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>
16 #include <sys/types.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
31 #include <sys/statfs.h>
39 #include <rx/rx_globals.h>
41 #include <afs/vlserver.h>
42 #include <afs/cellconfig.h>
44 #include <afs/afsutil.h>
46 #include <afs/afsint.h>
51 #include <afs/ihandle.h>
52 #include <afs/vnode.h>
53 #include <afs/volume.h>
60 #include "volser_prototypes.h"
62 #ifdef HAVE_POSIX_REGEX
76 #define COMMONPARMS cmd_Seek(ts, 12);\
77 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
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");\
83 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
87 struct rx_connection *tconn;
89 extern struct ubik_client *cstruct;
92 static struct tqHead busyHead, notokHead;
95 qInit(struct tqHead *ahead)
97 memset((char *)ahead, 0, sizeof(struct tqHead));
103 qPut(struct tqHead *ahead, afs_int32 volid)
107 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
108 elem->next = ahead->next;
116 qGet(struct tqHead *ahead, afs_int32 *volid)
120 if (ahead->count <= 0)
122 *volid = ahead->next->volid;
124 ahead->next = tmp->next;
130 /* returns 1 if <filename> exists else 0 */
132 FileExists(char *filename)
138 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
142 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
150 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
152 VolNameOK(char *name)
157 total = strlen(name);
158 if (!strcmp(&name[total - 9], ".readonly")) {
160 } else if (!strcmp(&name[total - 7], ".backup")) {
167 /* return 1 if name is a number else 0 */
169 IsNumeric(char *name)
177 for (i = 0; i < len; i++) {
178 if (*ptr < '0' || *ptr > '9') {
190 * Parse a server name/address and return the address in HOST BYTE order
193 GetServer(char *aname)
195 register struct hostent *th;
198 register afs_int32 code;
199 char hostname[MAXHOSTCHARS];
201 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
203 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
204 addr = ntohl(addr); /* convert to host order */
206 th = gethostbyname(aname);
209 memcpy(&addr, th->h_addr, sizeof(addr));
212 if (addr == htonl(0x7f000001)) { /* local host */
213 code = gethostname(hostname, MAXHOSTCHARS);
216 th = gethostbyname(hostname); /* returns host byte order */
219 memcpy(&addr, th->h_addr, sizeof(addr));
226 GetVolumeType(char *aname)
229 if (!strcmp(aname, "ro"))
231 else if (!strcmp(aname, "rw"))
233 else if (!strcmp(aname, "bk"))
240 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
242 struct partList dummyPartList;
248 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
251 for (i = 0; i < cnt; i++) {
252 if (dummyPartList.partFlags[i] & PARTVALID)
253 if (dummyPartList.partId[i] == partId)
261 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
262 * associated with <call> */
264 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
266 char *buffer = (char *)0;
271 buffer = (char *)malloc(blksize);
273 fprintf(STDERR, "malloc failed\n");
277 while (!error && !done) {
278 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
281 FD_SET((int)(ufd->handle), &in);
282 /* don't timeout if read blocks */
283 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
285 error = USD_READ(ufd, buffer, blksize, &nbytes);
287 fprintf(STDERR, "File system read failed\n");
294 if (rx_Write(call, buffer, nbytes) != nbytes) {
304 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
305 * writes it out to the volume. */
307 WriteData(struct rx_call *call, char *rock)
312 afs_int32 error, code;
314 afs_hyper_t filesize, currOffset;
321 if (!filename || !*filename) {
322 usd_StandardInput(&ufd);
326 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
329 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
332 fprintf(STDERR, "Could not access file '%s'\n", filename);
336 /* test if we have a valid dump */
337 hset64(filesize, 0, 0);
338 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
339 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
340 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
341 USD_READ(ufd, &buffer, sizeof(afs_uint32), &got);
342 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
343 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
347 /* rewind, we are done */
348 hset64(filesize, 0, 0);
349 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
351 code = SendFile(ufd, call, blksize);
358 code = USD_CLOSE(ufd);
360 fprintf(STDERR, "Could not close dump file %s\n",
361 (filename && *filename) ? filename : "STDOUT");
369 /* Receive data from <call> stream into file associated
370 * with <fd> <blksize>
373 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
377 afs_uint32 bytesleft, w;
380 buffer = (char *)malloc(blksize);
382 fprintf(STDERR, "memory allocation failed\n");
386 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
387 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
388 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
391 FD_SET((int)(ufd->handle), &out);
392 /* don't timeout if write blocks */
393 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
396 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
398 fprintf(STDERR, "File system write failed\n");
411 DumpFunction(struct rx_call *call, char *filename)
413 usd_handle_t ufd; /* default is to stdout */
414 afs_int32 error = 0, code;
419 /* Open the output file */
420 if (!filename || !*filename) {
421 usd_StandardOutput(&ufd);
426 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
430 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
433 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
436 fprintf(STDERR, "Could not create file '%s'\n", filename);
437 ERROR_EXIT(VOLSERBADOP);
441 code = ReceiveFile(ufd, call, blksize);
446 /* Close the output file */
448 code = USD_CLOSE(ufd);
450 fprintf(STDERR, "Could not close dump file %s\n",
451 (filename && *filename) ? filename : "STDIN");
462 vos_ctime(afs_int32 *timep)
468 #define vos_ctime ctime
472 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
475 afs_int32 server, part;
476 int *totalOK, *totalNotOK, *totalBusy;
477 int fast, longlist, disp;
482 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
483 } else if (longlist) {
484 if (pntr->status == VOK) {
485 fprintf(STDOUT, "%-32s ", pntr->name);
486 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
488 fprintf(STDOUT, "RW ");
490 fprintf(STDOUT, "RO ");
492 fprintf(STDOUT, "BK ");
493 fprintf(STDOUT, "%10d K ", pntr->size);
494 if (pntr->inUse == 1) {
495 fprintf(STDOUT, "On-line");
498 fprintf(STDOUT, "Off-line");
501 if (pntr->needsSalvaged == 1)
502 fprintf(STDOUT, "**needs salvage**");
503 fprintf(STDOUT, "\n");
504 MapPartIdIntoName(part, pname);
505 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
507 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
508 (unsigned long)pntr->parentID,
509 (unsigned long)pntr->cloneID,
510 (unsigned long)pntr->backupID);
511 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
512 fprintf(STDOUT, " Creation %s",
513 vos_ctime(& pntr->creationDate));
514 #ifdef FULL_LISTVOL_SWITCH
515 fprintf(STDOUT, " Copy %s",
516 vos_ctime( & pntr->copyDate));
517 if (!pntr->backupDate)
518 fprintf(STDOUT, " Backup Never\n");
520 fprintf(STDOUT, " Backup %s",
521 vos_ctime( & pntr->backupDate));
522 if (pntr->accessDate)
523 fprintf(STDOUT, " Last Access %s",
524 vos_ctime( & pntr->accessDate));
526 if (!pntr->updateDate)
527 fprintf(STDOUT, " Last Update Never\n");
529 fprintf(STDOUT, " Last Update %s",
530 vos_ctime( & pntr->updateDate));
532 " %d accesses in the past day (i.e., vnode references)\n",
535 } else if (pntr->status == VBUSY) {
537 qPut(&busyHead, pntr->volid);
539 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
540 (unsigned long)pntr->volid);
543 qPut(¬okHead, pntr->volid);
545 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
546 (unsigned long)pntr->volid);
548 fprintf(STDOUT, "\n");
549 } else { /* default listing */
550 if (pntr->status == VOK) {
551 fprintf(STDOUT, "%-32s ", pntr->name);
552 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
554 fprintf(STDOUT, "RW ");
556 fprintf(STDOUT, "RO ");
558 fprintf(STDOUT, "BK ");
559 fprintf(STDOUT, "%10d K ", pntr->size);
560 if (pntr->inUse == 1) {
561 fprintf(STDOUT, "On-line");
564 fprintf(STDOUT, "Off-line");
567 if (pntr->needsSalvaged == 1)
568 fprintf(STDOUT, "**needs salvage**");
569 fprintf(STDOUT, "\n");
570 } else if (pntr->status == VBUSY) {
572 qPut(&busyHead, pntr->volid);
574 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
575 (unsigned long)pntr->volid);
578 qPut(¬okHead, pntr->volid);
580 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
581 (unsigned long)pntr->volid);
586 /*------------------------------------------------------------------------
587 * PRIVATE XDisplayFormat
590 * Display the contents of one extended volume info structure.
593 * a_xInfoP : Ptr to extended volume info struct to print.
594 * a_servID : Server ID to print.
595 * a_partID : Partition ID to print.
596 * a_totalOKP : Ptr to total-OK counter.
597 * a_totalNotOKP : Ptr to total-screwed counter.
598 * a_totalBusyP : Ptr to total-busy counter.
599 * a_fast : Fast listing?
600 * a_int32 : Int32 listing?
601 * a_showProblems : Show volume problems?
607 * Nothing interesting.
611 *------------------------------------------------------------------------*/
614 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
615 a_totalBusyP, a_fast, a_int32, a_showProblems)
616 volintXInfo *a_xInfoP;
626 { /*XDisplayFormat */
634 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
635 } else if (a_int32) {
637 * Fully-detailed listing.
639 if (a_xInfoP->status == VOK) {
641 * Volume's status is OK - all the fields are valid.
643 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
644 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
645 if (a_xInfoP->type == 0)
646 fprintf(STDOUT, "RW ");
647 if (a_xInfoP->type == 1)
648 fprintf(STDOUT, "RO ");
649 if (a_xInfoP->type == 2)
650 fprintf(STDOUT, "BK ");
651 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
652 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
653 if (a_xInfoP->inUse == 1) {
654 fprintf(STDOUT, "On-line");
657 fprintf(STDOUT, "Off-line");
660 fprintf(STDOUT, "\n");
661 MapPartIdIntoName(a_partID, pname);
662 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
664 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
665 (unsigned long)a_xInfoP->parentID,
666 (unsigned long)a_xInfoP->cloneID,
667 (unsigned long)a_xInfoP->backupID);
668 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
669 fprintf(STDOUT, " Creation %s",
670 vos_ctime( & a_xInfoP->creationDate));
671 #ifdef FULL_LISTVOL_SWITCH
672 fprintf(STDOUT, " Copy %s",
673 vos_ctime( & a_xInfoP->copyDate));
674 if (!a_xInfoP->backupDate)
675 fprintf(STDOUT, " Backup Never\n");
677 fprintf(STDOUT, " Backup %s",
678 vos_ctime( & a_xInfoP->backupDate));
679 if (a_xInfoP->accessDate)
680 fprintf(STDOUT, " Last Access %s",
681 vos_ctime( & a_xInfoP->accessDate));
683 if (!a_xInfoP->updateDate)
684 fprintf(STDOUT, " Last Update Never\n");
686 fprintf(STDOUT, " Last Update %s",
687 vos_ctime( & a_xInfoP->updateDate));
689 " %d accesses in the past day (i.e., vnode references)\n",
694 * Print all the read/write and authorship stats.
696 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
698 " |-------------------------------------------|\n");
700 " | Same Network | Diff Network |\n");
702 " |----------|----------|----------|----------|\n");
704 " | Total | Auth | Total | Auth |\n");
706 " |----------|----------|----------|----------|\n");
707 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
708 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
709 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
710 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
711 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
712 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
713 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
714 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
715 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
716 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
718 " |-------------------------------------------|\n\n");
721 " Writes Affecting Authorship\n");
723 " |-------------------------------------------|\n");
725 " | File Authorship | Directory Authorship|\n");
727 " |----------|----------|----------|----------|\n");
729 " | Same | Diff | Same | Diff |\n");
731 " |----------|----------|----------|----------|\n");
732 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
733 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
734 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
735 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
736 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
737 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
738 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
739 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
740 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
741 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
742 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
743 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
744 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
745 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
746 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
747 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
748 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
749 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
750 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
751 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
752 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
753 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
754 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
755 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
756 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
757 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
758 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
759 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
760 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
761 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
763 " |-------------------------------------------|\n");
764 } /*Volume status OK */
765 else if (a_xInfoP->status == VBUSY) {
767 qPut(&busyHead, a_xInfoP->volid);
769 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
770 (unsigned long)a_xInfoP->volid);
774 qPut(¬okHead, a_xInfoP->volid);
776 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
777 (unsigned long)a_xInfoP->volid);
778 } /*Screwed volume */
779 fprintf(STDOUT, "\n");
785 if (a_xInfoP->status == VOK) {
786 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
787 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
788 if (a_xInfoP->type == 0)
789 fprintf(STDOUT, "RW ");
790 if (a_xInfoP->type == 1)
791 fprintf(STDOUT, "RO ");
792 if (a_xInfoP->type == 2)
793 fprintf(STDOUT, "BK ");
794 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
795 if (a_xInfoP->inUse == 1) {
796 fprintf(STDOUT, "On-line");
799 fprintf(STDOUT, "Off-line");
802 fprintf(STDOUT, "\n");
804 else if (a_xInfoP->status == VBUSY) {
806 qPut(&busyHead, a_xInfoP->volid);
808 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
809 (unsigned long)a_xInfoP->volid);
813 qPut(¬okHead, a_xInfoP->volid);
815 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
816 (unsigned long)a_xInfoP->volid);
817 } /*Screwed volume */
818 } /*Default listing */
819 } /*XDisplayFormat */
821 #ifdef FULL_LISTVOL_SWITCH
822 /*------------------------------------------------------------------------
823 * PRIVATE XDisplayFormat2
826 * Display the formated contents of one extended volume info structure.
829 * a_xInfoP : Ptr to extended volume info struct to print.
830 * a_servID : Server ID to print.
831 * a_partID : Partition ID to print.
832 * a_totalOKP : Ptr to total-OK counter.
833 * a_totalNotOKP : Ptr to total-screwed counter.
834 * a_totalBusyP : Ptr to total-busy counter.
835 * a_fast : Fast listing?
836 * a_int32 : Int32 listing?
837 * a_showProblems : Show volume problems?
843 * Nothing interesting.
847 *------------------------------------------------------------------------*/
850 XDisplayFormat2(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
851 a_totalBusyP, a_fast, a_int32, a_showProblems)
852 volintXInfo *a_xInfoP;
862 { /*XDisplayFormat */
867 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
868 } else if (a_int32) {
870 * Fully-detailed listing.
872 if (a_xInfoP->status == VOK) {
874 * Volume's status is OK - all the fields are valid.
877 static long server_cache = -1, partition_cache = -1;
878 static char hostname[256], address[32], pname[16];
879 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
880 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
882 if (a_servID != server_cache) {
886 strcpy(hostname, hostutil_GetNameByINet(a_servID));
887 strcpy(address, inet_ntoa(s));
888 server_cache = a_servID;
890 if (a_partID != partition_cache) {
891 MapPartIdIntoName(a_partID, pname);
892 partition_cache = a_partID;
895 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
896 fprintf(STDOUT, "id\t\t%lu\n", a_xInfoP->volid);
897 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
898 fprintf(STDOUT, "part\t\t%s\n", pname);
899 switch (a_xInfoP->status) {
901 fprintf(STDOUT, "status\t\tOK\n");
904 fprintf(STDOUT, "status\t\tBUSY\n");
907 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
910 fprintf(STDOUT, "backupID\t%lu\n", a_xInfoP->backupID);
911 fprintf(STDOUT, "parentID\t%lu\n", a_xInfoP->parentID);
912 fprintf(STDOUT, "cloneID\t\t%lu\n", a_xInfoP->cloneID);
913 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
914 switch (a_xInfoP->type) {
916 fprintf(STDOUT, "type\t\tRW\n");
919 fprintf(STDOUT, "type\t\tRO\n");
922 fprintf(STDOUT, "type\t\tBK\n");
925 fprintf(STDOUT, "type\t\t?\n");
928 fprintf(STDOUT, "creationDate\t%-9lu\t%s", a_xInfoP->creationDate,
929 vos_ctime(&a_xInfoP->creationDate));
930 fprintf(STDOUT, "accessDate\t%-9lu\t%s", a_xInfoP->accessDate,
931 vos_ctime(&a_xInfoP->accessDate));
932 fprintf(STDOUT, "updateDate\t%-9lu\t%s", a_xInfoP->updateDate,
933 vos_ctime(&a_xInfoP->updateDate));
934 fprintf(STDOUT, "backupDate\t%-9lu\t%s", a_xInfoP->backupDate,
935 vos_ctime(&a_xInfoP->backupDate));
936 fprintf(STDOUT, "copyDate\t%-9lu\t%s", a_xInfoP->copyDate,
937 vos_ctime(&a_xInfoP->copyDate));
939 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
940 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
942 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
943 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
947 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
948 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
949 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
950 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
952 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
953 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
954 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
955 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
959 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
960 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
961 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
962 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
965 } /*Volume status OK */
966 else if (a_xInfoP->status == VBUSY) {
968 qPut(&busyHead, a_xInfoP->volid);
970 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
971 (unsigned long)a_xInfoP->volid);
975 qPut(¬okHead, a_xInfoP->volid);
977 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
978 (unsigned long)a_xInfoP->volid);
979 } /*Screwed volume */
985 if (a_xInfoP->status == VOK) {
986 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
987 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
988 if (a_xInfoP->type == 0)
989 fprintf(STDOUT, "type\tRW\n");
990 if (a_xInfoP->type == 1)
991 fprintf(STDOUT, "type\tRO\n");
992 if (a_xInfoP->type == 2)
993 fprintf(STDOUT, "type\tBK\n");
994 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
996 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
997 if (a_xInfoP->inUse == 1)
1003 else if (a_xInfoP->status == VBUSY) {
1005 qPut(&busyHead, a_xInfoP->volid);
1007 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1008 (unsigned long)a_xInfoP->volid);
1012 qPut(¬okHead, a_xInfoP->volid);
1014 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1015 (unsigned long)a_xInfoP->volid);
1016 } /*Screwed volume */
1017 } /*Default listing */
1018 } /*XDisplayFormat */
1019 #endif /*FULL_LISTVOL_SWITCH*/
1021 #ifdef FULL_LISTVOL_SWITCH
1023 DisplayFormat2(server, partition, pntr)
1024 long server, partition;
1027 static long server_cache = -1, partition_cache = -1;
1028 static char hostname[256], address[32], pname[16];
1030 if (server != server_cache) {
1034 strcpy(hostname, hostutil_GetNameByINet(server));
1035 strcpy(address, inet_ntoa(s));
1036 server_cache = server;
1038 if (partition != partition_cache) {
1039 MapPartIdIntoName(partition, pname);
1040 partition_cache = partition;
1042 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1043 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
1044 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1045 fprintf(STDOUT, "part\t\t%s\n", pname);
1046 switch (pntr->status) {
1048 fprintf(STDOUT, "status\t\tOK\n");
1051 fprintf(STDOUT, "status\t\tBUSY\n");
1054 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1057 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
1058 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
1059 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
1060 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1061 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1062 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1063 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1064 switch (pntr->type) {
1066 fprintf(STDOUT, "type\t\tRW\n");
1069 fprintf(STDOUT, "type\t\tRO\n");
1072 fprintf(STDOUT, "type\t\tBK\n");
1075 fprintf(STDOUT, "type\t\t?\n");
1078 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
1079 vos_ctime(&pntr->creationDate));
1080 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
1081 vos_ctime(&pntr->accessDate));
1082 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
1083 vos_ctime(&pntr->updateDate));
1084 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
1085 vos_ctime(&pntr->backupDate));
1086 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
1087 vos_ctime(&pntr->copyDate));
1088 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
1089 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1090 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1091 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
1092 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1093 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1094 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
1095 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
1096 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
1101 DisplayVolumes2(server, partition, pntr, count)
1103 long server, partition, count;
1107 for (i = 0; i < count; i++) {
1108 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1109 DisplayFormat2(server, partition, pntr);
1110 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1115 #endif /* FULL_LISTVOL_SWITCH */
1118 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
1119 afs_int32 server, part;
1121 afs_int32 count, longlist, fast;
1124 int totalOK, totalNotOK, totalBusy, i;
1132 for (i = 0; i < count; i++) {
1133 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1138 while (busyHead.count) {
1139 qGet(&busyHead, &volid);
1140 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1141 (unsigned long)volid);
1145 while (notokHead.count) {
1146 qGet(¬okHead, &volid);
1147 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1148 (unsigned long)volid);
1152 fprintf(STDOUT, "\n");
1155 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1156 totalOK, totalNotOK, totalBusy);
1160 /*------------------------------------------------------------------------
1161 * PRIVATE XDisplayVolumes
1164 * Display extended volume information.
1167 * a_servID : Pointer to the Rx call we're performing.
1168 * a_partID : Partition for which we want the extended list.
1169 * a_xInfoP : Ptr to extended volume info.
1170 * a_count : Number of volume records contained above.
1171 * a_int32 : Int32 listing generated?
1172 * a_fast : Fast listing generated?
1173 * a_quiet : Quiet listing generated?
1179 * Nothing interesting.
1183 *------------------------------------------------------------------------*/
1186 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1190 volintXInfo *a_xInfoP;
1196 { /*XDisplayVolumes */
1198 int totalOK; /*Total OK volumes */
1199 int totalNotOK; /*Total screwed volumes */
1200 int totalBusy; /*Total busy volumes */
1201 int i; /*Loop variable */
1202 afs_int32 volid; /*Current volume ID */
1205 * Initialize counters and (global!!) queues.
1214 * Display each volume in the list.
1216 for (i = 0; i < a_count; i++) {
1217 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1218 &totalBusy, a_fast, a_int32, 0);
1223 * If any volumes were found to be busy or screwed, display them.
1226 while (busyHead.count) {
1227 qGet(&busyHead, &volid);
1228 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1229 (unsigned long)volid);
1233 while (notokHead.count) {
1234 qGet(¬okHead, &volid);
1235 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1236 (unsigned long)volid);
1241 fprintf(STDOUT, "\n");
1244 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1245 totalOK, totalNotOK, totalBusy);
1249 } /*XDisplayVolumes */
1250 #ifdef FULL_LISTVOL_SWITCH
1251 /*------------------------------------------------------------------------
1252 * PRIVATE XDisplayVolumes2
1255 * Display extended formated volume information.
1258 * a_servID : Pointer to the Rx call we're performing.
1259 * a_partID : Partition for which we want the extended list.
1260 * a_xInfoP : Ptr to extended volume info.
1261 * a_count : Number of volume records contained above.
1262 * a_int32 : Int32 listing generated?
1263 * a_fast : Fast listing generated?
1264 * a_quiet : Quiet listing generated?
1270 * Nothing interesting.
1274 *------------------------------------------------------------------------*/
1277 XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1281 volintXInfo *a_xInfoP;
1287 { /*XDisplayVolumes */
1289 int totalOK; /*Total OK volumes */
1290 int totalNotOK; /*Total screwed volumes */
1291 int totalBusy; /*Total busy volumes */
1292 int i; /*Loop variable */
1293 afs_int32 volid; /*Current volume ID */
1296 * Initialize counters and (global!!) queues.
1305 * Display each volume in the list.
1307 for (i = 0; i < a_count; i++) {
1308 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1309 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1310 &totalBusy, a_fast, a_int32, 0);
1311 fprintf(STDOUT, "END_OF_ENTRY\n");
1316 * If any volumes were found to be busy or screwed, display them.
1319 while (busyHead.count) {
1320 qGet(&busyHead, &volid);
1321 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1322 (unsigned long)volid);
1326 while (notokHead.count) {
1327 qGet(¬okHead, &volid);
1328 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1329 (unsigned long)volid);
1334 fprintf(STDOUT, "\n");
1337 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1338 totalOK, totalNotOK, totalBusy);
1342 } /*XDisplayVolumes2 */
1343 #endif /* FULL_LISTVOL_SWITCH */
1346 /* set <server> and <part> to the correct values depending on
1347 * <voltype> and <entry> */
1349 GetServerAndPart(entry, voltype, server, part, previdx)
1350 struct nvldbentry *entry;
1351 afs_int32 *server, *part;
1355 int i, istart, vtype;
1360 /* Doesn't check for non-existance of backup volume */
1361 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1363 istart = 0; /* seach the entire entry */
1366 /* Seach from beginning of entry or pick up where we left off */
1367 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1370 for (i = istart; i < entry->nServers; i++) {
1371 if (entry->serverFlags[i] & vtype) {
1372 *server = entry->serverNumber[i];
1373 *part = entry->serverPartition[i];
1379 /* Didn't find any, return -1 */
1385 PostVolumeStats(entry)
1386 struct nvldbentry *entry;
1388 SubEnumerateEntry(entry);
1389 /* Check for VLOP_ALLOPERS */
1390 if (entry->flags & VLOP_ALLOPERS)
1391 fprintf(STDOUT, " Volume is currently LOCKED \n");
1395 /*------------------------------------------------------------------------
1396 * PRIVATE XVolumeStats
1399 * Display extended volume information.
1402 * a_xInfoP : Ptr to extended volume info.
1403 * a_entryP : Ptr to the volume's VLDB entry.
1404 * a_srvID : Server ID.
1405 * a_partID : Partition ID.
1406 * a_volType : Type of volume to print.
1412 * Nothing interesting.
1416 *------------------------------------------------------------------------*/
1419 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1420 volintXInfo *a_xInfoP;
1421 struct nvldbentry *a_entryP;
1428 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1430 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1431 a_srvID, /*Server ID to print */
1432 a_partID, /*Partition ID to print */
1433 &totalOK, /*Ptr to total-OK counter */
1434 &totalNotOK, /*Ptr to total-screwed counter */
1435 &totalBusy, /*Ptr to total-busy counter */
1436 0, /*Don't do a fast listing */
1437 1, /*Do a long listing */
1438 1); /*Show volume problems */
1444 VolumeStats(pntr, entry, server, part, voltype)
1446 struct nvldbentry *entry;
1448 afs_int32 server, part;
1450 int totalOK, totalNotOK, totalBusy;
1452 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1457 /* command to forcibly remove a volume */
1459 NukeVolume(register struct cmd_syndesc *as)
1461 register afs_int32 code;
1462 afs_int32 volID, err;
1467 server = GetServer(tp = as->parms[0].items->data);
1469 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1473 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1475 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1479 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1482 PrintError("", err);
1485 "vos: could not parse '%s' as a numeric volume ID", tp);
1490 "vos: forcibly removing all traces of volume %d, please wait...",
1493 code = UV_NukeVolume(server, partID, volID);
1495 fprintf(STDOUT, "done.\n");
1497 fprintf(STDOUT, "failed with code %d.\n", code);
1502 /*------------------------------------------------------------------------
1503 * PRIVATE ExamineVolume
1506 * Routine used to examine a single volume, contacting the VLDB as
1507 * well as the Volume Server.
1510 * as : Ptr to parsed command line arguments.
1513 * 0 for a successful operation,
1514 * Otherwise, one of the ubik or VolServer error values.
1517 * Nothing interesting.
1521 *------------------------------------------------------------------------
1524 ExamineVolume(register struct cmd_syndesc *as, void *arock)
1526 struct nvldbentry entry;
1527 afs_int32 vcode = 0;
1528 volintInfo *pntr = (volintInfo *) 0;
1529 volintXInfo *xInfoP = (volintXInfo *) 0;
1531 afs_int32 code, err, error = 0;
1532 int voltype, foundserv = 0, foundentry = 0;
1533 afs_int32 aserver, apart;
1535 int wantExtendedInfo; /*Do we want extended vol info? */
1537 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1539 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1542 PrintError("", err);
1544 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1545 as->parms[0].items->data);
1550 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1551 (unsigned long)volid);
1554 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1557 "Could not fetch the entry for volume number %lu from VLDB \n",
1558 (unsigned long)volid);
1562 fprintf(STDOUT, "done\n");
1563 MapHostToNetwork(&entry);
1565 if (entry.volumeId[RWVOL] == volid)
1567 else if (entry.volumeId[BACKVOL] == volid)
1569 else /* (entry.volumeId[ROVOL] == volid) */
1572 do { /* do {...} while (voltype == ROVOL) */
1573 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1574 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1575 * If its a RO vol, get the next RO entry.
1577 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1578 &aserver, &apart, &previdx);
1579 if (previdx == -1) { /* searched all entries */
1581 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1582 as->parms[0].items->data);
1589 /* Get information about the volume from the server */
1591 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1592 hostutil_GetNameByINet(aserver));
1595 if (wantExtendedInfo)
1596 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1598 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1600 fprintf(STDOUT, "done\n");
1604 if (code == ENODEV) {
1605 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1606 /* The VLDB says there is no backup volume and its not on disk */
1607 fprintf(STDERR, "Volume %s does not exist\n",
1608 as->parms[0].items->data);
1612 "Volume does not exist on server %s as indicated by the VLDB\n",
1613 hostutil_GetNameByINet(aserver));
1616 PrintDiagnostics("examine", code);
1618 fprintf(STDOUT, "\n");
1621 if (wantExtendedInfo)
1622 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1624 #ifdef FULL_LISTVOL_SWITCH
1625 if (as->parms[2].items) {
1626 DisplayFormat2(aserver, apart, pntr);
1627 EnumerateEntry(&entry);
1629 #endif /* FULL_LISTVOL_SWITCH */
1630 VolumeStats(pntr, &entry, aserver, apart, voltype);
1632 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1633 /* The VLDB says there is no backup volume yet we found one on disk */
1634 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1635 as->parms[0].items->data);
1644 } while (voltype == ROVOL);
1647 fprintf(STDERR, "Dump only information from VLDB\n\n");
1648 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1650 PostVolumeStats(&entry);
1655 /*------------------------------------------------------------------------
1659 * Routine used to change the status of a single volume.
1662 * as : Ptr to parsed command line arguments.
1665 * 0 for a successful operation,
1666 * Otherwise, one of the ubik or VolServer error values.
1669 * Nothing interesting.
1673 *------------------------------------------------------------------------
1676 SetFields(register struct cmd_syndesc *as, void *arock)
1678 struct nvldbentry entry;
1679 afs_int32 vcode = 0;
1682 afs_int32 code, err;
1683 afs_int32 aserver, apart;
1686 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1689 PrintError("", err);
1691 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1692 as->parms[0].items->data);
1696 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1699 "Could not fetch the entry for volume number %lu from VLDB \n",
1700 (unsigned long)volid);
1703 MapHostToNetwork(&entry);
1705 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1706 if (previdx == -1) {
1707 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1708 as->parms[0].items->data);
1712 init_volintInfo(&info);
1716 if (as->parms[1].items) {
1718 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1720 fprintf(STDERR, "invalid quota value\n");
1724 if (as->parms[2].items) {
1728 if (as->parms[3].items) {
1729 /* -clearVolUpCounter */
1732 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1735 "Could not update volume info fields for volume number %lu\n",
1736 (unsigned long)volid);
1740 /*------------------------------------------------------------------------
1744 * Brings a volume online.
1747 * as : Ptr to parsed command line arguments.
1750 * 0 for a successful operation,
1753 * Nothing interesting.
1757 *------------------------------------------------------------------------
1760 volOnline(register struct cmd_syndesc *as, void *arock)
1762 afs_int32 server, partition, volid;
1763 afs_int32 code, err = 0;
1765 server = GetServer(as->parms[0].items->data);
1767 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1768 as->parms[0].items->data);
1772 partition = volutil_GetPartitionID(as->parms[1].items->data);
1773 if (partition < 0) {
1774 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1775 as->parms[1].items->data);
1779 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1782 PrintError("", err);
1784 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1785 as->parms[0].items->data);
1789 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1792 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1799 /*------------------------------------------------------------------------
1800 * PRIVATE volOffline
1803 * Brings a volume offline.
1806 * as : Ptr to parsed command line arguments.
1809 * 0 for a successful operation,
1812 * Nothing interesting.
1816 *------------------------------------------------------------------------
1819 volOffline(register struct cmd_syndesc *as, void *arock)
1821 afs_int32 server, partition, volid;
1822 afs_int32 code, err = 0;
1823 afs_int32 transflag, sleeptime, transdone;
1825 server = GetServer(as->parms[0].items->data);
1827 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1828 as->parms[0].items->data);
1832 partition = volutil_GetPartitionID(as->parms[1].items->data);
1833 if (partition < 0) {
1834 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1835 as->parms[1].items->data);
1839 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1842 PrintError("", err);
1844 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1845 as->parms[0].items->data);
1849 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1850 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1851 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1852 if (as->parms[4].items && !as->parms[3].items) {
1853 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1858 UV_SetVolume(server, partition, volid, transflag, transdone,
1861 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1869 CreateVolume(register struct cmd_syndesc *as, void *arock)
1873 afs_int32 volid, code;
1874 struct nvldbentry entry;
1879 tserver = GetServer(as->parms[0].items->data);
1881 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1882 as->parms[0].items->data);
1885 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1887 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1888 as->parms[1].items->data);
1891 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1893 PrintError("", code);
1896 "vos : partition %s does not exist on the server\n",
1897 as->parms[1].items->data);
1900 if (!ISNAMEVALID(as->parms[2].items->data)) {
1902 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1903 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1906 if (!VolNameOK(as->parms[2].items->data)) {
1908 "Illegal volume name %s, should not end in .readonly or .backup\n",
1909 as->parms[2].items->data);
1912 if (IsNumeric(as->parms[2].items->data)) {
1913 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1914 as->parms[2].items->data);
1917 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1919 fprintf(STDERR, "Volume %s already exists\n",
1920 as->parms[2].items->data);
1921 PrintDiagnostics("create", code);
1925 if (as->parms[3].items) {
1926 if (!IsNumeric(as->parms[3].items->data)) {
1927 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1928 as->parms[3].items->data);
1932 code = util_GetInt32(as->parms[3].items->data, "a);
1934 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1940 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1943 PrintDiagnostics("create", code);
1946 MapPartIdIntoName(pnum, part);
1947 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1948 (unsigned long)volid, part, as->parms[0].items->data);
1955 struct nvldbentry *entry;
1958 afs_int32 error, code, curserver, curpart, volid;
1960 MapHostToNetwork(entry);
1962 for (i = 0; i < entry->nServers; i++) {
1963 curserver = entry->serverNumber[i];
1964 curpart = entry->serverPartition[i];
1965 if (entry->serverFlags[i] & ITSROVOL) {
1966 volid = entry->volumeId[ROVOL];
1968 volid = entry->volumeId[RWVOL];
1970 code = UV_DeleteVolume(curserver, curpart, volid);
1978 DeleteVolume(struct cmd_syndesc *as, void *arock)
1980 afs_int32 err, code = 0;
1981 afs_int32 server = 0, partition = -1, volid;
1985 if (as->parms[0].items) {
1986 server = GetServer(as->parms[0].items->data);
1988 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1989 as->parms[0].items->data);
1994 if (as->parms[1].items) {
1995 partition = volutil_GetPartitionID(as->parms[1].items->data);
1996 if (partition < 0) {
1997 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1998 as->parms[1].items->data);
2002 /* Check for validity of the partition */
2003 if (!IsPartValid(partition, server, &code)) {
2005 PrintError("", code);
2008 "vos : partition %s does not exist on the server\n",
2009 as->parms[1].items->data);
2015 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2017 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2018 as->parms[2].items->data);
2020 PrintError("", err);
2024 /* If the server or partition option are not complete, try to fill
2025 * them in from the VLDB entry.
2027 if ((partition == -1) || !server) {
2028 struct nvldbentry entry;
2030 code = VLDB_GetEntryByID(volid, -1, &entry);
2033 "Could not fetch the entry for volume %lu from VLDB\n",
2034 (unsigned long)volid);
2035 PrintError("", code);
2039 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2040 || ((volid == entry.volumeId[BACKVOL])
2041 && (entry.flags & BACK_EXISTS))) {
2042 idx = Lp_GetRwIndex(&entry);
2043 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2044 || ((partition != -1)
2045 && (partition != entry.serverPartition[idx]))) {
2046 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2047 as->parms[2].items->data);
2050 } else if ((volid == entry.volumeId[ROVOL])
2051 && (entry.flags & RO_EXISTS)) {
2052 for (idx = -1, j = 0; j < entry.nServers; j++) {
2053 if (entry.serverFlags[j] != ITSROVOL)
2056 if (((server == 0) || (server == entry.serverNumber[j]))
2057 && ((partition == -1)
2058 || (partition == entry.serverPartition[j]))) {
2061 "VLDB: Volume '%s' matches more than one RO\n",
2062 as->parms[2].items->data);
2069 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2070 as->parms[2].items->data);
2074 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2075 as->parms[2].items->data);
2079 server = htonl(entry.serverNumber[idx]);
2080 partition = entry.serverPartition[idx];
2084 code = UV_DeleteVolume(server, partition, volid);
2086 PrintDiagnostics("remove", code);
2090 MapPartIdIntoName(partition, pname);
2091 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2092 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2096 #define TESTM 0 /* set for move space tests, clear for production */
2098 MoveVolume(register struct cmd_syndesc *as, void *arock)
2101 afs_int32 volid, fromserver, toserver, frompart, topart;
2102 afs_int32 flags, code, err;
2103 char fromPartName[10], toPartName[10];
2105 struct diskPartition64 partition; /* for space check */
2108 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2111 PrintError("", err);
2113 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2114 as->parms[0].items->data);
2117 fromserver = GetServer(as->parms[1].items->data);
2118 if (fromserver == 0) {
2119 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2120 as->parms[1].items->data);
2123 toserver = GetServer(as->parms[3].items->data);
2124 if (toserver == 0) {
2125 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2126 as->parms[3].items->data);
2129 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2131 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2132 as->parms[2].items->data);
2135 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2137 PrintError("", code);
2140 "vos : partition %s does not exist on the server\n",
2141 as->parms[2].items->data);
2144 topart = volutil_GetPartitionID(as->parms[4].items->data);
2146 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2147 as->parms[4].items->data);
2150 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2152 PrintError("", code);
2155 "vos : partition %s does not exist on the server\n",
2156 as->parms[4].items->data);
2161 if (as->parms[5].items) flags |= RV_NOCLONE;
2164 * check source partition for space to clone volume
2167 MapPartIdIntoName(topart, toPartName);
2168 MapPartIdIntoName(frompart, fromPartName);
2171 * check target partition for space to move volume
2174 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2176 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2180 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2183 p = (volintInfo *) 0;
2184 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2186 fprintf(STDERR, "vos:cannot access volume %lu\n",
2187 (unsigned long)volid);
2191 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2193 if (partition.free <= p->size) {
2195 "vos: no space on target partition %s to move volume %lu\n",
2196 toPartName, (unsigned long)volid);
2203 fprintf(STDOUT, "size test - don't do move\n");
2207 /* successful move still not guaranteed but shoot for it */
2210 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2212 PrintDiagnostics("move", code);
2215 MapPartIdIntoName(topart, toPartName);
2216 MapPartIdIntoName(frompart, fromPartName);
2217 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2218 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2219 as->parms[3].items->data, toPartName);
2225 CopyVolume(register struct cmd_syndesc *as, void *arock)
2227 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
2228 char fromPartName[10], toPartName[10], *tovolume;
2229 struct nvldbentry entry;
2230 struct diskPartition64 partition; /* for space check */
2233 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2236 PrintError("", err);
2238 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2239 as->parms[0].items->data);
2242 fromserver = GetServer(as->parms[1].items->data);
2243 if (fromserver == 0) {
2244 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2245 as->parms[1].items->data);
2249 toserver = GetServer(as->parms[4].items->data);
2250 if (toserver == 0) {
2251 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2252 as->parms[4].items->data);
2256 tovolume = as->parms[3].items->data;
2257 if (!ISNAMEVALID(tovolume)) {
2259 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2260 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2263 if (!VolNameOK(tovolume)) {
2265 "Illegal volume name %s, should not end in .readonly or .backup\n",
2269 if (IsNumeric(tovolume)) {
2270 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2274 code = VLDB_GetEntryByName(tovolume, &entry);
2276 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2277 PrintDiagnostics("copy", code);
2281 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2283 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2284 as->parms[2].items->data);
2287 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2289 PrintError("", code);
2292 "vos : partition %s does not exist on the server\n",
2293 as->parms[2].items->data);
2297 topart = volutil_GetPartitionID(as->parms[5].items->data);
2299 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2300 as->parms[5].items->data);
2303 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2305 PrintError("", code);
2308 "vos : partition %s does not exist on the server\n",
2309 as->parms[5].items->data);
2314 if (as->parms[6].items) flags |= RV_OFFLINE;
2315 if (as->parms[7].items) flags |= RV_RDONLY;
2316 if (as->parms[8].items) flags |= RV_NOCLONE;
2318 MapPartIdIntoName(topart, toPartName);
2319 MapPartIdIntoName(frompart, fromPartName);
2322 * check target partition for space to move volume
2325 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2327 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2331 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2334 p = (volintInfo *) 0;
2335 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2337 fprintf(STDERR, "vos:cannot access volume %lu\n",
2338 (unsigned long)volid);
2342 if (partition.free <= p->size) {
2344 "vos: no space on target partition %s to copy volume %lu\n",
2345 toPartName, (unsigned long)volid);
2351 /* successful copy still not guaranteed but shoot for it */
2354 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2357 PrintDiagnostics("copy", code);
2360 MapPartIdIntoName(topart, toPartName);
2361 MapPartIdIntoName(frompart, fromPartName);
2362 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2363 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2364 tovolume, as->parms[4].items->data, toPartName);
2371 ShadowVolume(register struct cmd_syndesc *as, void *arock)
2373 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2374 afs_int32 code, err, flags;
2375 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2376 struct nvldbentry entry;
2377 struct diskPartition64 partition; /* for space check */
2380 p = (volintInfo *) 0;
2381 q = (volintInfo *) 0;
2383 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2386 PrintError("", err);
2388 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2389 as->parms[0].items->data);
2392 fromserver = GetServer(as->parms[1].items->data);
2393 if (fromserver == 0) {
2394 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2395 as->parms[1].items->data);
2399 toserver = GetServer(as->parms[3].items->data);
2400 if (toserver == 0) {
2401 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2402 as->parms[3].items->data);
2406 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2408 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2409 as->parms[2].items->data);
2412 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2414 PrintError("", code);
2417 "vos : partition %s does not exist on the server\n",
2418 as->parms[2].items->data);
2422 topart = volutil_GetPartitionID(as->parms[4].items->data);
2424 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2425 as->parms[4].items->data);
2428 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2430 PrintError("", code);
2433 "vos : partition %s does not exist on the server\n",
2434 as->parms[4].items->data);
2438 if (as->parms[5].items) {
2439 tovolume = as->parms[5].items->data;
2440 if (!ISNAMEVALID(tovolume)) {
2442 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2443 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2446 if (!VolNameOK(tovolume)) {
2448 "Illegal volume name %s, should not end in .readonly or .backup\n",
2452 if (IsNumeric(tovolume)) {
2454 "Illegal volume name %s, should not be a number\n",
2459 /* use actual name of source volume */
2460 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2462 fprintf(STDERR, "vos:cannot access volume %lu\n",
2463 (unsigned long)volid);
2466 strcpy(toVolName, p->name);
2467 tovolume = toVolName;
2468 /* save p for size checks later */
2471 if (as->parms[6].items) {
2472 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2475 PrintError("", err);
2477 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2478 as->parms[6].items->data);
2484 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2487 PrintError("", err);
2489 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2498 if (as->parms[7].items) flags |= RV_OFFLINE;
2499 if (as->parms[8].items) flags |= RV_RDONLY;
2500 if (as->parms[9].items) flags |= RV_NOCLONE;
2501 if (as->parms[10].items) flags |= RV_CPINCR;
2503 MapPartIdIntoName(topart, toPartName);
2504 MapPartIdIntoName(frompart, fromPartName);
2507 * check target partition for space to move volume
2510 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2512 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2516 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2519 /* Don't do this again if we did it above */
2521 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2523 fprintf(STDERR, "vos:cannot access volume %lu\n",
2524 (unsigned long)volid);
2529 /* OK if this fails */
2530 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2532 /* Treat existing volume size as "free" */
2534 p->size = (q->size < p->size) ? p->size - q->size : 0;
2536 if (partition.free <= p->size) {
2538 "vos: no space on target partition %s to copy volume %lu\n",
2539 toPartName, (unsigned long)volid);
2547 /* successful copy still not guaranteed but shoot for it */
2550 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2551 topart, tovolid, flags);
2553 PrintDiagnostics("shadow", code);
2556 MapPartIdIntoName(topart, toPartName);
2557 MapPartIdIntoName(frompart, fromPartName);
2558 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2559 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2560 as->parms[3].items->data, toPartName);
2567 CloneVolume(register struct cmd_syndesc *as, void *arock)
2569 afs_int32 server, part, volid, cloneid, voltype;
2570 char partName[10], *volname;
2571 afs_int32 code, err, flags;
2572 struct nvldbentry entry;
2574 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2577 PrintError("", err);
2579 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2580 as->parms[0].items->data);
2584 if (as->parms[1].items || as->parms[2].items) {
2585 if (!as->parms[1].items || !as->parms[2].items) {
2587 "Must specify both -server and -partition options\n");
2590 server = GetServer(as->parms[1].items->data);
2592 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2593 as->parms[1].items->data);
2596 part = volutil_GetPartitionID(as->parms[2].items->data);
2598 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2599 as->parms[2].items->data);
2602 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2604 PrintError("", code);
2607 "vos : partition %s does not exist on the server\n",
2608 as->parms[2].items->data);
2612 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2618 if (as->parms[3].items) {
2619 volname = as->parms[3].items->data;
2620 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2622 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2623 volname, VOLSER_OLDMAXVOLNAME - 1);
2628 * In order that you be able to make clones of RO or BK, this
2629 * check must be omitted.
2631 if (!VolNameOK(volname)) {
2633 "Illegal volume name %s, should not end in .readonly or .backup\n",
2638 if (IsNumeric(volname)) {
2640 "Illegal volume name %s, should not be a number\n",
2647 if (as->parms[4].items) {
2648 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2651 PrintError("", err);
2653 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2654 as->parms[4].items->data);
2660 if (as->parms[5].items) flags |= RV_OFFLINE;
2661 if (as->parms[6].items) flags |= RV_RDONLY;
2665 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2668 PrintDiagnostics("clone", code);
2671 MapPartIdIntoName(part, partName);
2672 fprintf(STDOUT, "Created clone for volume %s\n",
2673 as->parms[0].items->data);
2680 BackupVolume(register struct cmd_syndesc *as, void *arock)
2682 afs_int32 avolid, aserver, apart, vtype, code, err;
2683 struct nvldbentry entry;
2685 afs_int32 buvolid, buserver, bupart, butype;
2686 struct nvldbentry buentry;
2688 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2691 PrintError("", err);
2693 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2694 as->parms[0].items->data);
2697 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2701 /* verify this is a readwrite volume */
2703 if (vtype != RWVOL) {
2704 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2708 /* is there a backup volume already? */
2710 if (entry.flags & BACK_EXISTS) {
2711 /* yep, where is it? */
2713 buvolid = entry.volumeId[BACKVOL];
2714 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2719 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2722 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2728 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2729 (unsigned long)buvolid, (unsigned long)buserver);
2734 /* nope, carry on */
2736 code = UV_BackupVolume(aserver, apart, avolid);
2739 PrintDiagnostics("backup", code);
2742 fprintf(STDOUT, "Created backup volume for %s \n",
2743 as->parms[0].items->data);
2748 ReleaseVolume(register struct cmd_syndesc *as, void *arock)
2751 struct nvldbentry entry;
2752 afs_int32 avolid, aserver, apart, vtype, code, err;
2755 if (as->parms[1].items)
2757 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2760 PrintError("", err);
2762 fprintf(STDERR, "vos: can't find volume '%s'\n",
2763 as->parms[0].items->data);
2766 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2770 if (vtype != RWVOL) {
2771 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2775 if (!ISNAMEVALID(entry.name)) {
2777 "Volume name %s is too long, rename before releasing\n",
2782 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2784 PrintDiagnostics("release", code);
2787 fprintf(STDOUT, "Released volume %s successfully\n",
2788 as->parms[0].items->data);
2793 DumpVolume(register struct cmd_syndesc *as, void *arock)
2795 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2796 char filename[MAXPATHLEN];
2797 struct nvldbentry entry;
2799 rx_SetRxDeadTime(60 * 10);
2800 for (i = 0; i < MAXSERVERS; i++) {
2801 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2804 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2805 if (rxConn->service)
2806 rxConn->service->connDeadTime = rx_connDeadTime;
2809 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2812 PrintError("", err);
2814 fprintf(STDERR, "vos: can't find volume '%s'\n",
2815 as->parms[0].items->data);
2819 if (as->parms[3].items || as->parms[4].items) {
2820 if (!as->parms[3].items || !as->parms[4].items) {
2822 "Must specify both -server and -partition options\n");
2825 aserver = GetServer(as->parms[3].items->data);
2827 fprintf(STDERR, "Invalid server name\n");
2830 apart = volutil_GetPartitionID(as->parms[4].items->data);
2832 fprintf(STDERR, "Invalid partition name\n");
2836 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2841 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2842 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2844 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2845 as->parms[1].items->data, code);
2849 if (as->parms[2].items) {
2850 strcpy(filename, as->parms[2].items->data);
2852 strcpy(filename, "");
2855 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2857 if (as->parms[5].items) {
2859 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2860 DumpFunction, filename, flags);
2863 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2866 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2867 flags &= ~VOLDUMPV2_OMITDIRS;
2871 PrintDiagnostics("dump", code);
2874 if (strcmp(filename, ""))
2875 fprintf(STDERR, "Dumped volume %s in file %s\n",
2876 as->parms[0].items->data, filename);
2878 fprintf(STDERR, "Dumped volume %s in stdout \n",
2879 as->parms[0].items->data);
2893 RestoreVolume(register struct cmd_syndesc *as, void *arock)
2895 afs_int32 avolid, aparentid, aserver, apart, code, vcode, err;
2896 afs_int32 aoverwrite = ASK;
2897 afs_int32 acreation = 0, alastupdate = 0;
2898 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2900 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2901 char volname[VOLSER_MAXVOLNAME + 1];
2902 struct nvldbentry entry;
2907 if (as->parms[4].items) {
2908 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2911 PrintError("", err);
2913 fprintf(STDERR, "vos: can't find volume '%s'\n",
2914 as->parms[4].items->data);
2920 if (as->parms[5].items) {
2921 if ((strcmp(as->parms[5].items->data, "a") == 0)
2922 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2924 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2925 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2927 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2928 || (strcmp(as->parms[5].items->data, "inc") == 0)
2929 || (strcmp(as->parms[5].items->data, "increment") == 0)
2930 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2933 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2934 as->parms[5].items->data);
2938 if (as->parms[6].items)
2940 if (as->parms[7].items) {
2945 if (as->parms[8].items) {
2946 if ((strcmp(as->parms[8].items->data, "d") == 0)
2947 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2948 acreation = TS_DUMP;
2949 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2950 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2951 acreation = TS_KEEP;
2952 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2953 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2956 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2957 as->parms[8].items->data);
2962 if (as->parms[9].items) {
2963 if ((strcmp(as->parms[9].items->data, "d") == 0)
2964 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2965 alastupdate = TS_DUMP;
2966 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2967 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2968 alastupdate = TS_KEEP;
2969 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2970 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2971 alastupdate = TS_NEW;
2973 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2974 as->parms[9].items->data);
2979 aserver = GetServer(as->parms[0].items->data);
2981 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2982 as->parms[0].items->data);
2985 apart = volutil_GetPartitionID(as->parms[1].items->data);
2987 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2988 as->parms[1].items->data);
2991 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2993 PrintError("", code);
2996 "vos : partition %s does not exist on the server\n",
2997 as->parms[1].items->data);
3000 strcpy(avolname, as->parms[2].items->data);
3001 if (!ISNAMEVALID(avolname)) {
3003 "vos: the name of the volume %s exceeds the size limit\n",
3007 if (!VolNameOK(avolname)) {
3009 "Illegal volume name %s, should not end in .readonly or .backup\n",
3013 if (as->parms[3].items) {
3014 strcpy(afilename, as->parms[3].items->data);
3015 if (!FileExists(afilename)) {
3016 fprintf(STDERR, "Can't access file %s\n", afilename);
3020 strcpy(afilename, "");
3023 /* Check if volume exists or not */
3025 vsu_ExtractName(volname, avolname);
3026 vcode = VLDB_GetEntryByName(volname, &entry);
3027 if (vcode) { /* no volume - do a full restore */
3028 restoreflags = RV_FULLRST;
3029 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3031 "Volume does not exist; Will perform a full restore\n");
3034 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3035 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3036 restoreflags = RV_FULLRST;
3037 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3039 "%s Volume does not exist; Will perform a full restore\n",
3040 readonly ? "RO" : "RW");
3043 avolid = entry.volumeId[voltype];
3044 } else if (entry.volumeId[voltype] != 0
3045 && entry.volumeId[voltype] != avolid) {
3046 avolid = entry.volumeId[voltype];
3048 aparentid = entry.volumeId[RWVOL];
3051 else { /* volume exists - do we do a full incremental or abort */
3052 int Oserver, Opart, Otype, vol_elsewhere = 0;
3053 struct nvldbentry Oentry;
3057 avolid = entry.volumeId[voltype];
3058 } else if (entry.volumeId[voltype] != 0
3059 && entry.volumeId[voltype] != avolid) {
3060 avolid = entry.volumeId[voltype];
3062 aparentid = entry.volumeId[RWVOL];
3064 /* A file name was specified - check if volume is on another partition */
3065 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3069 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3072 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3076 if (!vcode || (Opart != apart))
3079 if (aoverwrite == ASK) {
3080 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3082 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3086 /* Ask what to do */
3087 if (vol_elsewhere) {
3089 "The volume %s %u already exists on a different server/part\n",
3090 volname, entry.volumeId[voltype]);
3092 "Do you want to do a full restore or abort? [fa](a): ");
3095 "The volume %s %u already exists in the VLDB\n",
3096 volname, entry.volumeId[voltype]);
3098 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3101 while (!(dc == EOF || dc == '\n'))
3102 dc = getchar(); /* goto end of line */
3103 if ((c == 'f') || (c == 'F'))
3105 else if ((c == 'i') || (c == 'I'))
3111 if (aoverwrite == ABORT) {
3112 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3114 } else if (aoverwrite == FULL) {
3115 restoreflags = RV_FULLRST;
3117 "Volume exists; Will delete and perform full restore\n");
3118 } else if (aoverwrite == INC) {
3120 if (vol_elsewhere) {
3122 "%s volume %lu already exists on a different server/part; not allowed\n",
3123 readonly ? "RO" : "RW", (unsigned long)avolid);
3129 restoreflags |= RV_OFFLINE;
3131 restoreflags |= RV_RDONLY;
3133 switch (acreation) {
3135 restoreflags |= RV_CRDUMP;
3138 restoreflags |= RV_CRKEEP;
3141 restoreflags |= RV_CRNEW;
3144 if (aoverwrite == FULL)
3145 restoreflags |= RV_CRNEW;
3147 restoreflags |= RV_CRKEEP;
3150 switch (alastupdate) {
3152 restoreflags |= RV_LUDUMP;
3155 restoreflags |= RV_LUKEEP;
3158 restoreflags |= RV_LUNEW;
3161 restoreflags |= RV_LUDUMP;
3163 if (as->parms[10].items) {
3164 restoreflags |= RV_NODEL;
3169 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3170 avolname, restoreflags, WriteData, afilename);
3172 PrintDiagnostics("restore", code);
3175 MapPartIdIntoName(apart, apartName);
3178 * patch typo here - originally "parms[1]", should be "parms[0]"
3181 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3182 as->parms[0].items->data, apartName);
3187 LockReleaseCmd(register struct cmd_syndesc *as, void *arock)
3189 afs_int32 avolid, code, err;
3191 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3194 PrintError("", err);
3196 fprintf(STDERR, "vos: can't find volume '%s'\n",
3197 as->parms[0].items->data);
3201 code = UV_LockRelease(avolid);
3203 PrintDiagnostics("unlock", code);
3206 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3207 as->parms[0].items->data);
3212 AddSite(register struct cmd_syndesc *as, void *arock)
3214 afs_int32 avolid, aserver, apart, code, err, valid = 0;
3215 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3217 vsu_ExtractName(avolname, as->parms[2].items->data);;
3218 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3221 PrintError("", err);
3223 fprintf(STDERR, "vos: can't find volume '%s'\n",
3224 as->parms[2].items->data);
3227 aserver = GetServer(as->parms[0].items->data);
3229 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3230 as->parms[0].items->data);
3233 apart = volutil_GetPartitionID(as->parms[1].items->data);
3235 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3236 as->parms[1].items->data);
3239 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3241 PrintError("", code);
3244 "vos : partition %s does not exist on the server\n",
3245 as->parms[1].items->data);
3248 if (as->parms[3].items) {
3251 code = UV_AddSite(aserver, apart, avolid, valid);
3253 PrintDiagnostics("addsite", code);
3256 MapPartIdIntoName(apart, apartName);
3257 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3258 as->parms[0].items->data, apartName, as->parms[2].items->data);
3263 RemoveSite(register struct cmd_syndesc *as, void *arock)
3266 afs_int32 avolid, aserver, apart, code, err;
3267 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3269 vsu_ExtractName(avolname, as->parms[2].items->data);
3270 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3273 PrintError("", err);
3275 fprintf(STDERR, "vos: can't find volume '%s'\n",
3276 as->parms[2].items->data);
3279 aserver = GetServer(as->parms[0].items->data);
3281 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3282 as->parms[0].items->data);
3285 apart = volutil_GetPartitionID(as->parms[1].items->data);
3287 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3288 as->parms[1].items->data);
3292 *skip the partition validity check, since it is possible that the partition
3293 *has since been decomissioned.
3296 if (!IsPartValid(apart,aserver,&code)){
3297 if(code) PrintError("",code);
3298 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3302 code = UV_RemoveSite(aserver, apart, avolid);
3304 PrintDiagnostics("remsite", code);
3307 MapPartIdIntoName(apart, apartName);
3308 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3309 as->parms[0].items->data, apartName, as->parms[2].items->data);
3314 ChangeLocation(register struct cmd_syndesc *as, void *arock)
3316 afs_int32 avolid, aserver, apart, code, err;
3319 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3322 PrintError("", err);
3324 fprintf(STDERR, "vos: can't find volume '%s'\n",
3325 as->parms[2].items->data);
3328 aserver = GetServer(as->parms[0].items->data);
3330 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3331 as->parms[0].items->data);
3334 apart = volutil_GetPartitionID(as->parms[1].items->data);
3336 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3337 as->parms[1].items->data);
3340 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3342 PrintError("", code);
3345 "vos : partition %s does not exist on the server\n",
3346 as->parms[1].items->data);
3349 code = UV_ChangeLocation(aserver, apart, avolid);
3351 PrintDiagnostics("addsite", code);
3354 MapPartIdIntoName(apart, apartName);
3355 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3356 as->parms[0].items->data, apartName, as->parms[2].items->data);
3361 ListPartitions(register struct cmd_syndesc *as, void *arock)
3363 afs_int32 aserver, code;
3364 struct partList dummyPartList;
3369 aserver = GetServer(as->parms[0].items->data);
3371 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3372 as->parms[0].items->data);
3377 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3379 PrintDiagnostics("listpart", code);
3383 fprintf(STDOUT, "The partitions on the server are:\n");
3384 for (i = 0; i < cnt; i++) {
3385 if (dummyPartList.partFlags[i] & PARTVALID) {
3386 memset(pname, 0, sizeof(pname));
3387 MapPartIdIntoName(dummyPartList.partId[i], pname);
3388 fprintf(STDOUT, " %10s ", pname);
3390 if ((i % 5) == 0 && (i != 0))
3391 fprintf(STDOUT, "\n");
3394 fprintf(STDOUT, "\n");
3395 fprintf(STDOUT, "Total: %d\n", total);
3401 CompareVolName(p1, p2)
3404 volintInfo *arg1, *arg2;
3406 arg1 = (volintInfo *) p1;
3407 arg2 = (volintInfo *) p2;
3408 return (strcmp(arg1->name, arg2->name));
3412 /*------------------------------------------------------------------------
3413 * PRIVATE XCompareVolName
3416 * Comparison routine for volume names coming from an extended
3420 * a_obj1P : Char ptr to first extended vol info object
3421 * a_obj1P : Char ptr to second extended vol info object
3424 * The value of strcmp() on the volume names within the passed
3425 * objects (i,e., -1, 0, or 1).
3428 * Passed to qsort() as the designated comparison routine.
3432 *------------------------------------------------------------------------*/
3435 XCompareVolName(a_obj1P, a_obj2P)
3436 char *a_obj1P, *a_obj2P;
3438 { /*XCompareVolName */
3441 (((struct volintXInfo *)(a_obj1P))->name,
3442 ((struct volintXInfo *)(a_obj2P))->name));
3444 } /*XCompareVolName */
3447 CompareVolID(p1, p2)
3450 volintInfo *arg1, *arg2;
3452 arg1 = (volintInfo *) p1;
3453 arg2 = (volintInfo *) p2;
3454 if (arg1->volid == arg2->volid)
3456 if (arg1->volid > arg2->volid)
3463 /*------------------------------------------------------------------------
3464 * PRIVATE XCompareVolID
3467 * Comparison routine for volume IDs coming from an extended
3471 * a_obj1P : Char ptr to first extended vol info object
3472 * a_obj1P : Char ptr to second extended vol info object
3475 * The value of strcmp() on the volume names within the passed
3476 * objects (i,e., -1, 0, or 1).
3479 * Passed to qsort() as the designated comparison routine.
3483 *------------------------------------------------------------------------*/
3486 XCompareVolID(a_obj1P, a_obj2P)
3487 char *a_obj1P, *a_obj2P;
3489 { /*XCompareVolID */
3491 afs_int32 id1, id2; /*Volume IDs we're comparing */
3493 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3494 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3502 } /*XCompareVolID */
3504 /*------------------------------------------------------------------------
3505 * PRIVATE ListVolumes
3508 * Routine used to list volumes, contacting the Volume Server
3509 * directly, bypassing the VLDB.
3512 * as : Ptr to parsed command line arguments.
3515 * 0 Successful operation
3518 * Nothing interesting.
3522 *------------------------------------------------------------------------*/
3525 ListVolumes(register struct cmd_syndesc *as, void *arock)
3527 afs_int32 apart, int32list, fast;
3528 afs_int32 aserver, code;
3529 volintInfo *pntr, *oldpntr;
3533 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3534 int wantExtendedInfo; /*Do we want extended vol info? */
3537 struct partList dummyPartList;
3545 if (as->parms[3].items)
3547 if (as->parms[4].items)
3551 if (as->parms[2].items)
3557 if (as->parms[5].items) {
3559 * We can't coexist with the fast flag.
3563 "vos: Can't use the -fast and -extended flags together\n");
3568 * We need to turn on ``long'' listings to get the full effect.
3570 wantExtendedInfo = 1;
3573 wantExtendedInfo = 0;
3574 if (as->parms[1].items) {
3575 apart = volutil_GetPartitionID(as->parms[1].items->data);
3577 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3578 as->parms[1].items->data);
3581 dummyPartList.partId[0] = apart;
3582 dummyPartList.partFlags[0] = PARTVALID;
3585 aserver = GetServer(as->parms[0].items->data);
3587 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3588 as->parms[0].items->data);
3593 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3595 PrintError("", code);
3598 "vos : partition %s does not exist on the server\n",
3599 as->parms[1].items->data);
3603 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3605 PrintDiagnostics("listvol", code);
3609 for (i = 0; i < cnt; i++) {
3610 if (dummyPartList.partFlags[i] & PARTVALID) {
3611 if (wantExtendedInfo)
3613 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3617 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3620 PrintDiagnostics("listvol", code);
3625 if (wantExtendedInfo) {
3626 origxInfoP = xInfoP;
3627 base = (char *)xInfoP;
3630 base = (char *)pntr;
3634 if (wantExtendedInfo)
3635 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3637 qsort(base, count, sizeof(volintInfo), CompareVolName);
3639 if (wantExtendedInfo)
3640 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3642 qsort(base, count, sizeof(volintInfo), CompareVolID);
3644 MapPartIdIntoName(dummyPartList.partId[i], pname);
3647 "Total number of volumes on server %s partition %s: %lu \n",
3648 as->parms[0].items->data, pname,
3649 (unsigned long)count);
3650 if (wantExtendedInfo) {
3651 #ifdef FULL_LISTVOL_SWITCH
3652 if (as->parms[6].items)
3653 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3654 count, int32list, fast, quiet);
3656 #endif /* FULL_LISTVOL_SWITCH */
3657 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3658 count, int32list, fast, quiet);