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>
29 #include <rx/rx_queue.h>
32 #include <rx/rx_globals.h>
34 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
37 #include <afs/afsutil.h>
39 #include <afs/afsint.h>
44 #include <afs/ihandle.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/com_err.h>
51 #include "volser_internal.h"
52 #include "volser_prototypes.h"
53 #include "vsutils_prototypes.h"
54 #include "lockprocs_prototypes.h"
56 #ifdef HAVE_POSIX_REGEX
60 /* Local Prototypes */
61 int PrintDiagnostics(char *astring, afs_int32 acode);
62 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
63 afs_int32 *voltype, struct nvldbentry *rentry);
75 #define COMMONPARMS cmd_Seek(ts, 12);\
76 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
77 cmd_AddParmAlias(ts, 12, "-c"); /* original -cell option */ \
78 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
79 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
80 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
81 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
82 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
83 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
85 #define ERROR_EXIT(code) do { \
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 = 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;
286 buffer = malloc(blksize);
288 fprintf(STDERR, "malloc failed\n");
293 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
296 FD_SET((intptr_t)(ufd->handle), &in);
297 /* don't timeout if read blocks */
298 #if defined(AFS_PTHREAD_ENV)
299 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
301 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
304 error = USD_READ(ufd, buffer, blksize, &nbytes);
306 fprintf(STDERR, "File system read failed: %s\n",
307 afs_error_message(error));
314 if (rx_Write(call, buffer, nbytes) != nbytes) {
324 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
325 * writes it out to the volume. */
327 WriteData(struct rx_call *call, void *rock)
329 char *filename = (char *) rock;
332 afs_int32 error, code;
334 afs_int64 currOffset;
340 if (!filename || !*filename) {
341 usd_StandardInput(&ufd);
345 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
348 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
351 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
352 afs_error_message(code));
356 /* test if we have a valid dump */
357 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
358 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
359 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
360 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
361 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
365 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
367 code = SendFile(ufd, call, blksize);
374 code = USD_CLOSE(ufd);
376 fprintf(STDERR, "Could not close dump file %s\n",
377 (filename && *filename) ? filename : "STDOUT");
385 /* Receive data from <call> stream into file associated
386 * with <fd> <blksize>
389 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
393 afs_uint32 bytesleft, w;
396 buffer = malloc(blksize);
398 fprintf(STDERR, "memory allocation failed\n");
402 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
403 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
404 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
407 FD_SET((intptr_t)(ufd->handle), &out);
408 /* don't timeout if write blocks */
409 #if defined(AFS_PTHREAD_ENV)
410 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
412 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
416 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
418 fprintf(STDERR, "File system write failed: %s\n",
419 afs_error_message(error));
432 DumpFunction(struct rx_call *call, void *rock)
434 char *filename = (char *)rock;
435 usd_handle_t ufd; /* default is to stdout */
436 afs_int32 error = 0, code;
441 /* Open the output file */
442 if (!filename || !*filename) {
443 usd_StandardOutput(&ufd);
448 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
452 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
455 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
458 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
459 afs_error_message(code));
460 ERROR_EXIT(VOLSERBADOP);
464 code = ReceiveFile(ufd, call, blksize);
469 /* Close the output file */
471 code = USD_CLOSE(ufd);
473 fprintf(STDERR, "Could not close dump file %s\n",
474 (filename && *filename) ? filename : "STDIN");
484 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
485 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
486 int longlist, int disp)
492 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
493 } else if (longlist) {
494 if (pntr->status == VOK) {
495 fprintf(STDOUT, "%-32s ", pntr->name);
496 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
498 fprintf(STDOUT, "RW ");
500 fprintf(STDOUT, "RO ");
502 fprintf(STDOUT, "BK ");
503 fprintf(STDOUT, "%10d K ", pntr->size);
504 if (pntr->inUse == 1) {
505 fprintf(STDOUT, "On-line");
508 fprintf(STDOUT, "Off-line");
511 if (pntr->needsSalvaged == 1)
512 fprintf(STDOUT, "**needs salvage**");
513 fprintf(STDOUT, "\n");
514 MapPartIdIntoName(part, pname);
515 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
517 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
518 (unsigned long)pntr->parentID,
519 (unsigned long)pntr->cloneID,
520 (unsigned long)pntr->backupID);
521 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
522 t = pntr->creationDate;
523 fprintf(STDOUT, " Creation %s",
526 fprintf(STDOUT, " Copy %s",
529 t = pntr->backupDate;
531 fprintf(STDOUT, " Backup Never\n");
533 fprintf(STDOUT, " Backup %s",
536 t = pntr->accessDate;
538 fprintf(STDOUT, " Last Access %s",
541 t = pntr->updateDate;
543 fprintf(STDOUT, " Last Update Never\n");
545 fprintf(STDOUT, " Last Update %s",
548 " %d accesses in the past day (i.e., vnode references)\n",
550 } else if (pntr->status == VBUSY) {
552 qPut(&busyHead, pntr->volid);
554 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
555 (unsigned long)pntr->volid);
558 qPut(¬okHead, pntr->volid);
560 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
561 (unsigned long)pntr->volid);
563 fprintf(STDOUT, "\n");
564 } else { /* default listing */
565 if (pntr->status == VOK) {
566 fprintf(STDOUT, "%-32s ", pntr->name);
567 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
569 fprintf(STDOUT, "RW ");
571 fprintf(STDOUT, "RO ");
573 fprintf(STDOUT, "BK ");
574 fprintf(STDOUT, "%10d K ", pntr->size);
575 if (pntr->inUse == 1) {
576 fprintf(STDOUT, "On-line");
579 fprintf(STDOUT, "Off-line");
582 if (pntr->needsSalvaged == 1)
583 fprintf(STDOUT, "**needs salvage**");
584 fprintf(STDOUT, "\n");
585 } else if (pntr->status == VBUSY) {
587 qPut(&busyHead, pntr->volid);
589 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
590 (unsigned long)pntr->volid);
593 qPut(¬okHead, pntr->volid);
595 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
596 (unsigned long)pntr->volid);
601 /*------------------------------------------------------------------------
602 * PRIVATE XDisplayFormat
605 * Display the contents of one extended volume info structure.
608 * a_xInfoP : Ptr to extended volume info struct to print.
609 * a_servID : Server ID to print.
610 * a_partID : Partition ID to print.
611 * a_totalOKP : Ptr to total-OK counter.
612 * a_totalNotOKP : Ptr to total-screwed counter.
613 * a_totalBusyP : Ptr to total-busy counter.
614 * a_fast : Fast listing?
615 * a_int32 : Int32 listing?
616 * a_showProblems : Show volume problems?
622 * Nothing interesting.
626 *------------------------------------------------------------------------*/
629 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
630 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
631 int a_fast, int a_int32, int a_showProblems)
632 { /*XDisplayFormat */
640 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
641 } else if (a_int32) {
643 * Fully-detailed listing.
645 if (a_xInfoP->status == VOK) {
647 * Volume's status is OK - all the fields are valid.
649 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
650 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
651 if (a_xInfoP->type == 0)
652 fprintf(STDOUT, "RW ");
653 if (a_xInfoP->type == 1)
654 fprintf(STDOUT, "RO ");
655 if (a_xInfoP->type == 2)
656 fprintf(STDOUT, "BK ");
657 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
658 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
659 if (a_xInfoP->inUse == 1) {
660 fprintf(STDOUT, "On-line");
663 fprintf(STDOUT, "Off-line");
666 fprintf(STDOUT, "\n");
667 MapPartIdIntoName(a_partID, pname);
668 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
670 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
671 (unsigned long)a_xInfoP->parentID,
672 (unsigned long)a_xInfoP->cloneID,
673 (unsigned long)a_xInfoP->backupID);
674 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
676 t = a_xInfoP->creationDate;
677 fprintf(STDOUT, " Creation %s",
680 t = a_xInfoP->copyDate;
681 fprintf(STDOUT, " Copy %s",
684 t = a_xInfoP->backupDate;
686 fprintf(STDOUT, " Backup Never\n");
688 fprintf(STDOUT, " Backup %s",
691 t = a_xInfoP->accessDate;
693 fprintf(STDOUT, " Last Access %s",
696 t = a_xInfoP->updateDate;
698 fprintf(STDOUT, " Last Update Never\n");
700 fprintf(STDOUT, " Last Update %s",
703 " %d accesses in the past day (i.e., vnode references)\n",
707 * Print all the read/write and authorship stats.
709 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
711 " |-------------------------------------------|\n");
713 " | Same Network | Diff Network |\n");
715 " |----------|----------|----------|----------|\n");
717 " | Total | Auth | Total | Auth |\n");
719 " |----------|----------|----------|----------|\n");
720 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
721 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
722 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
723 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
724 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
725 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
726 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
727 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
728 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
729 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
731 " |-------------------------------------------|\n\n");
734 " Writes Affecting Authorship\n");
736 " |-------------------------------------------|\n");
738 " | File Authorship | Directory Authorship|\n");
740 " |----------|----------|----------|----------|\n");
742 " | Same | Diff | Same | Diff |\n");
744 " |----------|----------|----------|----------|\n");
745 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
746 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
747 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
749 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
750 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
751 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
752 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
754 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
755 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
756 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
757 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
759 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
760 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
761 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
762 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
764 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
765 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
766 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
767 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
769 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
770 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
771 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
772 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
774 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
776 " |-------------------------------------------|\n");
777 } /*Volume status OK */
778 else if (a_xInfoP->status == VBUSY) {
780 qPut(&busyHead, a_xInfoP->volid);
782 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
783 (unsigned long)a_xInfoP->volid);
787 qPut(¬okHead, a_xInfoP->volid);
789 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
790 (unsigned long)a_xInfoP->volid);
791 } /*Screwed volume */
792 fprintf(STDOUT, "\n");
798 if (a_xInfoP->status == VOK) {
799 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
800 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
801 if (a_xInfoP->type == 0)
802 fprintf(STDOUT, "RW ");
803 if (a_xInfoP->type == 1)
804 fprintf(STDOUT, "RO ");
805 if (a_xInfoP->type == 2)
806 fprintf(STDOUT, "BK ");
807 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
808 if (a_xInfoP->inUse == 1) {
809 fprintf(STDOUT, "On-line");
812 fprintf(STDOUT, "Off-line");
815 fprintf(STDOUT, "\n");
817 else if (a_xInfoP->status == VBUSY) {
819 qPut(&busyHead, a_xInfoP->volid);
821 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
822 (unsigned long)a_xInfoP->volid);
826 qPut(¬okHead, a_xInfoP->volid);
828 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
829 (unsigned long)a_xInfoP->volid);
830 } /*Screwed volume */
831 } /*Default listing */
832 } /*XDisplayFormat */
834 /*------------------------------------------------------------------------
835 * PRIVATE XDisplayFormat2
838 * Display the formated contents of one extended volume info structure.
841 * a_xInfoP : Ptr to extended volume info struct to print.
842 * a_servID : Server ID to print.
843 * a_partID : Partition ID to print.
844 * a_totalOKP : Ptr to total-OK counter.
845 * a_totalNotOKP : Ptr to total-screwed counter.
846 * a_totalBusyP : Ptr to total-busy counter.
847 * a_fast : Fast listing?
848 * a_int32 : Int32 listing?
849 * a_showProblems : Show volume problems?
855 * Nothing interesting.
859 *------------------------------------------------------------------------*/
862 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
863 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
864 int a_fast, int a_int32, int a_showProblems)
865 { /*XDisplayFormat */
871 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
872 } else if (a_int32) {
874 * Fully-detailed listing.
876 if (a_xInfoP->status == VOK) {
878 * Volume's status is OK - all the fields are valid.
881 static long server_cache = -1, partition_cache = -1;
882 static char hostname[256], address[32], pname[16];
883 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
884 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
886 if (a_servID != server_cache) {
890 strcpy(hostname, hostutil_GetNameByINet(a_servID));
891 strcpy(address, inet_ntoa(s));
892 server_cache = a_servID;
894 if (a_partID != partition_cache) {
895 MapPartIdIntoName(a_partID, pname);
896 partition_cache = a_partID;
899 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
900 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
901 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
902 fprintf(STDOUT, "part\t\t%s\n", pname);
903 fprintf(STDOUT, "status\t\tOK\n");
904 fprintf(STDOUT, "backupID\t%lu\n",
905 afs_printable_uint32_lu(a_xInfoP->backupID));
906 fprintf(STDOUT, "parentID\t%lu\n",
907 afs_printable_uint32_lu(a_xInfoP->parentID));
908 fprintf(STDOUT, "cloneID\t\t%lu\n",
909 afs_printable_uint32_lu(a_xInfoP->cloneID));
910 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
911 switch (a_xInfoP->type) {
913 fprintf(STDOUT, "type\t\tRW\n");
916 fprintf(STDOUT, "type\t\tRO\n");
919 fprintf(STDOUT, "type\t\tBK\n");
922 fprintf(STDOUT, "type\t\t?\n");
925 t = a_xInfoP->creationDate;
926 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
927 afs_printable_uint32_lu(a_xInfoP->creationDate),
930 t = a_xInfoP->accessDate;
931 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
932 afs_printable_uint32_lu(a_xInfoP->accessDate),
935 t = a_xInfoP->updateDate;
936 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
937 afs_printable_uint32_lu(a_xInfoP->updateDate),
940 t = a_xInfoP->backupDate;
941 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
942 afs_printable_uint32_lu(a_xInfoP->backupDate),
945 t = a_xInfoP->copyDate;
946 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
947 afs_printable_uint32_lu(a_xInfoP->copyDate),
950 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
951 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
953 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
954 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
958 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
959 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
960 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
961 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
963 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
964 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
965 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
966 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
970 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
971 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
972 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
973 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
976 } /*Volume status OK */
977 else if (a_xInfoP->status == VBUSY) {
979 qPut(&busyHead, a_xInfoP->volid);
981 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
982 (unsigned long)a_xInfoP->volid);
986 qPut(¬okHead, a_xInfoP->volid);
988 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
989 (unsigned long)a_xInfoP->volid);
990 } /*Screwed volume */
996 if (a_xInfoP->status == VOK) {
997 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
998 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
999 if (a_xInfoP->type == 0)
1000 fprintf(STDOUT, "type\tRW\n");
1001 if (a_xInfoP->type == 1)
1002 fprintf(STDOUT, "type\tRO\n");
1003 if (a_xInfoP->type == 2)
1004 fprintf(STDOUT, "type\tBK\n");
1005 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1007 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1008 if (a_xInfoP->inUse == 1)
1014 else if (a_xInfoP->status == VBUSY) {
1016 qPut(&busyHead, a_xInfoP->volid);
1018 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1019 (unsigned long)a_xInfoP->volid);
1023 qPut(¬okHead, a_xInfoP->volid);
1025 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1026 (unsigned long)a_xInfoP->volid);
1027 } /*Screwed volume */
1028 } /*Default listing */
1029 } /*XDisplayFormat */
1032 DisplayFormat2(long server, long partition, volintInfo *pntr)
1034 static long server_cache = -1, partition_cache = -1;
1035 static char hostname[256], address[32], pname[16];
1038 if (server != server_cache) {
1042 strcpy(hostname, hostutil_GetNameByINet(server));
1043 strcpy(address, inet_ntoa(s));
1044 server_cache = server;
1046 if (partition != partition_cache) {
1047 MapPartIdIntoName(partition, pname);
1048 partition_cache = partition;
1051 if (pntr->status == VOK)
1052 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1054 fprintf(STDOUT, "id\t\t%lu\n",
1055 afs_printable_uint32_lu(pntr->volid));
1056 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1057 fprintf(STDOUT, "part\t\t%s\n", pname);
1058 switch (pntr->status) {
1060 fprintf(STDOUT, "status\t\tOK\n");
1063 fprintf(STDOUT, "status\t\tBUSY\n");
1066 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1069 fprintf(STDOUT, "backupID\t%lu\n",
1070 afs_printable_uint32_lu(pntr->backupID));
1071 fprintf(STDOUT, "parentID\t%lu\n",
1072 afs_printable_uint32_lu(pntr->parentID));
1073 fprintf(STDOUT, "cloneID\t\t%lu\n",
1074 afs_printable_uint32_lu(pntr->cloneID));
1075 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1076 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1077 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1078 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1079 switch (pntr->type) {
1081 fprintf(STDOUT, "type\t\tRW\n");
1084 fprintf(STDOUT, "type\t\tRO\n");
1087 fprintf(STDOUT, "type\t\tBK\n");
1090 fprintf(STDOUT, "type\t\t?\n");
1093 t = pntr->creationDate;
1094 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1095 afs_printable_uint32_lu(pntr->creationDate),
1098 t = pntr->accessDate;
1099 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1100 afs_printable_uint32_lu(pntr->accessDate),
1103 t = pntr->updateDate;
1104 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1105 afs_printable_uint32_lu(pntr->updateDate),
1108 t = pntr->backupDate;
1109 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1110 afs_printable_uint32_lu(pntr->backupDate),
1114 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1115 afs_printable_uint32_lu(pntr->copyDate),
1118 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1119 afs_printable_uint32_lu(pntr->flags));
1120 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1121 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1122 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1123 afs_printable_uint32_lu(pntr->spare0));
1124 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1125 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1126 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1127 afs_printable_uint32_lu(pntr->spare1));
1128 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1129 afs_printable_uint32_lu(pntr->spare2));
1130 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1131 afs_printable_uint32_lu(pntr->spare3));
1136 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1140 for (i = 0; i < count; i++) {
1141 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1142 DisplayFormat2(server, partition, pntr);
1143 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1150 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1151 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1154 int totalOK, totalNotOK, totalBusy, i;
1155 afs_uint32 volid = 0;
1162 for (i = 0; i < count; i++) {
1163 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1168 while (busyHead.count) {
1169 qGet(&busyHead, &volid);
1170 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1171 (unsigned long)volid);
1175 while (notokHead.count) {
1176 qGet(¬okHead, &volid);
1177 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1178 (unsigned long)volid);
1182 fprintf(STDOUT, "\n");
1185 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1186 totalOK, totalNotOK, totalBusy);
1190 /*------------------------------------------------------------------------
1191 * PRIVATE XDisplayVolumes
1194 * Display extended volume information.
1197 * a_servID : Pointer to the Rx call we're performing.
1198 * a_partID : Partition for which we want the extended list.
1199 * a_xInfoP : Ptr to extended volume info.
1200 * a_count : Number of volume records contained above.
1201 * a_int32 : Int32 listing generated?
1202 * a_fast : Fast listing generated?
1203 * a_quiet : Quiet listing generated?
1209 * Nothing interesting.
1213 *------------------------------------------------------------------------*/
1216 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1217 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1219 { /*XDisplayVolumes */
1221 int totalOK; /*Total OK volumes */
1222 int totalNotOK; /*Total screwed volumes */
1223 int totalBusy; /*Total busy volumes */
1224 int i; /*Loop variable */
1225 afs_uint32 volid = 0; /*Current volume ID */
1228 * Initialize counters and (global!!) queues.
1237 * Display each volume in the list.
1239 for (i = 0; i < a_count; i++) {
1240 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1241 &totalBusy, a_fast, a_int32, 0);
1246 * If any volumes were found to be busy or screwed, display them.
1249 while (busyHead.count) {
1250 qGet(&busyHead, &volid);
1251 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1252 (unsigned long)volid);
1256 while (notokHead.count) {
1257 qGet(¬okHead, &volid);
1258 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1259 (unsigned long)volid);
1264 fprintf(STDOUT, "\n");
1267 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1268 totalOK, totalNotOK, totalBusy);
1272 } /*XDisplayVolumes */
1274 /*------------------------------------------------------------------------
1275 * PRIVATE XDisplayVolumes2
1278 * Display extended formated volume information.
1281 * a_servID : Pointer to the Rx call we're performing.
1282 * a_partID : Partition for which we want the extended list.
1283 * a_xInfoP : Ptr to extended volume info.
1284 * a_count : Number of volume records contained above.
1285 * a_int32 : Int32 listing generated?
1286 * a_fast : Fast listing generated?
1287 * a_quiet : Quiet listing generated?
1293 * Nothing interesting.
1297 *------------------------------------------------------------------------*/
1300 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1301 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1303 { /*XDisplayVolumes */
1305 int totalOK; /*Total OK volumes */
1306 int totalNotOK; /*Total screwed volumes */
1307 int totalBusy; /*Total busy volumes */
1308 int i; /*Loop variable */
1309 afs_uint32 volid = 0; /*Current volume ID */
1312 * Initialize counters and (global!!) queues.
1321 * Display each volume in the list.
1323 for (i = 0; i < a_count; i++) {
1324 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1325 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1326 &totalBusy, a_fast, a_int32, 0);
1327 fprintf(STDOUT, "END_OF_ENTRY\n");
1332 * If any volumes were found to be busy or screwed, display them.
1335 while (busyHead.count) {
1336 qGet(&busyHead, &volid);
1337 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1338 (unsigned long)volid);
1342 while (notokHead.count) {
1343 qGet(¬okHead, &volid);
1344 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1345 (unsigned long)volid);
1350 fprintf(STDOUT, "\n");
1353 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1354 totalOK, totalNotOK, totalBusy);
1358 } /*XDisplayVolumes2 */
1361 /* set <server> and <part> to the correct values depending on
1362 * <voltype> and <entry> */
1364 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1365 afs_int32 *part, int *previdx)
1367 int i, istart, vtype;
1372 /* Doesn't check for non-existance of backup volume */
1373 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1375 istart = 0; /* seach the entire entry */
1378 /* Seach from beginning of entry or pick up where we left off */
1379 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1382 for (i = istart; i < entry->nServers; i++) {
1383 if (entry->serverFlags[i] & vtype) {
1384 *server = entry->serverNumber[i];
1385 *part = entry->serverPartition[i];
1391 /* Didn't find any, return -1 */
1397 PrintLocked(afs_int32 aflags)
1399 afs_int32 flags = aflags & VLOP_ALLOPERS;
1402 fprintf(STDOUT, " Volume is currently LOCKED \n");
1404 if (flags & VLOP_MOVE) {
1405 fprintf(STDOUT, " Volume is locked for a move operation\n");
1407 if (flags & VLOP_RELEASE) {
1408 fprintf(STDOUT, " Volume is locked for a release operation\n");
1410 if (flags & VLOP_BACKUP) {
1411 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1413 if (flags & VLOP_DELETE) {
1414 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1416 if (flags & VLOP_DUMP) {
1417 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1423 PostVolumeStats(struct nvldbentry *entry)
1425 SubEnumerateEntry(entry);
1426 /* Check for VLOP_ALLOPERS */
1427 PrintLocked(entry->flags);
1431 /*------------------------------------------------------------------------
1432 * PRIVATE XVolumeStats
1435 * Display extended volume information.
1438 * a_xInfoP : Ptr to extended volume info.
1439 * a_entryP : Ptr to the volume's VLDB entry.
1440 * a_srvID : Server ID.
1441 * a_partID : Partition ID.
1442 * a_volType : Type of volume to print.
1448 * Nothing interesting.
1452 *------------------------------------------------------------------------*/
1455 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1456 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1459 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1461 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1462 a_srvID, /*Server ID to print */
1463 a_partID, /*Partition ID to print */
1464 &totalOK, /*Ptr to total-OK counter */
1465 &totalNotOK, /*Ptr to total-screwed counter */
1466 &totalBusy, /*Ptr to total-busy counter */
1467 0, /*Don't do a fast listing */
1468 1, /*Do a long listing */
1469 1); /*Show volume problems */
1475 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1476 afs_int32 part, int voltype)
1482 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1487 /* command to forcibly remove a volume */
1489 NukeVolume(struct cmd_syndesc *as)
1498 server = GetServer(tp = as->parms[0].items->data);
1500 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1504 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1506 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1510 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1513 PrintError("", err);
1516 "vos: could not parse '%s' as a numeric volume ID", tp);
1521 "vos: forcibly removing all traces of volume %d, please wait...",
1524 code = UV_NukeVolume(server, partID, volID);
1526 fprintf(STDOUT, "done.\n");
1528 fprintf(STDOUT, "failed with code %d.\n", code);
1533 /*------------------------------------------------------------------------
1534 * PRIVATE ExamineVolume
1537 * Routine used to examine a single volume, contacting the VLDB as
1538 * well as the Volume Server.
1541 * as : Ptr to parsed command line arguments.
1544 * 0 for a successful operation,
1545 * Otherwise, one of the ubik or VolServer error values.
1548 * Nothing interesting.
1552 *------------------------------------------------------------------------
1555 ExamineVolume(struct cmd_syndesc *as, void *arock)
1557 struct nvldbentry entry;
1558 afs_int32 vcode = 0;
1559 volintInfo *pntr = (volintInfo *) 0;
1560 volintXInfo *xInfoP = (volintXInfo *) 0;
1562 afs_int32 code, err, error = 0;
1563 int voltype, foundserv = 0, foundentry = 0;
1567 int wantExtendedInfo; /*Do we want extended vol info? */
1568 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1569 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1571 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1574 PrintError("", err);
1576 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1577 as->parms[0].items->data);
1582 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1583 (unsigned long)volid);
1586 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1589 "Could not fetch the entry for volume number %lu from VLDB \n",
1590 (unsigned long)volid);
1594 fprintf(STDOUT, "done\n");
1595 MapHostToNetwork(&entry);
1597 if (entry.volumeId[RWVOL] == volid)
1599 else if (entry.volumeId[BACKVOL] == volid)
1601 else /* (entry.volumeId[ROVOL] == volid) */
1604 do { /* do {...} while (voltype == ROVOL) */
1605 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1606 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1607 * If its a RO vol, get the next RO entry.
1609 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1610 &aserver, &apart, &previdx);
1611 if (previdx == -1) { /* searched all entries */
1613 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1614 as->parms[0].items->data);
1621 /* Get information about the volume from the server */
1623 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1624 hostutil_GetNameByINet(aserver));
1627 if (wantExtendedInfo)
1628 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1630 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1632 fprintf(STDOUT, "done\n");
1636 if (code == ENODEV) {
1637 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1638 /* The VLDB says there is no backup volume and its not on disk */
1639 fprintf(STDERR, "Volume %s does not exist\n",
1640 as->parms[0].items->data);
1644 "Volume does not exist on server %s as indicated by the VLDB\n",
1645 hostutil_GetNameByINet(aserver));
1648 PrintDiagnostics("examine", code);
1650 fprintf(STDOUT, "\n");
1653 if (wantExtendedInfo)
1654 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1655 else if (as->parms[2].items) {
1656 DisplayFormat2(aserver, apart, pntr);
1657 EnumerateEntry(&entry);
1660 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1662 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1663 /* The VLDB says there is no backup volume yet we found one on disk */
1664 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1665 as->parms[0].items->data);
1674 } while (voltype == ROVOL);
1677 fprintf(STDERR, "Dump only information from VLDB\n\n");
1678 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1682 PostVolumeStats(&entry);
1687 /*------------------------------------------------------------------------
1691 * Routine used to change the status of a single volume.
1694 * as : Ptr to parsed command line arguments.
1697 * 0 for a successful operation,
1698 * Otherwise, one of the ubik or VolServer error values.
1701 * Nothing interesting.
1705 *------------------------------------------------------------------------
1708 SetFields(struct cmd_syndesc *as, void *arock)
1710 struct nvldbentry entry;
1713 afs_int32 code, err;
1719 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1722 PrintError("", err);
1724 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1725 as->parms[0].items->data);
1729 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1732 "Could not fetch the entry for volume number %lu from VLDB \n",
1733 (unsigned long)volid);
1736 MapHostToNetwork(&entry);
1738 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1739 if (previdx == -1) {
1740 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1741 as->parms[0].items->data);
1745 init_volintInfo(&info);
1749 if (as->parms[1].items) {
1752 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1754 fprintf(STDERR, "invalid quota value\n");
1758 if (as->parms[2].items) {
1763 if (as->parms[3].items) {
1764 /* -clearVolUpCounter */
1769 fprintf(STDERR,"Nothing to set.\n");
1772 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1775 "Could not update volume info fields for volume number %lu\n",
1776 (unsigned long)volid);
1780 /*------------------------------------------------------------------------
1784 * Brings a volume online.
1787 * as : Ptr to parsed command line arguments.
1790 * 0 for a successful operation,
1793 * Nothing interesting.
1797 *------------------------------------------------------------------------
1800 volOnline(struct cmd_syndesc *as, void *arock)
1803 afs_int32 partition;
1805 afs_int32 code, err = 0;
1807 server = GetServer(as->parms[0].items->data);
1809 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1810 as->parms[0].items->data);
1814 partition = volutil_GetPartitionID(as->parms[1].items->data);
1815 if (partition < 0) {
1816 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1817 as->parms[1].items->data);
1821 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1824 PrintError("", err);
1826 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1827 as->parms[0].items->data);
1831 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1834 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1841 /*------------------------------------------------------------------------
1842 * PRIVATE volOffline
1845 * Brings a volume offline.
1848 * as : Ptr to parsed command line arguments.
1851 * 0 for a successful operation,
1854 * Nothing interesting.
1858 *------------------------------------------------------------------------
1861 volOffline(struct cmd_syndesc *as, void *arock)
1864 afs_int32 partition;
1866 afs_int32 code, err = 0;
1867 afs_int32 transflag, sleeptime, transdone;
1869 server = GetServer(as->parms[0].items->data);
1871 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1872 as->parms[0].items->data);
1876 partition = volutil_GetPartitionID(as->parms[1].items->data);
1877 if (partition < 0) {
1878 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1879 as->parms[1].items->data);
1883 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1886 PrintError("", err);
1888 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1889 as->parms[0].items->data);
1893 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1894 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1895 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1896 if (as->parms[4].items && !as->parms[3].items) {
1897 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1902 UV_SetVolume(server, partition, volid, transflag, transdone,
1905 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1913 CreateVolume(struct cmd_syndesc *as, void *arock)
1917 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1918 afs_uint32 *arovolid;
1920 struct nvldbentry entry;
1925 arovolid = &rovolid;
1928 tserver = GetServer(as->parms[0].items->data);
1930 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1931 as->parms[0].items->data);
1934 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1936 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1937 as->parms[1].items->data);
1940 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1942 PrintError("", code);
1945 "vos : partition %s does not exist on the server\n",
1946 as->parms[1].items->data);
1949 if (!ISNAMEVALID(as->parms[2].items->data)) {
1951 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1952 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1955 if (!VolNameOK(as->parms[2].items->data)) {
1957 "Illegal volume name %s, should not end in .readonly or .backup\n",
1958 as->parms[2].items->data);
1961 if (IsNumeric(as->parms[2].items->data)) {
1962 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1963 as->parms[2].items->data);
1966 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1968 fprintf(STDERR, "Volume %s already exists\n",
1969 as->parms[2].items->data);
1970 PrintDiagnostics("create", code);
1974 if (as->parms[3].items) {
1975 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1977 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1982 if (as->parms[4].items) {
1983 if (!IsNumeric(as->parms[4].items->data)) {
1984 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1985 as->parms[4].items->data);
1989 code = util_GetUInt32(as->parms[4].items->data, &volid);
1991 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1996 if (as->parms[5].items) {
1997 if (!IsNumeric(as->parms[5].items->data)) {
1998 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1999 as->parms[5].items->data);
2003 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2005 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2015 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2016 0, 0, 0, &volid, arovolid, &bkvolid);
2018 PrintDiagnostics("create", code);
2021 MapPartIdIntoName(pnum, part);
2022 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2023 (unsigned long)volid, part, as->parms[0].items->data);
2030 DeleteAll(struct nvldbentry *entry)
2033 afs_int32 error, code, curserver, curpart;
2036 MapHostToNetwork(entry);
2038 for (i = 0; i < entry->nServers; i++) {
2039 curserver = entry->serverNumber[i];
2040 curpart = entry->serverPartition[i];
2041 if (entry->serverFlags[i] & ITSROVOL) {
2042 volid = entry->volumeId[ROVOL];
2044 volid = entry->volumeId[RWVOL];
2046 code = UV_DeleteVolume(curserver, curpart, volid);
2055 DeleteVolume(struct cmd_syndesc *as, void *arock)
2057 afs_int32 err, code = 0;
2058 afs_uint32 server = 0;
2059 afs_int32 partition = -1;
2064 if (as->parms[0].items) {
2065 server = GetServer(as->parms[0].items->data);
2067 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2068 as->parms[0].items->data);
2073 if (as->parms[1].items) {
2074 partition = volutil_GetPartitionID(as->parms[1].items->data);
2075 if (partition < 0) {
2076 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2077 as->parms[1].items->data);
2081 /* Check for validity of the partition */
2082 if (!IsPartValid(partition, server, &code)) {
2084 PrintError("", code);
2087 "vos : partition %s does not exist on the server\n",
2088 as->parms[1].items->data);
2094 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2096 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2097 as->parms[2].items->data);
2099 PrintError("", err);
2103 /* If the server or partition option are not complete, try to fill
2104 * them in from the VLDB entry.
2106 if ((partition == -1) || !server) {
2107 struct nvldbentry entry;
2109 code = VLDB_GetEntryByID(volid, -1, &entry);
2112 "Could not fetch the entry for volume %lu from VLDB\n",
2113 (unsigned long)volid);
2114 PrintError("", code);
2118 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2119 || ((volid == entry.volumeId[BACKVOL])
2120 && (entry.flags & BACK_EXISTS))) {
2121 idx = Lp_GetRwIndex(&entry);
2122 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2123 || ((partition != -1)
2124 && (partition != entry.serverPartition[idx]))) {
2125 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2126 as->parms[2].items->data);
2129 } else if ((volid == entry.volumeId[ROVOL])
2130 && (entry.flags & RO_EXISTS)) {
2131 for (idx = -1, j = 0; j < entry.nServers; j++) {
2132 if (entry.serverFlags[j] != ITSROVOL)
2135 if (((server == 0) || (server == entry.serverNumber[j]))
2136 && ((partition == -1)
2137 || (partition == entry.serverPartition[j]))) {
2140 "VLDB: Volume '%s' matches more than one RO\n",
2141 as->parms[2].items->data);
2148 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2149 as->parms[2].items->data);
2153 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2154 as->parms[2].items->data);
2158 server = htonl(entry.serverNumber[idx]);
2159 partition = entry.serverPartition[idx];
2163 code = UV_DeleteVolume(server, partition, volid);
2165 PrintDiagnostics("remove", code);
2169 MapPartIdIntoName(partition, pname);
2170 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2171 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2175 #define TESTM 0 /* set for move space tests, clear for production */
2177 MoveVolume(struct cmd_syndesc *as, void *arock)
2181 afs_uint32 fromserver, toserver;
2182 afs_int32 frompart, topart;
2183 afs_int32 flags, code, err;
2184 char fromPartName[10], toPartName[10];
2186 struct diskPartition64 partition; /* for space check */
2189 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2192 PrintError("", err);
2194 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2195 as->parms[0].items->data);
2198 fromserver = GetServer(as->parms[1].items->data);
2199 if (fromserver == 0) {
2200 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2201 as->parms[1].items->data);
2204 toserver = GetServer(as->parms[3].items->data);
2205 if (toserver == 0) {
2206 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2207 as->parms[3].items->data);
2210 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2212 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2213 as->parms[2].items->data);
2216 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2218 PrintError("", code);
2221 "vos : partition %s does not exist on the server\n",
2222 as->parms[2].items->data);
2225 topart = volutil_GetPartitionID(as->parms[4].items->data);
2227 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2228 as->parms[4].items->data);
2231 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2233 PrintError("", code);
2236 "vos : partition %s does not exist on the server\n",
2237 as->parms[4].items->data);
2242 if (as->parms[5].items) flags |= RV_NOCLONE;
2245 * check source partition for space to clone volume
2248 MapPartIdIntoName(topart, toPartName);
2249 MapPartIdIntoName(frompart, fromPartName);
2252 * check target partition for space to move volume
2255 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2257 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2261 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2264 p = (volintInfo *) 0;
2265 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2267 fprintf(STDERR, "vos:cannot access volume %lu\n",
2268 (unsigned long)volid);
2272 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2274 if (partition.free <= p->size) {
2276 "vos: no space on target partition %s to move volume %lu\n",
2277 toPartName, (unsigned long)volid);
2284 fprintf(STDOUT, "size test - don't do move\n");
2288 /* successful move still not guaranteed but shoot for it */
2291 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2293 PrintDiagnostics("move", code);
2296 MapPartIdIntoName(topart, toPartName);
2297 MapPartIdIntoName(frompart, fromPartName);
2298 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2299 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2300 as->parms[3].items->data, toPartName);
2306 CopyVolume(struct cmd_syndesc *as, void *arock)
2309 afs_uint32 fromserver, toserver;
2310 afs_int32 frompart, topart, code, err, flags;
2311 char fromPartName[10], toPartName[10], *tovolume;
2312 struct nvldbentry entry;
2313 struct diskPartition64 partition; /* for space check */
2316 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2319 PrintError("", err);
2321 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2322 as->parms[0].items->data);
2325 fromserver = GetServer(as->parms[1].items->data);
2326 if (fromserver == 0) {
2327 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2328 as->parms[1].items->data);
2332 toserver = GetServer(as->parms[4].items->data);
2333 if (toserver == 0) {
2334 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2335 as->parms[4].items->data);
2339 tovolume = as->parms[3].items->data;
2340 if (!ISNAMEVALID(tovolume)) {
2342 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2343 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2346 if (!VolNameOK(tovolume)) {
2348 "Illegal volume name %s, should not end in .readonly or .backup\n",
2352 if (IsNumeric(tovolume)) {
2353 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2357 code = VLDB_GetEntryByName(tovolume, &entry);
2359 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2360 PrintDiagnostics("copy", code);
2364 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2366 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2367 as->parms[2].items->data);
2370 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2372 PrintError("", code);
2375 "vos : partition %s does not exist on the server\n",
2376 as->parms[2].items->data);
2380 topart = volutil_GetPartitionID(as->parms[5].items->data);
2382 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2383 as->parms[5].items->data);
2386 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2388 PrintError("", code);
2391 "vos : partition %s does not exist on the server\n",
2392 as->parms[5].items->data);
2397 if (as->parms[6].items) flags |= RV_OFFLINE;
2398 if (as->parms[7].items) flags |= RV_RDONLY;
2399 if (as->parms[8].items) flags |= RV_NOCLONE;
2401 MapPartIdIntoName(topart, toPartName);
2402 MapPartIdIntoName(frompart, fromPartName);
2405 * check target partition for space to move volume
2408 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2410 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2414 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2417 p = (volintInfo *) 0;
2418 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2420 fprintf(STDERR, "vos:cannot access volume %lu\n",
2421 (unsigned long)volid);
2425 if (partition.free <= p->size) {
2427 "vos: no space on target partition %s to copy volume %lu\n",
2428 toPartName, (unsigned long)volid);
2434 /* successful copy still not guaranteed but shoot for it */
2437 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2440 PrintDiagnostics("copy", code);
2443 MapPartIdIntoName(topart, toPartName);
2444 MapPartIdIntoName(frompart, fromPartName);
2445 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2446 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2447 tovolume, as->parms[4].items->data, toPartName);
2454 ShadowVolume(struct cmd_syndesc *as, void *arock)
2456 afs_uint32 volid, tovolid;
2457 afs_uint32 fromserver, toserver;
2458 afs_int32 frompart, topart;
2459 afs_int32 code, err, flags;
2460 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2461 struct diskPartition64 partition; /* for space check */
2464 p = (volintInfo *) 0;
2465 q = (volintInfo *) 0;
2467 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2470 PrintError("", err);
2472 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2473 as->parms[0].items->data);
2476 fromserver = GetServer(as->parms[1].items->data);
2477 if (fromserver == 0) {
2478 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2479 as->parms[1].items->data);
2483 toserver = GetServer(as->parms[3].items->data);
2484 if (toserver == 0) {
2485 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2486 as->parms[3].items->data);
2490 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2492 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2493 as->parms[2].items->data);
2496 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2498 PrintError("", code);
2501 "vos : partition %s does not exist on the server\n",
2502 as->parms[2].items->data);
2506 topart = volutil_GetPartitionID(as->parms[4].items->data);
2508 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2509 as->parms[4].items->data);
2512 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2514 PrintError("", code);
2517 "vos : partition %s does not exist on the server\n",
2518 as->parms[4].items->data);
2522 if (as->parms[5].items) {
2523 tovolume = as->parms[5].items->data;
2524 if (!ISNAMEVALID(tovolume)) {
2526 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2527 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2530 if (!VolNameOK(tovolume)) {
2532 "Illegal volume name %s, should not end in .readonly or .backup\n",
2536 if (IsNumeric(tovolume)) {
2538 "Illegal volume name %s, should not be a number\n",
2543 /* use actual name of source volume */
2544 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2546 fprintf(STDERR, "vos:cannot access volume %lu\n",
2547 (unsigned long)volid);
2550 strcpy(toVolName, p->name);
2551 tovolume = toVolName;
2552 /* save p for size checks later */
2555 if (as->parms[6].items) {
2556 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2559 PrintError("", err);
2561 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2562 as->parms[6].items->data);
2568 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2571 PrintError("", err);
2573 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2582 if (as->parms[7].items) flags |= RV_OFFLINE;
2583 if (as->parms[8].items) flags |= RV_RDONLY;
2584 if (as->parms[9].items) flags |= RV_NOCLONE;
2585 if (as->parms[10].items) flags |= RV_CPINCR;
2587 MapPartIdIntoName(topart, toPartName);
2588 MapPartIdIntoName(frompart, fromPartName);
2591 * check target partition for space to move volume
2594 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2596 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2600 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2603 /* Don't do this again if we did it above */
2605 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2607 fprintf(STDERR, "vos:cannot access volume %lu\n",
2608 (unsigned long)volid);
2613 /* OK if this fails */
2614 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2616 /* Treat existing volume size as "free" */
2618 p->size = (q->size < p->size) ? p->size - q->size : 0;
2620 if (partition.free <= p->size) {
2622 "vos: no space on target partition %s to copy volume %lu\n",
2623 toPartName, (unsigned long)volid);
2631 /* successful copy still not guaranteed but shoot for it */
2634 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2635 topart, tovolid, flags);
2637 PrintDiagnostics("shadow", code);
2640 MapPartIdIntoName(topart, toPartName);
2641 MapPartIdIntoName(frompart, fromPartName);
2642 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2643 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2644 as->parms[3].items->data, toPartName);
2651 CloneVolume(struct cmd_syndesc *as, void *arock)
2653 afs_uint32 volid, cloneid;
2655 afs_int32 part, voltype;
2656 char partName[10], *volname;
2657 afs_int32 code, err, flags;
2658 struct nvldbentry entry;
2660 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2663 PrintError("", err);
2665 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2666 as->parms[0].items->data);
2670 if (as->parms[1].items || as->parms[2].items) {
2671 if (!as->parms[1].items || !as->parms[2].items) {
2673 "Must specify both -server and -partition options\n");
2676 server = GetServer(as->parms[1].items->data);
2678 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2679 as->parms[1].items->data);
2682 part = volutil_GetPartitionID(as->parms[2].items->data);
2684 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2685 as->parms[2].items->data);
2688 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2690 PrintError("", code);
2693 "vos : partition %s does not exist on the server\n",
2694 as->parms[2].items->data);
2698 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2704 if (as->parms[3].items) {
2705 volname = as->parms[3].items->data;
2706 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2708 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2709 volname, VOLSER_OLDMAXVOLNAME - 1);
2714 * In order that you be able to make clones of RO or BK, this
2715 * check must be omitted.
2717 if (!VolNameOK(volname)) {
2719 "Illegal volume name %s, should not end in .readonly or .backup\n",
2724 if (IsNumeric(volname)) {
2726 "Illegal volume name %s, should not be a number\n",
2733 if (as->parms[4].items) {
2734 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2737 PrintError("", err);
2739 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2740 as->parms[4].items->data);
2746 if (as->parms[5].items) flags |= RV_OFFLINE;
2747 if (as->parms[6].items && as->parms[7].items) {
2748 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2751 if (as->parms[6].items) flags |= RV_RDONLY;
2752 if (as->parms[7].items) flags |= RV_RWONLY;
2756 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2759 PrintDiagnostics("clone", code);
2762 MapPartIdIntoName(part, partName);
2763 fprintf(STDOUT, "Created clone for volume %s\n",
2764 as->parms[0].items->data);
2771 BackupVolume(struct cmd_syndesc *as, void *arock)
2775 afs_int32 apart, vtype, code, err;
2776 struct nvldbentry entry;
2779 afs_uint32 buserver;
2780 afs_int32 bupart, butype;
2781 struct nvldbentry buentry;
2783 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2786 PrintError("", err);
2788 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2789 as->parms[0].items->data);
2792 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2796 /* verify this is a readwrite volume */
2798 if (vtype != RWVOL) {
2799 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2803 /* is there a backup volume already? */
2805 if (entry.flags & BACK_EXISTS) {
2806 /* yep, where is it? */
2808 buvolid = entry.volumeId[BACKVOL];
2809 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2814 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2817 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2823 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2824 (unsigned long)buvolid, (unsigned long)buserver);
2829 /* nope, carry on */
2831 code = UV_BackupVolume(aserver, apart, avolid);
2834 PrintDiagnostics("backup", code);
2837 fprintf(STDOUT, "Created backup volume for %s \n",
2838 as->parms[0].items->data);
2843 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2846 struct nvldbentry entry;
2849 afs_int32 apart, vtype, code, err;
2853 if (as->parms[1].items)
2855 if (as->parms[2].items)
2857 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2860 PrintError("", err);
2862 fprintf(STDERR, "vos: can't find volume '%s'\n",
2863 as->parms[0].items->data);
2866 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2870 if (vtype != RWVOL) {
2871 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2875 if (!ISNAMEVALID(entry.name)) {
2877 "Volume name %s is too long, rename before releasing\n",
2882 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2885 PrintDiagnostics("release", code);
2888 fprintf(STDOUT, "Released volume %s successfully\n",
2889 as->parms[0].items->data);
2894 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2898 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2899 char filename[MAXPATHLEN];
2900 struct nvldbentry entry;
2902 rx_SetRxDeadTime(60 * 10);
2903 for (i = 0; i < MAXSERVERS; i++) {
2904 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2907 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2908 if (rx_ServiceOf(rxConn))
2909 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2912 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2915 PrintError("", err);
2917 fprintf(STDERR, "vos: can't find volume '%s'\n",
2918 as->parms[0].items->data);
2922 if (as->parms[3].items || as->parms[4].items) {
2923 if (!as->parms[3].items || !as->parms[4].items) {
2925 "Must specify both -server and -partition options\n");
2928 aserver = GetServer(as->parms[3].items->data);
2930 fprintf(STDERR, "Invalid server name\n");
2933 apart = volutil_GetPartitionID(as->parms[4].items->data);
2935 fprintf(STDERR, "Invalid partition name\n");
2939 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2944 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2945 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2947 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2948 as->parms[1].items->data, code);
2952 if (as->parms[2].items) {
2953 strcpy(filename, as->parms[2].items->data);
2955 strcpy(filename, "");
2958 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2960 if (as->parms[5].items) {
2962 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2963 DumpFunction, filename, flags);
2966 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2969 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2970 flags &= ~VOLDUMPV2_OMITDIRS;
2974 PrintDiagnostics("dump", code);
2977 if (strcmp(filename, ""))
2978 fprintf(STDERR, "Dumped volume %s in file %s\n",
2979 as->parms[0].items->data, filename);
2981 fprintf(STDERR, "Dumped volume %s in stdout \n",
2982 as->parms[0].items->data);
2996 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2998 afs_uint32 avolid, aparentid;
3000 afs_int32 apart, code, vcode, err;
3001 afs_int32 aoverwrite = ASK;
3002 afs_int32 acreation = 0, alastupdate = 0;
3003 int restoreflags = 0;
3004 int readonly = 0, offline = 0, voltype = RWVOL;
3005 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3006 char volname[VOLSER_MAXVOLNAME + 1];
3007 struct nvldbentry entry;
3010 if (as->parms[4].items) {
3011 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3014 PrintError("", err);
3016 fprintf(STDERR, "vos: can't find volume '%s'\n",
3017 as->parms[4].items->data);
3023 if (as->parms[5].items) {
3024 if ((strcmp(as->parms[5].items->data, "a") == 0)
3025 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3027 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3028 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3030 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3031 || (strcmp(as->parms[5].items->data, "inc") == 0)
3032 || (strcmp(as->parms[5].items->data, "increment") == 0)
3033 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3036 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3037 as->parms[5].items->data);
3041 if (as->parms[6].items)
3043 if (as->parms[7].items) {
3048 if (as->parms[8].items) {
3049 if ((strcmp(as->parms[8].items->data, "d") == 0)
3050 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3051 acreation = TS_DUMP;
3052 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3053 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3054 acreation = TS_KEEP;
3055 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3056 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3059 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3060 as->parms[8].items->data);
3065 if (as->parms[9].items) {
3066 if ((strcmp(as->parms[9].items->data, "d") == 0)
3067 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3068 alastupdate = TS_DUMP;
3069 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3070 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3071 alastupdate = TS_KEEP;
3072 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3073 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3074 alastupdate = TS_NEW;
3076 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3077 as->parms[9].items->data);
3082 aserver = GetServer(as->parms[0].items->data);
3084 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3085 as->parms[0].items->data);
3088 apart = volutil_GetPartitionID(as->parms[1].items->data);
3090 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3091 as->parms[1].items->data);
3094 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3096 PrintError("", code);
3099 "vos : partition %s does not exist on the server\n",
3100 as->parms[1].items->data);
3103 strcpy(avolname, as->parms[2].items->data);
3104 if (!ISNAMEVALID(avolname)) {
3106 "vos: the name of the volume %s exceeds the size limit\n",
3110 if (!VolNameOK(avolname)) {
3112 "Illegal volume name %s, should not end in .readonly or .backup\n",
3116 if (as->parms[3].items) {
3117 strcpy(afilename, as->parms[3].items->data);
3118 if (!FileExists(afilename)) {
3119 fprintf(STDERR, "Can't access file %s\n", afilename);
3123 strcpy(afilename, "");
3126 /* Check if volume exists or not */
3128 vsu_ExtractName(volname, avolname);
3129 vcode = VLDB_GetEntryByName(volname, &entry);
3130 if (vcode) { /* no volume - do a full restore */
3131 restoreflags = RV_FULLRST;
3132 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3134 "Volume does not exist; Will perform a full restore\n");
3137 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3138 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3139 restoreflags = RV_FULLRST;
3140 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3142 "%s Volume does not exist; Will perform a full restore\n",
3143 readonly ? "RO" : "RW");
3146 avolid = entry.volumeId[voltype];
3147 } else if (entry.volumeId[voltype] != 0
3148 && entry.volumeId[voltype] != avolid) {
3149 avolid = entry.volumeId[voltype];
3151 aparentid = entry.volumeId[RWVOL];
3154 else { /* volume exists - do we do a full incremental or abort */
3156 afs_int32 Opart, Otype, vol_elsewhere = 0;
3157 struct nvldbentry Oentry;
3161 avolid = entry.volumeId[voltype];
3162 } else if (entry.volumeId[voltype] != 0
3163 && entry.volumeId[voltype] != avolid) {
3164 avolid = entry.volumeId[voltype];
3166 aparentid = entry.volumeId[RWVOL];
3168 /* A file name was specified - check if volume is on another partition */
3169 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3173 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3176 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3180 if (!vcode || (Opart != apart))
3183 if (aoverwrite == ASK) {
3184 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3186 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3190 /* Ask what to do */
3191 if (vol_elsewhere) {
3193 "The volume %s %u already exists on a different server/part\n",
3194 volname, entry.volumeId[voltype]);
3196 "Do you want to do a full restore or abort? [fa](a): ");
3199 "The volume %s %u already exists in the VLDB\n",
3200 volname, entry.volumeId[voltype]);
3202 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3205 while (!(dc == EOF || dc == '\n'))
3206 dc = getchar(); /* goto end of line */
3207 if ((c == 'f') || (c == 'F'))
3209 else if ((c == 'i') || (c == 'I'))
3215 if (aoverwrite == ABORT) {
3216 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3218 } else if (aoverwrite == FULL) {
3219 restoreflags = RV_FULLRST;
3221 "Volume exists; Will delete and perform full restore\n");
3222 } else if (aoverwrite == INC) {
3224 if (vol_elsewhere) {
3226 "%s volume %lu already exists on a different server/part; not allowed\n",
3227 readonly ? "RO" : "RW", (unsigned long)avolid);
3233 restoreflags |= RV_OFFLINE;
3235 restoreflags |= RV_RDONLY;
3237 switch (acreation) {
3239 restoreflags |= RV_CRDUMP;
3242 restoreflags |= RV_CRKEEP;
3245 restoreflags |= RV_CRNEW;
3248 if (aoverwrite == FULL)
3249 restoreflags |= RV_CRNEW;
3251 restoreflags |= RV_CRKEEP;
3254 switch (alastupdate) {
3256 restoreflags |= RV_LUDUMP;
3259 restoreflags |= RV_LUKEEP;
3262 restoreflags |= RV_LUNEW;
3265 restoreflags |= RV_LUDUMP;
3267 if (as->parms[10].items) {
3268 restoreflags |= RV_NODEL;
3273 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3274 avolname, restoreflags, WriteData, afilename);
3276 PrintDiagnostics("restore", code);
3279 MapPartIdIntoName(apart, apartName);
3282 * patch typo here - originally "parms[1]", should be "parms[0]"
3285 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3286 as->parms[0].items->data, apartName);
3291 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3294 afs_int32 code, err;
3296 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3299 PrintError("", err);
3301 fprintf(STDERR, "vos: can't find volume '%s'\n",
3302 as->parms[0].items->data);
3306 code = UV_LockRelease(avolid);
3308 PrintDiagnostics("unlock", code);
3311 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3312 as->parms[0].items->data);
3317 AddSite(struct cmd_syndesc *as, void *arock)
3321 afs_int32 apart, code, err, arovolid, valid = 0;
3322 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3324 vsu_ExtractName(avolname, as->parms[2].items->data);;
3325 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3328 PrintError("", err);
3330 fprintf(STDERR, "vos: can't find volume '%s'\n",
3331 as->parms[2].items->data);
3335 if (as->parms[3].items) {
3336 vsu_ExtractName(avolname, as->parms[3].items->data);
3337 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3339 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3340 as->parms[3].items->data);
3344 aserver = GetServer(as->parms[0].items->data);
3346 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3347 as->parms[0].items->data);
3350 apart = volutil_GetPartitionID(as->parms[1].items->data);
3352 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3353 as->parms[1].items->data);
3356 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3358 PrintError("", code);
3361 "vos : partition %s does not exist on the server\n",
3362 as->parms[1].items->data);
3365 if (as->parms[4].items) {
3368 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3370 PrintDiagnostics("addsite", code);
3373 MapPartIdIntoName(apart, apartName);
3374 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3375 as->parms[0].items->data, apartName, as->parms[2].items->data);
3380 RemoveSite(struct cmd_syndesc *as, void *arock)
3385 afs_int32 apart, code, err;
3386 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3388 vsu_ExtractName(avolname, as->parms[2].items->data);
3389 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3392 PrintError("", err);
3394 fprintf(STDERR, "vos: can't find volume '%s'\n",
3395 as->parms[2].items->data);
3398 aserver = GetServer(as->parms[0].items->data);
3400 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3401 as->parms[0].items->data);
3404 apart = volutil_GetPartitionID(as->parms[1].items->data);
3406 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3407 as->parms[1].items->data);
3411 *skip the partition validity check, since it is possible that the partition
3412 *has since been decomissioned.
3415 if (!IsPartValid(apart,aserver,&code)){
3416 if(code) PrintError("",code);
3417 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3421 code = UV_RemoveSite(aserver, apart, avolid);
3423 PrintDiagnostics("remsite", code);
3426 MapPartIdIntoName(apart, apartName);
3427 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3428 as->parms[0].items->data, apartName, as->parms[2].items->data);
3433 ChangeLocation(struct cmd_syndesc *as, void *arock)
3437 afs_int32 apart, code, err;
3440 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3443 PrintError("", err);
3445 fprintf(STDERR, "vos: can't find volume '%s'\n",
3446 as->parms[2].items->data);
3449 aserver = GetServer(as->parms[0].items->data);
3451 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3452 as->parms[0].items->data);
3455 apart = volutil_GetPartitionID(as->parms[1].items->data);
3457 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3458 as->parms[1].items->data);
3461 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3463 PrintError("", code);
3466 "vos : partition %s does not exist on the server\n",
3467 as->parms[1].items->data);
3470 code = UV_ChangeLocation(aserver, apart, avolid);
3472 PrintDiagnostics("changeloc", code);
3475 MapPartIdIntoName(apart, apartName);
3476 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3477 as->parms[0].items->data, apartName, as->parms[2].items->data);
3482 ListPartitions(struct cmd_syndesc *as, void *arock)
3486 struct partList dummyPartList;
3491 aserver = GetServer(as->parms[0].items->data);
3493 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3494 as->parms[0].items->data);
3499 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3501 PrintDiagnostics("listpart", code);
3505 fprintf(STDOUT, "The partitions on the server are:\n");
3506 for (i = 0; i < cnt; i++) {
3507 if (dummyPartList.partFlags[i] & PARTVALID) {
3508 memset(pname, 0, sizeof(pname));
3509 MapPartIdIntoName(dummyPartList.partId[i], pname);
3510 fprintf(STDOUT, " %10s ", pname);
3512 if ((i % 5) == 0 && (i != 0))
3513 fprintf(STDOUT, "\n");
3516 fprintf(STDOUT, "\n");
3517 fprintf(STDOUT, "Total: %d\n", total);
3523 CompareVolName(const void *p1, const void *p2)
3525 volintInfo *arg1, *arg2;
3527 arg1 = (volintInfo *) p1;
3528 arg2 = (volintInfo *) p2;
3529 return (strcmp(arg1->name, arg2->name));
3533 /*------------------------------------------------------------------------
3534 * PRIVATE XCompareVolName
3537 * Comparison routine for volume names coming from an extended
3541 * a_obj1P : Char ptr to first extended vol info object
3542 * a_obj1P : Char ptr to second extended vol info object
3545 * The value of strcmp() on the volume names within the passed
3546 * objects (i,e., -1, 0, or 1).
3549 * Passed to qsort() as the designated comparison routine.
3553 *------------------------------------------------------------------------*/
3556 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3557 { /*XCompareVolName */
3560 (((struct volintXInfo *)(a_obj1P))->name,
3561 ((struct volintXInfo *)(a_obj2P))->name));
3563 } /*XCompareVolName */
3566 CompareVolID(const void *p1, const void *p2)
3568 volintInfo *arg1, *arg2;
3570 arg1 = (volintInfo *) p1;
3571 arg2 = (volintInfo *) p2;
3572 if (arg1->volid == arg2->volid)
3574 if (arg1->volid > arg2->volid)
3581 /*------------------------------------------------------------------------
3582 * PRIVATE XCompareVolID
3585 * Comparison routine for volume IDs coming from an extended
3589 * a_obj1P : Char ptr to first extended vol info object
3590 * a_obj1P : Char ptr to second extended vol info object
3593 * The value of strcmp() on the volume names within the passed
3594 * objects (i,e., -1, 0, or 1).
3597 * Passed to qsort() as the designated comparison routine.
3601 *------------------------------------------------------------------------*/
3604 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3605 { /*XCompareVolID */
3607 afs_int32 id1, id2; /*Volume IDs we're comparing */
3609 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3610 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3618 } /*XCompareVolID */
3620 /*------------------------------------------------------------------------
3621 * PRIVATE ListVolumes
3624 * Routine used to list volumes, contacting the Volume Server
3625 * directly, bypassing the VLDB.
3628 * as : Ptr to parsed command line arguments.
3631 * 0 Successful operation
3634 * Nothing interesting.
3638 *------------------------------------------------------------------------*/
3641 ListVolumes(struct cmd_syndesc *as, void *arock)
3643 afs_int32 apart, int32list, fast;
3647 volintInfo *oldpntr = NULL;
3651 volintXInfo *xInfoP;
3652 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3653 int wantExtendedInfo; /*Do we want extended vol info? */
3656 struct partList dummyPartList;
3664 if (as->parms[3].items)
3666 if (as->parms[4].items)
3670 if (as->parms[2].items)