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;
1718 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1721 PrintError("", err);
1723 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1724 as->parms[0].items->data);
1728 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1731 "Could not fetch the entry for volume number %lu from VLDB \n",
1732 (unsigned long)volid);
1735 MapHostToNetwork(&entry);
1737 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1738 if (previdx == -1) {
1739 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1740 as->parms[0].items->data);
1744 init_volintInfo(&info);
1748 if (as->parms[1].items) {
1750 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1752 fprintf(STDERR, "invalid quota value\n");
1756 if (as->parms[2].items) {
1760 if (as->parms[3].items) {
1761 /* -clearVolUpCounter */
1764 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1767 "Could not update volume info fields for volume number %lu\n",
1768 (unsigned long)volid);
1772 /*------------------------------------------------------------------------
1776 * Brings a volume online.
1779 * as : Ptr to parsed command line arguments.
1782 * 0 for a successful operation,
1785 * Nothing interesting.
1789 *------------------------------------------------------------------------
1792 volOnline(struct cmd_syndesc *as, void *arock)
1795 afs_int32 partition;
1797 afs_int32 code, err = 0;
1799 server = GetServer(as->parms[0].items->data);
1801 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1802 as->parms[0].items->data);
1806 partition = volutil_GetPartitionID(as->parms[1].items->data);
1807 if (partition < 0) {
1808 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1809 as->parms[1].items->data);
1813 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1816 PrintError("", err);
1818 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1819 as->parms[0].items->data);
1823 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1826 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1833 /*------------------------------------------------------------------------
1834 * PRIVATE volOffline
1837 * Brings a volume offline.
1840 * as : Ptr to parsed command line arguments.
1843 * 0 for a successful operation,
1846 * Nothing interesting.
1850 *------------------------------------------------------------------------
1853 volOffline(struct cmd_syndesc *as, void *arock)
1856 afs_int32 partition;
1858 afs_int32 code, err = 0;
1859 afs_int32 transflag, sleeptime, transdone;
1861 server = GetServer(as->parms[0].items->data);
1863 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1864 as->parms[0].items->data);
1868 partition = volutil_GetPartitionID(as->parms[1].items->data);
1869 if (partition < 0) {
1870 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1871 as->parms[1].items->data);
1875 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1878 PrintError("", err);
1880 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1881 as->parms[0].items->data);
1885 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1886 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1887 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1888 if (as->parms[4].items && !as->parms[3].items) {
1889 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1894 UV_SetVolume(server, partition, volid, transflag, transdone,
1897 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1905 CreateVolume(struct cmd_syndesc *as, void *arock)
1909 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1910 afs_uint32 *arovolid;
1912 struct nvldbentry entry;
1917 arovolid = &rovolid;
1920 tserver = GetServer(as->parms[0].items->data);
1922 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1923 as->parms[0].items->data);
1926 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1928 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1929 as->parms[1].items->data);
1932 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1934 PrintError("", code);
1937 "vos : partition %s does not exist on the server\n",
1938 as->parms[1].items->data);
1941 if (!ISNAMEVALID(as->parms[2].items->data)) {
1943 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1944 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1947 if (!VolNameOK(as->parms[2].items->data)) {
1949 "Illegal volume name %s, should not end in .readonly or .backup\n",
1950 as->parms[2].items->data);
1953 if (IsNumeric(as->parms[2].items->data)) {
1954 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1955 as->parms[2].items->data);
1958 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1960 fprintf(STDERR, "Volume %s already exists\n",
1961 as->parms[2].items->data);
1962 PrintDiagnostics("create", code);
1966 if (as->parms[3].items) {
1967 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1969 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1974 if (as->parms[4].items) {
1975 if (!IsNumeric(as->parms[4].items->data)) {
1976 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1977 as->parms[4].items->data);
1981 code = util_GetUInt32(as->parms[4].items->data, &volid);
1983 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1988 if (as->parms[5].items) {
1989 if (!IsNumeric(as->parms[5].items->data)) {
1990 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1991 as->parms[5].items->data);
1995 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1997 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2007 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2008 0, 0, 0, &volid, arovolid, &bkvolid);
2010 PrintDiagnostics("create", code);
2013 MapPartIdIntoName(pnum, part);
2014 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2015 (unsigned long)volid, part, as->parms[0].items->data);
2022 DeleteAll(struct nvldbentry *entry)
2025 afs_int32 error, code, curserver, curpart;
2028 MapHostToNetwork(entry);
2030 for (i = 0; i < entry->nServers; i++) {
2031 curserver = entry->serverNumber[i];
2032 curpart = entry->serverPartition[i];
2033 if (entry->serverFlags[i] & ITSROVOL) {
2034 volid = entry->volumeId[ROVOL];
2036 volid = entry->volumeId[RWVOL];
2038 code = UV_DeleteVolume(curserver, curpart, volid);
2047 DeleteVolume(struct cmd_syndesc *as, void *arock)
2049 afs_int32 err, code = 0;
2050 afs_uint32 server = 0;
2051 afs_int32 partition = -1;
2056 if (as->parms[0].items) {
2057 server = GetServer(as->parms[0].items->data);
2059 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2060 as->parms[0].items->data);
2065 if (as->parms[1].items) {
2066 partition = volutil_GetPartitionID(as->parms[1].items->data);
2067 if (partition < 0) {
2068 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2069 as->parms[1].items->data);
2073 /* Check for validity of the partition */
2074 if (!IsPartValid(partition, server, &code)) {
2076 PrintError("", code);
2079 "vos : partition %s does not exist on the server\n",
2080 as->parms[1].items->data);
2086 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2088 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2089 as->parms[2].items->data);
2091 PrintError("", err);
2095 /* If the server or partition option are not complete, try to fill
2096 * them in from the VLDB entry.
2098 if ((partition == -1) || !server) {
2099 struct nvldbentry entry;
2101 code = VLDB_GetEntryByID(volid, -1, &entry);
2104 "Could not fetch the entry for volume %lu from VLDB\n",
2105 (unsigned long)volid);
2106 PrintError("", code);
2110 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2111 || ((volid == entry.volumeId[BACKVOL])
2112 && (entry.flags & BACK_EXISTS))) {
2113 idx = Lp_GetRwIndex(&entry);
2114 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2115 || ((partition != -1)
2116 && (partition != entry.serverPartition[idx]))) {
2117 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2118 as->parms[2].items->data);
2121 } else if ((volid == entry.volumeId[ROVOL])
2122 && (entry.flags & RO_EXISTS)) {
2123 for (idx = -1, j = 0; j < entry.nServers; j++) {
2124 if (entry.serverFlags[j] != ITSROVOL)
2127 if (((server == 0) || (server == entry.serverNumber[j]))
2128 && ((partition == -1)
2129 || (partition == entry.serverPartition[j]))) {
2132 "VLDB: Volume '%s' matches more than one RO\n",
2133 as->parms[2].items->data);
2140 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2141 as->parms[2].items->data);
2145 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2146 as->parms[2].items->data);
2150 server = htonl(entry.serverNumber[idx]);
2151 partition = entry.serverPartition[idx];
2155 code = UV_DeleteVolume(server, partition, volid);
2157 PrintDiagnostics("remove", code);
2161 MapPartIdIntoName(partition, pname);
2162 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2163 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2167 #define TESTM 0 /* set for move space tests, clear for production */
2169 MoveVolume(struct cmd_syndesc *as, void *arock)
2173 afs_uint32 fromserver, toserver;
2174 afs_int32 frompart, topart;
2175 afs_int32 flags, code, err;
2176 char fromPartName[10], toPartName[10];
2178 struct diskPartition64 partition; /* for space check */
2181 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2184 PrintError("", err);
2186 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2187 as->parms[0].items->data);
2190 fromserver = GetServer(as->parms[1].items->data);
2191 if (fromserver == 0) {
2192 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2193 as->parms[1].items->data);
2196 toserver = GetServer(as->parms[3].items->data);
2197 if (toserver == 0) {
2198 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2199 as->parms[3].items->data);
2202 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2204 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2205 as->parms[2].items->data);
2208 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2210 PrintError("", code);
2213 "vos : partition %s does not exist on the server\n",
2214 as->parms[2].items->data);
2217 topart = volutil_GetPartitionID(as->parms[4].items->data);
2219 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2220 as->parms[4].items->data);
2223 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2225 PrintError("", code);
2228 "vos : partition %s does not exist on the server\n",
2229 as->parms[4].items->data);
2234 if (as->parms[5].items) flags |= RV_NOCLONE;
2237 * check source partition for space to clone volume
2240 MapPartIdIntoName(topart, toPartName);
2241 MapPartIdIntoName(frompart, fromPartName);
2244 * check target partition for space to move volume
2247 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2249 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2253 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2256 p = (volintInfo *) 0;
2257 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2259 fprintf(STDERR, "vos:cannot access volume %lu\n",
2260 (unsigned long)volid);
2264 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2266 if (partition.free <= p->size) {
2268 "vos: no space on target partition %s to move volume %lu\n",
2269 toPartName, (unsigned long)volid);
2276 fprintf(STDOUT, "size test - don't do move\n");
2280 /* successful move still not guaranteed but shoot for it */
2283 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2285 PrintDiagnostics("move", code);
2288 MapPartIdIntoName(topart, toPartName);
2289 MapPartIdIntoName(frompart, fromPartName);
2290 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2291 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2292 as->parms[3].items->data, toPartName);
2298 CopyVolume(struct cmd_syndesc *as, void *arock)
2301 afs_uint32 fromserver, toserver;
2302 afs_int32 frompart, topart, code, err, flags;
2303 char fromPartName[10], toPartName[10], *tovolume;
2304 struct nvldbentry entry;
2305 struct diskPartition64 partition; /* for space check */
2308 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2311 PrintError("", err);
2313 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2314 as->parms[0].items->data);
2317 fromserver = GetServer(as->parms[1].items->data);
2318 if (fromserver == 0) {
2319 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2320 as->parms[1].items->data);
2324 toserver = GetServer(as->parms[4].items->data);
2325 if (toserver == 0) {
2326 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2327 as->parms[4].items->data);
2331 tovolume = as->parms[3].items->data;
2332 if (!ISNAMEVALID(tovolume)) {
2334 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2335 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2338 if (!VolNameOK(tovolume)) {
2340 "Illegal volume name %s, should not end in .readonly or .backup\n",
2344 if (IsNumeric(tovolume)) {
2345 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2349 code = VLDB_GetEntryByName(tovolume, &entry);
2351 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2352 PrintDiagnostics("copy", code);
2356 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2358 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2359 as->parms[2].items->data);
2362 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2364 PrintError("", code);
2367 "vos : partition %s does not exist on the server\n",
2368 as->parms[2].items->data);
2372 topart = volutil_GetPartitionID(as->parms[5].items->data);
2374 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2375 as->parms[5].items->data);
2378 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2380 PrintError("", code);
2383 "vos : partition %s does not exist on the server\n",
2384 as->parms[5].items->data);
2389 if (as->parms[6].items) flags |= RV_OFFLINE;
2390 if (as->parms[7].items) flags |= RV_RDONLY;
2391 if (as->parms[8].items) flags |= RV_NOCLONE;
2393 MapPartIdIntoName(topart, toPartName);
2394 MapPartIdIntoName(frompart, fromPartName);
2397 * check target partition for space to move volume
2400 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2402 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2406 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2409 p = (volintInfo *) 0;
2410 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2412 fprintf(STDERR, "vos:cannot access volume %lu\n",
2413 (unsigned long)volid);
2417 if (partition.free <= p->size) {
2419 "vos: no space on target partition %s to copy volume %lu\n",
2420 toPartName, (unsigned long)volid);
2426 /* successful copy still not guaranteed but shoot for it */
2429 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2432 PrintDiagnostics("copy", code);
2435 MapPartIdIntoName(topart, toPartName);
2436 MapPartIdIntoName(frompart, fromPartName);
2437 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2438 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2439 tovolume, as->parms[4].items->data, toPartName);
2446 ShadowVolume(struct cmd_syndesc *as, void *arock)
2448 afs_uint32 volid, tovolid;
2449 afs_uint32 fromserver, toserver;
2450 afs_int32 frompart, topart;
2451 afs_int32 code, err, flags;
2452 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2453 struct diskPartition64 partition; /* for space check */
2456 p = (volintInfo *) 0;
2457 q = (volintInfo *) 0;
2459 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2462 PrintError("", err);
2464 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2465 as->parms[0].items->data);
2468 fromserver = GetServer(as->parms[1].items->data);
2469 if (fromserver == 0) {
2470 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2471 as->parms[1].items->data);
2475 toserver = GetServer(as->parms[3].items->data);
2476 if (toserver == 0) {
2477 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2478 as->parms[3].items->data);
2482 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2484 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2485 as->parms[2].items->data);
2488 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2490 PrintError("", code);
2493 "vos : partition %s does not exist on the server\n",
2494 as->parms[2].items->data);
2498 topart = volutil_GetPartitionID(as->parms[4].items->data);
2500 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2501 as->parms[4].items->data);
2504 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2506 PrintError("", code);
2509 "vos : partition %s does not exist on the server\n",
2510 as->parms[4].items->data);
2514 if (as->parms[5].items) {
2515 tovolume = as->parms[5].items->data;
2516 if (!ISNAMEVALID(tovolume)) {
2518 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2519 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2522 if (!VolNameOK(tovolume)) {
2524 "Illegal volume name %s, should not end in .readonly or .backup\n",
2528 if (IsNumeric(tovolume)) {
2530 "Illegal volume name %s, should not be a number\n",
2535 /* use actual name of source volume */
2536 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2538 fprintf(STDERR, "vos:cannot access volume %lu\n",
2539 (unsigned long)volid);
2542 strcpy(toVolName, p->name);
2543 tovolume = toVolName;
2544 /* save p for size checks later */
2547 if (as->parms[6].items) {
2548 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2551 PrintError("", err);
2553 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2554 as->parms[6].items->data);
2560 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2563 PrintError("", err);
2565 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2574 if (as->parms[7].items) flags |= RV_OFFLINE;
2575 if (as->parms[8].items) flags |= RV_RDONLY;
2576 if (as->parms[9].items) flags |= RV_NOCLONE;
2577 if (as->parms[10].items) flags |= RV_CPINCR;
2579 MapPartIdIntoName(topart, toPartName);
2580 MapPartIdIntoName(frompart, fromPartName);
2583 * check target partition for space to move volume
2586 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2588 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2592 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2595 /* Don't do this again if we did it above */
2597 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2599 fprintf(STDERR, "vos:cannot access volume %lu\n",
2600 (unsigned long)volid);
2605 /* OK if this fails */
2606 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2608 /* Treat existing volume size as "free" */
2610 p->size = (q->size < p->size) ? p->size - q->size : 0;
2612 if (partition.free <= p->size) {
2614 "vos: no space on target partition %s to copy volume %lu\n",
2615 toPartName, (unsigned long)volid);
2623 /* successful copy still not guaranteed but shoot for it */
2626 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2627 topart, tovolid, flags);
2629 PrintDiagnostics("shadow", code);
2632 MapPartIdIntoName(topart, toPartName);
2633 MapPartIdIntoName(frompart, fromPartName);
2634 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2635 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2636 as->parms[3].items->data, toPartName);
2643 CloneVolume(struct cmd_syndesc *as, void *arock)
2645 afs_uint32 volid, cloneid;
2647 afs_int32 part, voltype;
2648 char partName[10], *volname;
2649 afs_int32 code, err, flags;
2650 struct nvldbentry entry;
2652 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2655 PrintError("", err);
2657 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2658 as->parms[0].items->data);
2662 if (as->parms[1].items || as->parms[2].items) {
2663 if (!as->parms[1].items || !as->parms[2].items) {
2665 "Must specify both -server and -partition options\n");
2668 server = GetServer(as->parms[1].items->data);
2670 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2671 as->parms[1].items->data);
2674 part = volutil_GetPartitionID(as->parms[2].items->data);
2676 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2677 as->parms[2].items->data);
2680 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2682 PrintError("", code);
2685 "vos : partition %s does not exist on the server\n",
2686 as->parms[2].items->data);
2690 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2696 if (as->parms[3].items) {
2697 volname = as->parms[3].items->data;
2698 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2700 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2701 volname, VOLSER_OLDMAXVOLNAME - 1);
2706 * In order that you be able to make clones of RO or BK, this
2707 * check must be omitted.
2709 if (!VolNameOK(volname)) {
2711 "Illegal volume name %s, should not end in .readonly or .backup\n",
2716 if (IsNumeric(volname)) {
2718 "Illegal volume name %s, should not be a number\n",
2725 if (as->parms[4].items) {
2726 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2729 PrintError("", err);
2731 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2732 as->parms[4].items->data);
2738 if (as->parms[5].items) flags |= RV_OFFLINE;
2739 if (as->parms[6].items && as->parms[7].items) {
2740 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2743 if (as->parms[6].items) flags |= RV_RDONLY;
2744 if (as->parms[7].items) flags |= RV_RWONLY;
2748 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2751 PrintDiagnostics("clone", code);
2754 MapPartIdIntoName(part, partName);
2755 fprintf(STDOUT, "Created clone for volume %s\n",
2756 as->parms[0].items->data);
2763 BackupVolume(struct cmd_syndesc *as, void *arock)
2767 afs_int32 apart, vtype, code, err;
2768 struct nvldbentry entry;
2771 afs_uint32 buserver;
2772 afs_int32 bupart, butype;
2773 struct nvldbentry buentry;
2775 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2778 PrintError("", err);
2780 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2781 as->parms[0].items->data);
2784 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2788 /* verify this is a readwrite volume */
2790 if (vtype != RWVOL) {
2791 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2795 /* is there a backup volume already? */
2797 if (entry.flags & BACK_EXISTS) {
2798 /* yep, where is it? */
2800 buvolid = entry.volumeId[BACKVOL];
2801 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2806 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2809 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2815 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2816 (unsigned long)buvolid, (unsigned long)buserver);
2821 /* nope, carry on */
2823 code = UV_BackupVolume(aserver, apart, avolid);
2826 PrintDiagnostics("backup", code);
2829 fprintf(STDOUT, "Created backup volume for %s \n",
2830 as->parms[0].items->data);
2835 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2838 struct nvldbentry entry;
2841 afs_int32 apart, vtype, code, err;
2845 if (as->parms[1].items)
2847 if (as->parms[2].items)
2849 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2852 PrintError("", err);
2854 fprintf(STDERR, "vos: can't find volume '%s'\n",
2855 as->parms[0].items->data);
2858 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2862 if (vtype != RWVOL) {
2863 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2867 if (!ISNAMEVALID(entry.name)) {
2869 "Volume name %s is too long, rename before releasing\n",
2874 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2877 PrintDiagnostics("release", code);
2880 fprintf(STDOUT, "Released volume %s successfully\n",
2881 as->parms[0].items->data);
2886 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2890 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2891 char filename[MAXPATHLEN];
2892 struct nvldbentry entry;
2894 rx_SetRxDeadTime(60 * 10);
2895 for (i = 0; i < MAXSERVERS; i++) {
2896 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2899 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2900 if (rx_ServiceOf(rxConn))
2901 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2904 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2907 PrintError("", err);
2909 fprintf(STDERR, "vos: can't find volume '%s'\n",
2910 as->parms[0].items->data);
2914 if (as->parms[3].items || as->parms[4].items) {
2915 if (!as->parms[3].items || !as->parms[4].items) {
2917 "Must specify both -server and -partition options\n");
2920 aserver = GetServer(as->parms[3].items->data);
2922 fprintf(STDERR, "Invalid server name\n");
2925 apart = volutil_GetPartitionID(as->parms[4].items->data);
2927 fprintf(STDERR, "Invalid partition name\n");
2931 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2936 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2937 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2939 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2940 as->parms[1].items->data, code);
2944 if (as->parms[2].items) {
2945 strcpy(filename, as->parms[2].items->data);
2947 strcpy(filename, "");
2950 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2952 if (as->parms[5].items) {
2954 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2955 DumpFunction, filename, flags);
2958 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2961 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2962 flags &= ~VOLDUMPV2_OMITDIRS;
2966 PrintDiagnostics("dump", code);
2969 if (strcmp(filename, ""))
2970 fprintf(STDERR, "Dumped volume %s in file %s\n",
2971 as->parms[0].items->data, filename);
2973 fprintf(STDERR, "Dumped volume %s in stdout \n",
2974 as->parms[0].items->data);
2988 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2990 afs_uint32 avolid, aparentid;
2992 afs_int32 apart, code, vcode, err;
2993 afs_int32 aoverwrite = ASK;
2994 afs_int32 acreation = 0, alastupdate = 0;
2995 int restoreflags = 0;
2996 int readonly = 0, offline = 0, voltype = RWVOL;
2997 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2998 char volname[VOLSER_MAXVOLNAME + 1];
2999 struct nvldbentry entry;
3002 if (as->parms[4].items) {
3003 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3006 PrintError("", err);
3008 fprintf(STDERR, "vos: can't find volume '%s'\n",
3009 as->parms[4].items->data);
3015 if (as->parms[5].items) {
3016 if ((strcmp(as->parms[5].items->data, "a") == 0)
3017 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3019 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3020 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3022 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3023 || (strcmp(as->parms[5].items->data, "inc") == 0)
3024 || (strcmp(as->parms[5].items->data, "increment") == 0)
3025 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3028 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3029 as->parms[5].items->data);
3033 if (as->parms[6].items)
3035 if (as->parms[7].items) {
3040 if (as->parms[8].items) {
3041 if ((strcmp(as->parms[8].items->data, "d") == 0)
3042 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3043 acreation = TS_DUMP;
3044 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3045 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3046 acreation = TS_KEEP;
3047 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3048 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3051 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3052 as->parms[8].items->data);
3057 if (as->parms[9].items) {
3058 if ((strcmp(as->parms[9].items->data, "d") == 0)
3059 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3060 alastupdate = TS_DUMP;
3061 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3062 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3063 alastupdate = TS_KEEP;
3064 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3065 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3066 alastupdate = TS_NEW;
3068 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3069 as->parms[9].items->data);
3074 aserver = GetServer(as->parms[0].items->data);
3076 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3077 as->parms[0].items->data);
3080 apart = volutil_GetPartitionID(as->parms[1].items->data);
3082 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3083 as->parms[1].items->data);
3086 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3088 PrintError("", code);
3091 "vos : partition %s does not exist on the server\n",
3092 as->parms[1].items->data);
3095 strcpy(avolname, as->parms[2].items->data);
3096 if (!ISNAMEVALID(avolname)) {
3098 "vos: the name of the volume %s exceeds the size limit\n",
3102 if (!VolNameOK(avolname)) {
3104 "Illegal volume name %s, should not end in .readonly or .backup\n",
3108 if (as->parms[3].items) {
3109 strcpy(afilename, as->parms[3].items->data);
3110 if (!FileExists(afilename)) {
3111 fprintf(STDERR, "Can't access file %s\n", afilename);
3115 strcpy(afilename, "");
3118 /* Check if volume exists or not */
3120 vsu_ExtractName(volname, avolname);
3121 vcode = VLDB_GetEntryByName(volname, &entry);
3122 if (vcode) { /* no volume - do a full restore */
3123 restoreflags = RV_FULLRST;
3124 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3126 "Volume does not exist; Will perform a full restore\n");
3129 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3130 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3131 restoreflags = RV_FULLRST;
3132 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3134 "%s Volume does not exist; Will perform a full restore\n",
3135 readonly ? "RO" : "RW");
3138 avolid = entry.volumeId[voltype];
3139 } else if (entry.volumeId[voltype] != 0
3140 && entry.volumeId[voltype] != avolid) {
3141 avolid = entry.volumeId[voltype];
3143 aparentid = entry.volumeId[RWVOL];
3146 else { /* volume exists - do we do a full incremental or abort */
3148 afs_int32 Opart, Otype, vol_elsewhere = 0;
3149 struct nvldbentry Oentry;
3153 avolid = entry.volumeId[voltype];
3154 } else if (entry.volumeId[voltype] != 0
3155 && entry.volumeId[voltype] != avolid) {
3156 avolid = entry.volumeId[voltype];
3158 aparentid = entry.volumeId[RWVOL];
3160 /* A file name was specified - check if volume is on another partition */
3161 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3165 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3168 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3172 if (!vcode || (Opart != apart))
3175 if (aoverwrite == ASK) {
3176 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3178 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3182 /* Ask what to do */
3183 if (vol_elsewhere) {
3185 "The volume %s %u already exists on a different server/part\n",
3186 volname, entry.volumeId[voltype]);
3188 "Do you want to do a full restore or abort? [fa](a): ");
3191 "The volume %s %u already exists in the VLDB\n",
3192 volname, entry.volumeId[voltype]);
3194 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3197 while (!(dc == EOF || dc == '\n'))
3198 dc = getchar(); /* goto end of line */
3199 if ((c == 'f') || (c == 'F'))
3201 else if ((c == 'i') || (c == 'I'))
3207 if (aoverwrite == ABORT) {
3208 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3210 } else if (aoverwrite == FULL) {
3211 restoreflags = RV_FULLRST;
3213 "Volume exists; Will delete and perform full restore\n");
3214 } else if (aoverwrite == INC) {
3216 if (vol_elsewhere) {
3218 "%s volume %lu already exists on a different server/part; not allowed\n",
3219 readonly ? "RO" : "RW", (unsigned long)avolid);
3225 restoreflags |= RV_OFFLINE;
3227 restoreflags |= RV_RDONLY;
3229 switch (acreation) {
3231 restoreflags |= RV_CRDUMP;
3234 restoreflags |= RV_CRKEEP;
3237 restoreflags |= RV_CRNEW;
3240 if (aoverwrite == FULL)
3241 restoreflags |= RV_CRNEW;
3243 restoreflags |= RV_CRKEEP;
3246 switch (alastupdate) {
3248 restoreflags |= RV_LUDUMP;
3251 restoreflags |= RV_LUKEEP;
3254 restoreflags |= RV_LUNEW;
3257 restoreflags |= RV_LUDUMP;
3259 if (as->parms[10].items) {
3260 restoreflags |= RV_NODEL;
3265 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3266 avolname, restoreflags, WriteData, afilename);
3268 PrintDiagnostics("restore", code);
3271 MapPartIdIntoName(apart, apartName);
3274 * patch typo here - originally "parms[1]", should be "parms[0]"
3277 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3278 as->parms[0].items->data, apartName);
3283 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3286 afs_int32 code, err;
3288 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3291 PrintError("", err);
3293 fprintf(STDERR, "vos: can't find volume '%s'\n",
3294 as->parms[0].items->data);
3298 code = UV_LockRelease(avolid);
3300 PrintDiagnostics("unlock", code);
3303 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3304 as->parms[0].items->data);
3309 AddSite(struct cmd_syndesc *as, void *arock)
3313 afs_int32 apart, code, err, arovolid, valid = 0;
3314 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3316 vsu_ExtractName(avolname, as->parms[2].items->data);;
3317 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3320 PrintError("", err);
3322 fprintf(STDERR, "vos: can't find volume '%s'\n",
3323 as->parms[2].items->data);
3327 if (as->parms[3].items) {
3328 vsu_ExtractName(avolname, as->parms[3].items->data);
3329 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3331 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3332 as->parms[3].items->data);
3336 aserver = GetServer(as->parms[0].items->data);
3338 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3339 as->parms[0].items->data);
3342 apart = volutil_GetPartitionID(as->parms[1].items->data);
3344 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3345 as->parms[1].items->data);
3348 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3350 PrintError("", code);
3353 "vos : partition %s does not exist on the server\n",
3354 as->parms[1].items->data);
3357 if (as->parms[4].items) {
3360 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3362 PrintDiagnostics("addsite", code);
3365 MapPartIdIntoName(apart, apartName);
3366 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3367 as->parms[0].items->data, apartName, as->parms[2].items->data);
3372 RemoveSite(struct cmd_syndesc *as, void *arock)
3377 afs_int32 apart, code, err;
3378 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3380 vsu_ExtractName(avolname, as->parms[2].items->data);
3381 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3384 PrintError("", err);
3386 fprintf(STDERR, "vos: can't find volume '%s'\n",
3387 as->parms[2].items->data);
3390 aserver = GetServer(as->parms[0].items->data);
3392 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3393 as->parms[0].items->data);
3396 apart = volutil_GetPartitionID(as->parms[1].items->data);
3398 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3399 as->parms[1].items->data);
3403 *skip the partition validity check, since it is possible that the partition
3404 *has since been decomissioned.
3407 if (!IsPartValid(apart,aserver,&code)){
3408 if(code) PrintError("",code);
3409 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3413 code = UV_RemoveSite(aserver, apart, avolid);
3415 PrintDiagnostics("remsite", code);
3418 MapPartIdIntoName(apart, apartName);
3419 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3420 as->parms[0].items->data, apartName, as->parms[2].items->data);
3425 ChangeLocation(struct cmd_syndesc *as, void *arock)
3429 afs_int32 apart, code, err;
3432 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3435 PrintError("", err);
3437 fprintf(STDERR, "vos: can't find volume '%s'\n",
3438 as->parms[2].items->data);
3441 aserver = GetServer(as->parms[0].items->data);
3443 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3444 as->parms[0].items->data);
3447 apart = volutil_GetPartitionID(as->parms[1].items->data);
3449 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3450 as->parms[1].items->data);
3453 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3455 PrintError("", code);
3458 "vos : partition %s does not exist on the server\n",
3459 as->parms[1].items->data);
3462 code = UV_ChangeLocation(aserver, apart, avolid);
3464 PrintDiagnostics("changeloc", code);
3467 MapPartIdIntoName(apart, apartName);
3468 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3469 as->parms[0].items->data, apartName, as->parms[2].items->data);
3474 ListPartitions(struct cmd_syndesc *as, void *arock)
3478 struct partList dummyPartList;
3483 aserver = GetServer(as->parms[0].items->data);
3485 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3486 as->parms[0].items->data);
3491 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3493 PrintDiagnostics("listpart", code);
3497 fprintf(STDOUT, "The partitions on the server are:\n");
3498 for (i = 0; i < cnt; i++) {
3499 if (dummyPartList.partFlags[i] & PARTVALID) {
3500 memset(pname, 0, sizeof(pname));
3501 MapPartIdIntoName(dummyPartList.partId[i], pname);
3502 fprintf(STDOUT, " %10s ", pname);
3504 if ((i % 5) == 0 && (i != 0))
3505 fprintf(STDOUT, "\n");
3508 fprintf(STDOUT, "\n");
3509 fprintf(STDOUT, "Total: %d\n", total);
3515 CompareVolName(const void *p1, const void *p2)
3517 volintInfo *arg1, *arg2;
3519 arg1 = (volintInfo *) p1;
3520 arg2 = (volintInfo *) p2;
3521 return (strcmp(arg1->name, arg2->name));
3525 /*------------------------------------------------------------------------
3526 * PRIVATE XCompareVolName
3529 * Comparison routine for volume names coming from an extended
3533 * a_obj1P : Char ptr to first extended vol info object
3534 * a_obj1P : Char ptr to second extended vol info object
3537 * The value of strcmp() on the volume names within the passed
3538 * objects (i,e., -1, 0, or 1).
3541 * Passed to qsort() as the designated comparison routine.
3545 *------------------------------------------------------------------------*/
3548 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3549 { /*XCompareVolName */
3552 (((struct volintXInfo *)(a_obj1P))->name,
3553 ((struct volintXInfo *)(a_obj2P))->name));
3555 } /*XCompareVolName */
3558 CompareVolID(const void *p1, const void *p2)
3560 volintInfo *arg1, *arg2;
3562 arg1 = (volintInfo *) p1;
3563 arg2 = (volintInfo *) p2;
3564 if (arg1->volid == arg2->volid)
3566 if (arg1->volid > arg2->volid)
3573 /*------------------------------------------------------------------------
3574 * PRIVATE XCompareVolID
3577 * Comparison routine for volume IDs coming from an extended
3581 * a_obj1P : Char ptr to first extended vol info object
3582 * a_obj1P : Char ptr to second extended vol info object
3585 * The value of strcmp() on the volume names within the passed
3586 * objects (i,e., -1, 0, or 1).
3589 * Passed to qsort() as the designated comparison routine.
3593 *------------------------------------------------------------------------*/
3596 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3597 { /*XCompareVolID */
3599 afs_int32 id1, id2; /*Volume IDs we're comparing */
3601 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3602 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3610 } /*XCompareVolID */
3612 /*------------------------------------------------------------------------
3613 * PRIVATE ListVolumes
3616 * Routine used to list volumes, contacting the Volume Server
3617 * directly, bypassing the VLDB.
3620 * as : Ptr to parsed command line arguments.
3623 * 0 Successful operation
3626 * Nothing interesting.
3630 *------------------------------------------------------------------------*/
3633 ListVolumes(struct cmd_syndesc *as, void *arock)
3635 afs_int32 apart, int32list, fast;
3639 volintInfo *oldpntr = NULL;
3643 volintXInfo *xInfoP;
3644 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3645 int wantExtendedInfo; /*Do we want extended vol info? */
3648 struct partList dummyPartList;
3656 if (as->parms[3].items)
3658 if (as->parms[4].items)
3662 if (as->parms[2].items)
3668 if (as->parms[5].items) {
3670 * We can't coexist with the fast flag.
3674 "vos: Can't use the -fast and -extended flags together\n");
3679 * We need to turn on ``long'' listings to get the full effect.
3681 wantExtendedInfo = 1;
3684 wantExtendedInfo = 0;
3685 if (as->parms[1].items) {
3686 apart = volutil_GetPartitionID(as->parms[1].items->data);
3688 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3689 as->parms[1].items->data);
3692 dummyPartList.partId[0] = apart;
3693 dummyPartList.partFlags[0] = PARTVALID;
3696 aserver = GetServer(as->parms[0].items->data);
3698 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3699 as->parms[0].items->data);
3704 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3706 PrintError("", code);
3709 "vos : partition %s does not exist on the server\n",
3710 as->parms[1].items->data);
3714 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3716 PrintDiagnostics("listvol", code);
3720 for (i = 0; i < cnt; i++) {
3721 if (dummyPartList.partFlags[i] & PARTVALID) {
3722 if (wantExtendedInfo)
3724 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3728 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3731 PrintDiagnostics("listvol", code);
3734 if (wantExtendedInfo) {
3735 origxInfoP = xInfoP;
3736 base = (char *)xInfoP;
3739 base = (char *)pntr;
3743 if (wantExtendedInfo)
3744 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3746 qsort(base, count, sizeof(volintInfo), CompareVolName);
3748 if (wantExtendedInfo)
3749 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3751 qsort(base, count, sizeof(volintInfo), CompareVolID);
3753 MapPartIdIntoName(dummyPartList.partId[i], pname);
3756 "Total number of volumes on server %s partition %s: %lu \n",
3757 as->parms[0].items->data, pname,
3758 (unsigned long)count);
3759 if (wantExtendedInfo) {
3760 if (as->parms[6].items)
3761 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3762 count, int32list, fast, quiet);
3764 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3765 count, int32list, fast, quiet);
3768 xInfoP = (volintXInfo *) 0;
3770 if (as->parms[6].items)
3771 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3774 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3775 count, int32list, fast, quiet);
3778 pntr = (volintInfo *) 0;
3786 SyncVldb(struct cmd_syndesc *as, void *arock)
3788 afs_int32 pnum = 0, code; /* part name */
3795 if (as->parms[0].items) {
3796 tserver = GetServer(as->parms[0].items->data);
3798 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3799 as->parms[0].items->data);
3804 if (as->parms[1].items) {
3805 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3807 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3808 as->parms[1].items->data);
3811 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3813 PrintError("", code);
3816 "vos: partition %s does not exist on the server\n",
3817 as->parms[1].items->data);
3824 "The -partition option requires a -server option\n");
3829 if (as->parms[3].items) {
3830 flags |= 2; /* don't update */
3833 if (as->parms[2].items) {
3834 /* Synchronize an individual volume */
3835 volname = as->parms[2].items->data;
3836 code = UV_SyncVolume(tserver, pnum, volname, flags);
3840 "Without a -volume option, the -server option is required\n");
3843 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3847 PrintDiagnostics("syncvldb", code);
3851 /* Print a summary of what we did */
3853 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3855 fprintf(STDOUT, "VLDB synchronized");
3857 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3860 MapPartIdIntoName(pnum, part);
3861 fprintf(STDOUT, " partition %s\n", part);
3863 fprintf(STDOUT, "\n");
3869 SyncServer(struct cmd_syndesc *as, void *arock)
3871 afs_int32 pnum, code; /* part name */
3877 tserver = GetServer(as->parms[0].items->data);
3879 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3880 as->parms[0].items->data);
3883 if (as->parms[1].items) {
3884 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3886 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3887 as->parms[1].items->data);
3890 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3892 PrintError("", code);
3895 "vos : partition %s does not exist on the server\n",
3896 as->parms[1].items->data);
3904 if (as->parms[2].items) {
3905 flags |= 2; /* don't update */
3907 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3909 PrintDiagnostics("syncserv", code);
3913 MapPartIdIntoName(pnum, part);
3914 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3915 as->parms[0].items->data, part);
3917 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3918 as->parms[0].items->data);
3924 VolumeInfoCmd(char *name)
3926 struct nvldbentry entry;
3929 /* The vlserver will handle names with the .readonly
3930 * and .backup extension as well as volume ids.
3932 vcode = VLDB_GetEntryByName(name, &entry);
3934 PrintError("", vcode);
3937 MapHostToNetwork(&entry);
3938 EnumerateEntry(&entry);
3940 /* Defect #3027: grubby check to handle locked volume.
3941 * If VLOP_ALLOPERS is set, the entry is locked.
3942 * Leave this routine as is, but put in correct check.
3944 PrintLocked(entry.flags);
3950 VolumeZap(struct cmd_syndesc *as, void *arock)
3952 struct nvldbentry entry;
3953 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3954 afs_int32 code, server, part, err;
3956 if (as->parms[3].items) {
3957 /* force flag is on, use the other version */
3958 return NukeVolume(as);
3961 if (as->parms[4].items) {
3965 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3968 PrintError("", err);
3970 fprintf(STDERR, "vos: can't find volume '%s'\n",
3971 as->parms[2].items->data);
3974 part = volutil_GetPartitionID(as->parms[1].items->data);
3976 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3977 as->parms[1].items->data);
3980 server = GetServer(as->parms[0].items->data);
3982 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3983 as->parms[0].items->data);
3986 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3988 PrintError("", code);
3991 "vos : partition %s does not exist on the server\n",
3992 as->parms[1].items->data);
3995 code = VLDB_GetEntryByID(volid, -1, &entry);
3997 if (volid == entry.volumeId[RWVOL])
3998 backupid = entry.volumeId[BACKVOL];
4000 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4001 (unsigned long)volid);
4004 volintInfo *pntr = (volintInfo *) 0;
4007 code = UV_ListOneVolume(server, part, volid, &pntr);
4009 if (volid == pntr->parentID)
4010 backupid = pntr->backupID;
4016 code = UV_VolumeZap(server, part, backupid);
4018 PrintDiagnostics("zap", code);
4021 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4022 (unsigned long)backupid);
4025 code = UV_VolumeZap(server, part, volid);
4027 PrintDiagnostics("zap", code);
4030 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4036 VolserStatus(struct cmd_syndesc *as, void *arock)
4040 transDebugInfo *pntr, *oldpntr;
4046 server = GetServer(as->parms[0].items->data);
4048 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4049 as->parms[0].items->data);
4052 code = UV_VolserStatus(server, &pntr, &count);
4054 PrintDiagnostics("status", code);
4059 fprintf(STDOUT, "No active transactions on %s\n",
4060 as->parms[0].items->data);
4062 fprintf(STDOUT, "Total transactions: %d\n", count);
4064 for (i = 0; i < count; i++) {
4065 /*print out the relevant info */
4066 fprintf(STDOUT, "--------------------------------------\n");
4067 t = pntr->creationTime;
4068 fprintf(STDOUT, "transaction: %lu created: %s",
4069 (unsigned long)pntr->tid, ctime(&t));
4071 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4072 if (pntr->returnCode) {
4073 fprintf(STDOUT, "returnCode: %lu\n",
4074 (unsigned long)pntr->returnCode);
4077 fprintf(STDOUT, "attachFlags: ");
4078 switch (pntr->iflags) {
4080 fprintf(STDOUT, "offline ");
4083 fprintf(STDOUT, "busy ");
4086 fprintf(STDOUT, "readonly ");
4089 fprintf(STDOUT, "create ");
4092 fprintf(STDOUT, "create volid ");
4095 fprintf(STDOUT, "\n");
4098 fprintf(STDOUT, "volumeStatus: ");
4099 switch (pntr->vflags) {
4100 case VTDeleteOnSalvage:
4101 fprintf(STDOUT, "deleteOnSalvage ");
4102 case VTOutOfService:
4103 fprintf(STDOUT, "outOfService ");
4105 fprintf(STDOUT, "deleted ");
4107 fprintf(STDOUT, "\n");
4110 fprintf(STDOUT, "transactionFlags: ");
4111 fprintf(STDOUT, "delete\n");
4113 MapPartIdIntoName(pntr->partition, pname);
4114 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4115 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4116 if (pntr->callValid) {
4117 t = pntr->lastReceiveTime;
4118 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4119 (unsigned long)pntr->readNext, ctime(&t));
4120 t = pntr->lastSendTime;
4121 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4122 (unsigned long)pntr->transmitNext, ctime(&t));
4125 fprintf(STDOUT, "--------------------------------------\n");
4126 fprintf(STDOUT, "\n");
4134 RenameVolume(struct cmd_syndesc *as, void *arock)
4136 afs_int32 code1, code2, code;
4137 struct nvldbentry entry;
4139 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4141 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4142 as->parms[0].items->data);
4145 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4146 if ((!code1) && (!code2)) { /*the newname already exists */
4147 fprintf(STDERR, "vos: volume %s already exists\n",
4148 as->parms[1].items->data);
4152 if (code1 && code2) {
4153 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4154 as->parms[0].items->data, as->parms[1].items->data);
4157 if (!VolNameOK(as->parms[0].items->data)) {
4159 "Illegal volume name %s, should not end in .readonly or .backup\n",
4160 as->parms[0].items->data);
4163 if (!ISNAMEVALID(as->parms[1].items->data)) {
4165 "vos: the new volume name %s exceeds the size limit of %d\n",
4166 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4169 if (!VolNameOK(as->parms[1].items->data)) {
4171 "Illegal volume name %s, should not end in .readonly or .backup\n",
4172 as->parms[1].items->data);
4175 if (IsNumeric(as->parms[1].items->data)) {
4176 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4177 as->parms[1].items->data);
4180 MapHostToNetwork(&entry);
4182 UV_RenameVolume(&entry, as->parms[0].items->data,
4183 as->parms[1].items->data);
4185 PrintDiagnostics("rename", code);
4188 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4189 as->parms[1].items->data);
4194 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4195 struct nvldbentry *rentry)
4200 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4203 "Could not fetch the entry for volume %lu from VLDB \n",
4204 (unsigned long)volid);
4205 PrintError("", vcode);
4208 MapHostToNetwork(rentry);
4209 if (volid == rentry->volumeId[ROVOL]) {
4211 for (i = 0; i < rentry->nServers; i++) {
4212 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4213 && !(rentry->serverFlags[i] & RO_DONTUSE))
4218 "RO volume is not found in VLDB entry for volume %lu\n",
4219 (unsigned long)volid);
4223 *server = rentry->serverNumber[index];
4224 *part = rentry->serverPartition[index];
4228 index = Lp_GetRwIndex(rentry);
4231 "RW Volume is not found in VLDB entry for volume %lu\n",
4232 (unsigned long)volid);
4235 if (volid == rentry->volumeId[RWVOL]) {
4237 *server = rentry->serverNumber[index];
4238 *part = rentry->serverPartition[index];
4241 if (volid == rentry->volumeId[BACKVOL]) {
4243 *server = rentry->serverNumber[index];
4244 *part = rentry->serverPartition[index];
4248 "unexpected volume type for volume %lu\n",
4249 (unsigned long)volid);
4254 DeleteEntry(struct cmd_syndesc *as, void *arock)
4256 afs_int32 apart = 0;
4259 struct VldbListByAttributes attributes;
4260 nbulkentries arrayEntries;
4261 struct nvldbentry *vllist;
4262 struct cmd_item *itp;
4265 char prefix[VOLSER_MAXVOLNAME + 1];
4267 afs_int32 totalBack = 0, totalFail = 0, err;
4269 if (as->parms[0].items) { /* -id */
4270 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4272 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4275 for (itp = as->parms[0].items; itp; itp = itp->next) {
4276 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4279 PrintError("", err);
4281 fprintf(STDERR, "vos: can't find volume '%s'\n",
4285 if (as->parms[4].items || as->parms[5].items) {
4286 /* -noexecute (hidden) or -dryrun */
4287 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4292 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4294 fprintf(STDERR, "Could not delete entry for volume %s\n",
4297 "You must specify a RW volume name or ID "
4298 "(the entire VLDB entry will be deleted)\n");
4299 PrintError("", vcode);
4305 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4309 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4310 fprintf(STDERR, "You must specify an option\n");
4314 /* Zero out search attributes */
4315 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4317 if (as->parms[1].items) { /* -prefix */
4318 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4320 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4322 "You must provide -server with the -prefix argument\n");