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 */
1460 register struct cmd_syndesc *as;
1462 register afs_int32 code;
1463 afs_int32 volID, err;
1468 server = GetServer(tp = as->parms[0].items->data);
1470 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1474 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1476 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1480 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1483 PrintError("", err);
1486 "vos: could not parse '%s' as a numeric volume ID", tp);
1491 "vos: forcibly removing all traces of volume %d, please wait...",
1494 code = UV_NukeVolume(server, partID, volID);
1496 fprintf(STDOUT, "done.\n");
1498 fprintf(STDOUT, "failed with code %d.\n", code);
1503 /*------------------------------------------------------------------------
1504 * PRIVATE ExamineVolume
1507 * Routine used to examine a single volume, contacting the VLDB as
1508 * well as the Volume Server.
1511 * as : Ptr to parsed command line arguments.
1514 * 0 for a successful operation,
1515 * Otherwise, one of the ubik or VolServer error values.
1518 * Nothing interesting.
1522 *------------------------------------------------------------------------
1526 register struct cmd_syndesc *as;
1528 struct nvldbentry entry;
1529 afs_int32 vcode = 0;
1530 volintInfo *pntr = (volintInfo *) 0;
1531 volintXInfo *xInfoP = (volintXInfo *) 0;
1533 afs_int32 code, err, error = 0;
1534 int voltype, foundserv = 0, foundentry = 0;
1535 afs_int32 aserver, apart;
1537 int wantExtendedInfo; /*Do we want extended vol info? */
1539 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1541 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1544 PrintError("", err);
1546 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1547 as->parms[0].items->data);
1552 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1553 (unsigned long)volid);
1556 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1559 "Could not fetch the entry for volume number %lu from VLDB \n",
1560 (unsigned long)volid);
1564 fprintf(STDOUT, "done\n");
1565 MapHostToNetwork(&entry);
1567 if (entry.volumeId[RWVOL] == volid)
1569 else if (entry.volumeId[BACKVOL] == volid)
1571 else /* (entry.volumeId[ROVOL] == volid) */
1574 do { /* do {...} while (voltype == ROVOL) */
1575 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1576 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1577 * If its a RO vol, get the next RO entry.
1579 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1580 &aserver, &apart, &previdx);
1581 if (previdx == -1) { /* searched all entries */
1583 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1584 as->parms[0].items->data);
1591 /* Get information about the volume from the server */
1593 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1594 hostutil_GetNameByINet(aserver));
1597 if (wantExtendedInfo)
1598 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1600 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1602 fprintf(STDOUT, "done\n");
1606 if (code == ENODEV) {
1607 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1608 /* The VLDB says there is no backup volume and its not on disk */
1609 fprintf(STDERR, "Volume %s does not exist\n",
1610 as->parms[0].items->data);
1614 "Volume does not exist on server %s as indicated by the VLDB\n",
1615 hostutil_GetNameByINet(aserver));
1618 PrintDiagnostics("examine", code);
1620 fprintf(STDOUT, "\n");
1623 if (wantExtendedInfo)
1624 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1626 #ifdef FULL_LISTVOL_SWITCH
1627 if (as->parms[2].items) {
1628 DisplayFormat2(aserver, apart, pntr);
1629 EnumerateEntry(&entry);
1631 #endif /* FULL_LISTVOL_SWITCH */
1632 VolumeStats(pntr, &entry, aserver, apart, voltype);
1634 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1635 /* The VLDB says there is no backup volume yet we found one on disk */
1636 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1637 as->parms[0].items->data);
1646 } while (voltype == ROVOL);
1649 fprintf(STDERR, "Dump only information from VLDB\n\n");
1650 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1652 PostVolumeStats(&entry);
1657 /*------------------------------------------------------------------------
1661 * Routine used to change the status of a single volume.
1664 * as : Ptr to parsed command line arguments.
1667 * 0 for a successful operation,
1668 * Otherwise, one of the ubik or VolServer error values.
1671 * Nothing interesting.
1675 *------------------------------------------------------------------------
1679 register struct cmd_syndesc *as;
1681 struct nvldbentry entry;
1682 afs_int32 vcode = 0;
1685 afs_int32 code, err;
1686 afs_int32 aserver, apart;
1689 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1692 PrintError("", err);
1694 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1695 as->parms[0].items->data);
1699 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1702 "Could not fetch the entry for volume number %lu from VLDB \n",
1703 (unsigned long)volid);
1706 MapHostToNetwork(&entry);
1708 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1709 if (previdx == -1) {
1710 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1711 as->parms[0].items->data);
1715 init_volintInfo(&info);
1719 if (as->parms[1].items) {
1721 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1723 fprintf(STDERR, "invalid quota value\n");
1727 if (as->parms[2].items) {
1731 if (as->parms[3].items) {
1732 /* -clearVolUpCounter */
1735 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1738 "Could not update volume info fields for volume number %lu\n",
1739 (unsigned long)volid);
1743 /*------------------------------------------------------------------------
1747 * Brings a volume online.
1750 * as : Ptr to parsed command line arguments.
1753 * 0 for a successful operation,
1756 * Nothing interesting.
1760 *------------------------------------------------------------------------
1764 register struct cmd_syndesc *as;
1766 afs_int32 server, partition, volid;
1767 afs_int32 code, err = 0;
1769 server = GetServer(as->parms[0].items->data);
1771 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1772 as->parms[0].items->data);
1776 partition = volutil_GetPartitionID(as->parms[1].items->data);
1777 if (partition < 0) {
1778 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1779 as->parms[1].items->data);
1783 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1786 PrintError("", err);
1788 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1789 as->parms[0].items->data);
1793 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1796 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1803 /*------------------------------------------------------------------------
1804 * PRIVATE volOffline
1807 * Brings a volume offline.
1810 * as : Ptr to parsed command line arguments.
1813 * 0 for a successful operation,
1816 * Nothing interesting.
1820 *------------------------------------------------------------------------
1823 volOffline(register struct cmd_syndesc *as)
1825 afs_int32 server, partition, volid;
1826 afs_int32 code, err = 0;
1827 afs_int32 transflag, sleeptime, transdone;
1829 server = GetServer(as->parms[0].items->data);
1831 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1832 as->parms[0].items->data);
1836 partition = volutil_GetPartitionID(as->parms[1].items->data);
1837 if (partition < 0) {
1838 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1839 as->parms[1].items->data);
1843 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1846 PrintError("", err);
1848 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1849 as->parms[0].items->data);
1853 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1854 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1855 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1856 if (as->parms[4].items && !as->parms[3].items) {
1857 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1862 UV_SetVolume(server, partition, volid, transflag, transdone,
1865 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1873 CreateVolume(register struct cmd_syndesc *as)
1877 afs_int32 volid, code;
1878 struct nvldbentry entry;
1883 tserver = GetServer(as->parms[0].items->data);
1885 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1886 as->parms[0].items->data);
1889 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1891 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1892 as->parms[1].items->data);
1895 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1897 PrintError("", code);
1900 "vos : partition %s does not exist on the server\n",
1901 as->parms[1].items->data);
1904 if (!ISNAMEVALID(as->parms[2].items->data)) {
1906 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1907 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1910 if (!VolNameOK(as->parms[2].items->data)) {
1912 "Illegal volume name %s, should not end in .readonly or .backup\n",
1913 as->parms[2].items->data);
1916 if (IsNumeric(as->parms[2].items->data)) {
1917 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1918 as->parms[2].items->data);
1921 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1923 fprintf(STDERR, "Volume %s already exists\n",
1924 as->parms[2].items->data);
1925 PrintDiagnostics("create", code);
1929 if (as->parms[3].items) {
1930 if (!IsNumeric(as->parms[3].items->data)) {
1931 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1932 as->parms[3].items->data);
1936 code = util_GetInt32(as->parms[3].items->data, "a);
1938 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1944 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1947 PrintDiagnostics("create", code);
1950 MapPartIdIntoName(pnum, part);
1951 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1952 (unsigned long)volid, part, as->parms[0].items->data);
1959 struct nvldbentry *entry;
1962 afs_int32 error, code, curserver, curpart, volid;
1964 MapHostToNetwork(entry);
1966 for (i = 0; i < entry->nServers; i++) {
1967 curserver = entry->serverNumber[i];
1968 curpart = entry->serverPartition[i];
1969 if (entry->serverFlags[i] & ITSROVOL) {
1970 volid = entry->volumeId[ROVOL];
1972 volid = entry->volumeId[RWVOL];
1974 code = UV_DeleteVolume(curserver, curpart, volid);
1983 struct cmd_syndesc *as;
1985 afs_int32 err, code = 0;
1986 afs_int32 server = 0, partition = -1, volid;
1990 if (as->parms[0].items) {
1991 server = GetServer(as->parms[0].items->data);
1993 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1994 as->parms[0].items->data);
1999 if (as->parms[1].items) {
2000 partition = volutil_GetPartitionID(as->parms[1].items->data);
2001 if (partition < 0) {
2002 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2003 as->parms[1].items->data);
2007 /* Check for validity of the partition */
2008 if (!IsPartValid(partition, server, &code)) {
2010 PrintError("", code);
2013 "vos : partition %s does not exist on the server\n",
2014 as->parms[1].items->data);
2020 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2022 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2023 as->parms[2].items->data);
2025 PrintError("", err);
2029 /* If the server or partition option are not complete, try to fill
2030 * them in from the VLDB entry.
2032 if ((partition == -1) || !server) {
2033 struct nvldbentry entry;
2035 code = VLDB_GetEntryByID(volid, -1, &entry);
2038 "Could not fetch the entry for volume %lu from VLDB\n",
2039 (unsigned long)volid);
2040 PrintError("", code);
2044 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2045 || ((volid == entry.volumeId[BACKVOL])
2046 && (entry.flags & BACK_EXISTS))) {
2047 idx = Lp_GetRwIndex(&entry);
2048 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2049 || ((partition != -1)
2050 && (partition != entry.serverPartition[idx]))) {
2051 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2052 as->parms[2].items->data);
2055 } else if ((volid == entry.volumeId[ROVOL])
2056 && (entry.flags & RO_EXISTS)) {
2057 for (idx = -1, j = 0; j < entry.nServers; j++) {
2058 if (entry.serverFlags[j] != ITSROVOL)
2061 if (((server == 0) || (server == entry.serverNumber[j]))
2062 && ((partition == -1)
2063 || (partition == entry.serverPartition[j]))) {
2066 "VLDB: Volume '%s' matches more than one RO\n",
2067 as->parms[2].items->data);
2074 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2075 as->parms[2].items->data);
2079 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2080 as->parms[2].items->data);
2084 server = htonl(entry.serverNumber[idx]);
2085 partition = entry.serverPartition[idx];
2089 code = UV_DeleteVolume(server, partition, volid);
2091 PrintDiagnostics("remove", code);
2095 MapPartIdIntoName(partition, pname);
2096 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2097 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2101 #define TESTM 0 /* set for move space tests, clear for production */
2104 register struct cmd_syndesc *as;
2107 afs_int32 volid, fromserver, toserver, frompart, topart;
2108 afs_int32 flags, code, err;
2109 char fromPartName[10], toPartName[10];
2111 struct diskPartition partition; /* for space check */
2114 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2117 PrintError("", err);
2119 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2120 as->parms[0].items->data);
2123 fromserver = GetServer(as->parms[1].items->data);
2124 if (fromserver == 0) {
2125 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2126 as->parms[1].items->data);
2129 toserver = GetServer(as->parms[3].items->data);
2130 if (toserver == 0) {
2131 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2132 as->parms[3].items->data);
2135 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2137 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2138 as->parms[2].items->data);
2141 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2143 PrintError("", code);
2146 "vos : partition %s does not exist on the server\n",
2147 as->parms[2].items->data);
2150 topart = volutil_GetPartitionID(as->parms[4].items->data);
2152 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2153 as->parms[4].items->data);
2156 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2158 PrintError("", code);
2161 "vos : partition %s does not exist on the server\n",
2162 as->parms[4].items->data);
2167 if (as->parms[5].items) flags |= RV_NOCLONE;
2170 * check source partition for space to clone volume
2173 MapPartIdIntoName(topart, toPartName);
2174 MapPartIdIntoName(frompart, fromPartName);
2177 * check target partition for space to move volume
2180 code = UV_PartitionInfo(toserver, toPartName, &partition);
2182 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2186 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2189 p = (volintInfo *) 0;
2190 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2192 fprintf(STDERR, "vos:cannot access volume %lu\n",
2193 (unsigned long)volid);
2197 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2199 if (partition.free <= p->size) {
2201 "vos: no space on target partition %s to move volume %lu\n",
2202 toPartName, (unsigned long)volid);
2209 fprintf(STDOUT, "size test - don't do move\n");
2213 /* successful move still not guaranteed but shoot for it */
2216 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2218 PrintDiagnostics("move", code);
2221 MapPartIdIntoName(topart, toPartName);
2222 MapPartIdIntoName(frompart, fromPartName);
2223 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2224 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2225 as->parms[3].items->data, toPartName);
2232 register struct cmd_syndesc *as;
2234 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
2235 char fromPartName[10], toPartName[10], *tovolume;
2236 struct nvldbentry entry;
2237 struct diskPartition partition; /* for space check */
2240 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2243 PrintError("", err);
2245 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2246 as->parms[0].items->data);
2249 fromserver = GetServer(as->parms[1].items->data);
2250 if (fromserver == 0) {
2251 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2252 as->parms[1].items->data);
2256 toserver = GetServer(as->parms[4].items->data);
2257 if (toserver == 0) {
2258 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2259 as->parms[4].items->data);
2263 tovolume = as->parms[3].items->data;
2264 if (!ISNAMEVALID(tovolume)) {
2266 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2267 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2270 if (!VolNameOK(tovolume)) {
2272 "Illegal volume name %s, should not end in .readonly or .backup\n",
2276 if (IsNumeric(tovolume)) {
2277 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2281 code = VLDB_GetEntryByName(tovolume, &entry);
2283 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2284 PrintDiagnostics("copy", code);
2288 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2290 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2291 as->parms[2].items->data);
2294 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2296 PrintError("", code);
2299 "vos : partition %s does not exist on the server\n",
2300 as->parms[2].items->data);
2304 topart = volutil_GetPartitionID(as->parms[5].items->data);
2306 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2307 as->parms[5].items->data);
2310 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2312 PrintError("", code);
2315 "vos : partition %s does not exist on the server\n",
2316 as->parms[5].items->data);
2321 if (as->parms[6].items) flags |= RV_OFFLINE;
2322 if (as->parms[7].items) flags |= RV_RDONLY;
2323 if (as->parms[8].items) flags |= RV_NOCLONE;
2325 MapPartIdIntoName(topart, toPartName);
2326 MapPartIdIntoName(frompart, fromPartName);
2329 * check target partition for space to move volume
2332 code = UV_PartitionInfo(toserver, toPartName, &partition);
2334 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2338 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2341 p = (volintInfo *) 0;
2342 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2344 fprintf(STDERR, "vos:cannot access volume %lu\n",
2345 (unsigned long)volid);
2349 if (partition.free <= p->size) {
2351 "vos: no space on target partition %s to copy volume %lu\n",
2352 toPartName, (unsigned long)volid);
2358 /* successful copy still not guaranteed but shoot for it */
2361 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2364 PrintDiagnostics("copy", code);
2367 MapPartIdIntoName(topart, toPartName);
2368 MapPartIdIntoName(frompart, fromPartName);
2369 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2370 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2371 tovolume, as->parms[4].items->data, toPartName);
2379 register struct cmd_syndesc *as;
2381 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2382 afs_int32 code, err, flags;
2383 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2384 struct nvldbentry entry;
2385 struct diskPartition partition; /* for space check */
2388 p = (volintInfo *) 0;
2389 q = (volintInfo *) 0;
2391 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2394 PrintError("", err);
2396 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2397 as->parms[0].items->data);
2400 fromserver = GetServer(as->parms[1].items->data);
2401 if (fromserver == 0) {
2402 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2403 as->parms[1].items->data);
2407 toserver = GetServer(as->parms[3].items->data);
2408 if (toserver == 0) {
2409 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2410 as->parms[3].items->data);
2414 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2416 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2417 as->parms[2].items->data);
2420 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2422 PrintError("", code);
2425 "vos : partition %s does not exist on the server\n",
2426 as->parms[2].items->data);
2430 topart = volutil_GetPartitionID(as->parms[4].items->data);
2432 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2433 as->parms[4].items->data);
2436 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2438 PrintError("", code);
2441 "vos : partition %s does not exist on the server\n",
2442 as->parms[4].items->data);
2446 if (as->parms[5].items) {
2447 tovolume = as->parms[5].items->data;
2448 if (!ISNAMEVALID(tovolume)) {
2450 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2451 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2454 if (!VolNameOK(tovolume)) {
2456 "Illegal volume name %s, should not end in .readonly or .backup\n",
2460 if (IsNumeric(tovolume)) {
2462 "Illegal volume name %s, should not be a number\n",
2467 /* use actual name of source volume */
2468 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2470 fprintf(STDERR, "vos:cannot access volume %lu\n",
2471 (unsigned long)volid);
2474 strcpy(toVolName, p->name);
2475 tovolume = toVolName;
2476 /* save p for size checks later */
2479 if (as->parms[6].items) {
2480 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2483 PrintError("", err);
2485 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2486 as->parms[6].items->data);
2492 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2495 PrintError("", err);
2497 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2506 if (as->parms[7].items) flags |= RV_OFFLINE;
2507 if (as->parms[8].items) flags |= RV_RDONLY;
2508 if (as->parms[9].items) flags |= RV_NOCLONE;
2509 if (as->parms[10].items) flags |= RV_CPINCR;
2511 MapPartIdIntoName(topart, toPartName);
2512 MapPartIdIntoName(frompart, fromPartName);
2515 * check target partition for space to move volume
2518 code = UV_PartitionInfo(toserver, toPartName, &partition);
2520 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2524 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2527 /* Don't do this again if we did it above */
2529 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2531 fprintf(STDERR, "vos:cannot access volume %lu\n",
2532 (unsigned long)volid);
2537 /* OK if this fails */
2538 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2540 /* Treat existing volume size as "free" */
2542 p->size = (q->size < p->size) ? p->size - q->size : 0;
2544 if (partition.free <= p->size) {
2546 "vos: no space on target partition %s to copy volume %lu\n",
2547 toPartName, (unsigned long)volid);
2555 /* successful copy still not guaranteed but shoot for it */
2558 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2559 topart, tovolid, flags);
2561 PrintDiagnostics("shadow", code);
2564 MapPartIdIntoName(topart, toPartName);
2565 MapPartIdIntoName(frompart, fromPartName);
2566 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2567 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2568 as->parms[3].items->data, toPartName);
2576 register struct cmd_syndesc *as;
2578 afs_int32 server, part, volid, cloneid, voltype;
2579 char partName[10], *volname;
2580 afs_int32 code, err, flags;
2581 struct nvldbentry entry;
2583 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2586 PrintError("", err);
2588 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2589 as->parms[0].items->data);
2593 if (as->parms[1].items || as->parms[2].items) {
2594 if (!as->parms[1].items || !as->parms[2].items) {
2596 "Must specify both -server and -partition options\n");
2599 server = GetServer(as->parms[1].items->data);
2601 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2602 as->parms[1].items->data);
2605 part = volutil_GetPartitionID(as->parms[2].items->data);
2607 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2608 as->parms[2].items->data);
2611 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2613 PrintError("", code);
2616 "vos : partition %s does not exist on the server\n",
2617 as->parms[2].items->data);
2621 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2627 if (as->parms[3].items) {
2628 volname = as->parms[3].items->data;
2629 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2631 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2632 volname, VOLSER_OLDMAXVOLNAME - 1);
2635 if (!VolNameOK(volname)) {
2637 "Illegal volume name %s, should not end in .readonly or .backup\n",
2641 if (IsNumeric(volname)) {
2643 "Illegal volume name %s, should not be a number\n",
2650 if (as->parms[4].items) {
2651 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2654 PrintError("", err);
2656 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2657 as->parms[4].items->data);
2663 if (as->parms[5].items) flags |= RV_OFFLINE;
2664 if (as->parms[6].items) flags |= RV_RDONLY;
2668 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2671 PrintDiagnostics("clone", code);
2674 MapPartIdIntoName(part, partName);
2675 fprintf(STDOUT, "Created clone for volume %lu\n",
2676 as->parms[0].items->data);
2684 register struct cmd_syndesc *as;
2686 afs_int32 avolid, aserver, apart, vtype, code, err;
2687 struct nvldbentry entry;
2689 afs_int32 buvolid, buserver, bupart, butype;
2690 struct nvldbentry buentry;
2692 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2695 PrintError("", err);
2697 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2698 as->parms[0].items->data);
2701 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2705 /* verify this is a readwrite volume */
2707 if (vtype != RWVOL) {
2708 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2712 /* is there a backup volume already? */
2714 if (entry.flags & BACK_EXISTS) {
2715 /* yep, where is it? */
2717 buvolid = entry.volumeId[BACKVOL];
2718 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2723 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2726 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2732 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2733 (unsigned long)buvolid, (unsigned long)buserver);
2738 /* nope, carry on */
2740 code = UV_BackupVolume(aserver, apart, avolid);
2743 PrintDiagnostics("backup", code);
2746 fprintf(STDOUT, "Created backup volume for %s \n",
2747 as->parms[0].items->data);
2753 register struct cmd_syndesc *as;
2756 struct nvldbentry entry;
2757 afs_int32 avolid, aserver, apart, vtype, code, err;
2760 if (as->parms[1].items)
2762 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2765 PrintError("", err);
2767 fprintf(STDERR, "vos: can't find volume '%s'\n",
2768 as->parms[0].items->data);
2771 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2775 if (vtype != RWVOL) {
2776 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2780 if (!ISNAMEVALID(entry.name)) {
2782 "Volume name %s is too long, rename before releasing\n",
2787 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2789 PrintDiagnostics("release", code);
2792 fprintf(STDOUT, "Released volume %s successfully\n",
2793 as->parms[0].items->data);
2799 register struct cmd_syndesc *as;
2802 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2803 char filename[MAXPATHLEN];
2804 struct nvldbentry entry;
2806 rx_SetRxDeadTime(60 * 10);
2807 for (i = 0; i < MAXSERVERS; i++) {
2808 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2811 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2812 if (rxConn->service)
2813 rxConn->service->connDeadTime = rx_connDeadTime;
2816 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2819 PrintError("", err);
2821 fprintf(STDERR, "vos: can't find volume '%s'\n",
2822 as->parms[0].items->data);
2826 if (as->parms[3].items || as->parms[4].items) {
2827 if (!as->parms[3].items || !as->parms[4].items) {
2829 "Must specify both -server and -partition options\n");
2832 aserver = GetServer(as->parms[3].items->data);
2834 fprintf(STDERR, "Invalid server name\n");
2837 apart = volutil_GetPartitionID(as->parms[4].items->data);
2839 fprintf(STDERR, "Invalid partition name\n");
2843 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2848 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2849 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2851 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2852 as->parms[1].items->data, code);
2856 if (as->parms[2].items) {
2857 strcpy(filename, as->parms[2].items->data);
2859 strcpy(filename, "");
2862 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2864 if (as->parms[5].items) {
2866 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2867 DumpFunction, filename, flags);
2870 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2873 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2874 flags &= ~VOLDUMPV2_OMITDIRS;
2878 PrintDiagnostics("dump", code);
2881 if (strcmp(filename, ""))
2882 fprintf(STDERR, "Dumped volume %s in file %s\n",
2883 as->parms[0].items->data, filename);
2885 fprintf(STDERR, "Dumped volume %s in stdout \n",
2886 as->parms[0].items->data);
2901 register struct cmd_syndesc *as;
2904 afs_int32 avolid, aparentid, aserver, apart, code, vcode, err;
2905 afs_int32 aoverwrite = ASK;
2906 afs_int32 acreation = 0, alastupdate = 0;
2907 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2909 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2910 char volname[VOLSER_MAXVOLNAME + 1];
2911 struct nvldbentry entry;
2916 if (as->parms[4].items) {
2917 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2920 PrintError("", err);
2922 fprintf(STDERR, "vos: can't find volume '%s'\n",
2923 as->parms[4].items->data);
2929 if (as->parms[5].items) {
2930 if ((strcmp(as->parms[5].items->data, "a") == 0)
2931 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2933 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2934 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2936 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2937 || (strcmp(as->parms[5].items->data, "inc") == 0)
2938 || (strcmp(as->parms[5].items->data, "increment") == 0)
2939 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2942 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2943 as->parms[5].items->data);
2947 if (as->parms[6].items)
2949 if (as->parms[7].items) {
2954 if (as->parms[8].items) {
2955 if ((strcmp(as->parms[8].items->data, "d") == 0)
2956 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2957 acreation = TS_DUMP;
2958 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2959 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2960 acreation = TS_KEEP;
2961 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2962 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2965 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2966 as->parms[8].items->data);
2971 if (as->parms[9].items) {
2972 if ((strcmp(as->parms[9].items->data, "d") == 0)
2973 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2974 alastupdate = TS_DUMP;
2975 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2976 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2977 alastupdate = TS_KEEP;
2978 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2979 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2980 alastupdate = TS_NEW;
2982 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2983 as->parms[9].items->data);
2988 aserver = GetServer(as->parms[0].items->data);
2990 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2991 as->parms[0].items->data);
2994 apart = volutil_GetPartitionID(as->parms[1].items->data);
2996 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2997 as->parms[1].items->data);
3000 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3002 PrintError("", code);
3005 "vos : partition %s does not exist on the server\n",
3006 as->parms[1].items->data);
3009 strcpy(avolname, as->parms[2].items->data);
3010 if (!ISNAMEVALID(avolname)) {
3012 "vos: the name of the volume %s exceeds the size limit\n",
3016 if (!VolNameOK(avolname)) {
3018 "Illegal volume name %s, should not end in .readonly or .backup\n",
3022 if (as->parms[3].items) {
3023 strcpy(afilename, as->parms[3].items->data);
3024 if (!FileExists(afilename)) {
3025 fprintf(STDERR, "Can't access file %s\n", afilename);
3029 strcpy(afilename, "");
3032 /* Check if volume exists or not */
3034 vsu_ExtractName(volname, avolname);
3035 vcode = VLDB_GetEntryByName(volname, &entry);
3036 if (vcode) { /* no volume - do a full restore */
3037 restoreflags = RV_FULLRST;
3038 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3040 "Volume does not exist; Will perform a full restore\n");
3043 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3044 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3045 restoreflags = RV_FULLRST;
3046 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3048 "%s Volume does not exist; Will perform a full restore\n",
3049 readonly ? "RO" : "RW");
3052 avolid = entry.volumeId[voltype];
3053 } else if (entry.volumeId[voltype] != 0
3054 && entry.volumeId[voltype] != avolid) {
3055 avolid = entry.volumeId[voltype];
3057 aparentid = entry.volumeId[RWVOL];
3060 else { /* volume exists - do we do a full incremental or abort */
3061 int Oserver, Opart, Otype, vol_elsewhere = 0;
3062 struct nvldbentry Oentry;
3066 avolid = entry.volumeId[voltype];
3067 } else if (entry.volumeId[voltype] != 0
3068 && entry.volumeId[voltype] != avolid) {
3069 avolid = entry.volumeId[voltype];
3071 aparentid = entry.volumeId[RWVOL];
3073 /* A file name was specified - check if volume is on another partition */
3074 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3078 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3081 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3085 if (!vcode || (Opart != apart))
3088 if (aoverwrite == ASK) {
3089 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3091 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3095 /* Ask what to do */
3096 if (vol_elsewhere) {
3098 "The volume %s %u already exists on a different server/part\n",
3099 volname, entry.volumeId[voltype]);
3101 "Do you want to do a full restore or abort? [fa](a): ");
3104 "The volume %s %u already exists in the VLDB\n",
3105 volname, entry.volumeId[voltype]);
3107 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3110 while (!(dc == EOF || dc == '\n'))
3111 dc = getchar(); /* goto end of line */
3112 if ((c == 'f') || (c == 'F'))
3114 else if ((c == 'i') || (c == 'I'))
3120 if (aoverwrite == ABORT) {
3121 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3123 } else if (aoverwrite == FULL) {
3124 restoreflags = RV_FULLRST;
3126 "Volume exists; Will delete and perform full restore\n");
3127 } else if (aoverwrite == INC) {
3129 if (vol_elsewhere) {
3131 "%s volume %lu already exists on a different server/part; not allowed\n",
3132 readonly ? "RO" : "RW", (unsigned long)avolid);
3138 restoreflags |= RV_OFFLINE;
3140 restoreflags |= RV_RDONLY;
3142 switch (acreation) {
3144 restoreflags |= RV_CRDUMP;
3147 restoreflags |= RV_CRKEEP;
3150 restoreflags |= RV_CRNEW;
3153 if (aoverwrite == FULL)
3154 restoreflags |= RV_CRNEW;
3156 restoreflags |= RV_CRKEEP;
3159 switch (alastupdate) {
3161 restoreflags |= RV_LUDUMP;
3164 restoreflags |= RV_LUKEEP;
3167 restoreflags |= RV_LUNEW;
3170 restoreflags |= RV_LUDUMP;
3174 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3175 avolname, restoreflags, WriteData, afilename);
3177 PrintDiagnostics("restore", code);
3180 MapPartIdIntoName(apart, apartName);
3183 * patch typo here - originally "parms[1]", should be "parms[0]"
3186 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3187 as->parms[0].items->data, apartName);
3193 register struct cmd_syndesc *as;
3196 afs_int32 avolid, code, err;
3198 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3201 PrintError("", err);
3203 fprintf(STDERR, "vos: can't find volume '%s'\n",
3204 as->parms[0].items->data);
3208 code = UV_LockRelease(avolid);
3210 PrintDiagnostics("unlock", code);
3213 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3214 as->parms[0].items->data);
3220 register struct cmd_syndesc *as;
3222 afs_int32 avolid, aserver, apart, code, err;
3223 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3225 vsu_ExtractName(avolname, as->parms[2].items->data);;
3226 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3229 PrintError("", err);
3231 fprintf(STDERR, "vos: can't find volume '%s'\n",
3232 as->parms[2].items->data);
3235 aserver = GetServer(as->parms[0].items->data);
3237 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3238 as->parms[0].items->data);
3241 apart = volutil_GetPartitionID(as->parms[1].items->data);
3243 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3244 as->parms[1].items->data);
3247 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3249 PrintError("", code);
3252 "vos : partition %s does not exist on the server\n",
3253 as->parms[1].items->data);
3256 code = UV_AddSite(aserver, apart, avolid);
3258 PrintDiagnostics("addsite", code);
3261 MapPartIdIntoName(apart, apartName);
3262 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3263 as->parms[0].items->data, apartName, as->parms[2].items->data);
3269 register struct cmd_syndesc *as;
3272 afs_int32 avolid, aserver, apart, code, err;
3273 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3275 vsu_ExtractName(avolname, as->parms[2].items->data);
3276 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3279 PrintError("", err);
3281 fprintf(STDERR, "vos: can't find volume '%s'\n",
3282 as->parms[2].items->data);
3285 aserver = GetServer(as->parms[0].items->data);
3287 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3288 as->parms[0].items->data);
3291 apart = volutil_GetPartitionID(as->parms[1].items->data);
3293 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3294 as->parms[1].items->data);
3298 *skip the partition validity check, since it is possible that the partition
3299 *has since been decomissioned.
3302 if (!IsPartValid(apart,aserver,&code)){
3303 if(code) PrintError("",code);
3304 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3308 code = UV_RemoveSite(aserver, apart, avolid);
3310 PrintDiagnostics("remsite", code);
3313 MapPartIdIntoName(apart, apartName);
3314 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3315 as->parms[0].items->data, apartName, as->parms[2].items->data);
3321 register struct cmd_syndesc *as;
3323 afs_int32 avolid, aserver, apart, code, err;
3326 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3329 PrintError("", err);
3331 fprintf(STDERR, "vos: can't find volume '%s'\n",
3332 as->parms[2].items->data);
3335 aserver = GetServer(as->parms[0].items->data);
3337 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3338 as->parms[0].items->data);
3341 apart = volutil_GetPartitionID(as->parms[1].items->data);
3343 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3344 as->parms[1].items->data);
3347 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3349 PrintError("", code);
3352 "vos : partition %s does not exist on the server\n",
3353 as->parms[1].items->data);
3356 code = UV_ChangeLocation(aserver, apart, avolid);
3358 PrintDiagnostics("addsite", code);
3361 MapPartIdIntoName(apart, apartName);
3362 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3363 as->parms[0].items->data, apartName, as->parms[2].items->data);
3369 register struct cmd_syndesc *as;
3371 afs_int32 aserver, code;
3372 struct partList dummyPartList;
3377 aserver = GetServer(as->parms[0].items->data);
3379 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3380 as->parms[0].items->data);
3385 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3387 PrintDiagnostics("listpart", code);
3391 fprintf(STDOUT, "The partitions on the server are:\n");
3392 for (i = 0; i < cnt; i++) {
3393 if (dummyPartList.partFlags[i] & PARTVALID) {
3394 memset(pname, 0, sizeof(pname));
3395 MapPartIdIntoName(dummyPartList.partId[i], pname);
3396 fprintf(STDOUT, " %10s ", pname);
3398 if ((i % 5) == 0 && (i != 0))
3399 fprintf(STDOUT, "\n");
3402 fprintf(STDOUT, "\n");
3403 fprintf(STDOUT, "Total: %d\n", total);
3409 CompareVolName(p1, p2)
3412 volintInfo *arg1, *arg2;
3414 arg1 = (volintInfo *) p1;
3415 arg2 = (volintInfo *) p2;
3416 return (strcmp(arg1->name, arg2->name));
3420 /*------------------------------------------------------------------------
3421 * PRIVATE XCompareVolName
3424 * Comparison routine for volume names coming from an extended
3428 * a_obj1P : Char ptr to first extended vol info object
3429 * a_obj1P : Char ptr to second extended vol info object
3432 * The value of strcmp() on the volume names within the passed
3433 * objects (i,e., -1, 0, or 1).
3436 * Passed to qsort() as the designated comparison routine.
3440 *------------------------------------------------------------------------*/
3443 XCompareVolName(a_obj1P, a_obj2P)
3444 char *a_obj1P, *a_obj2P;
3446 { /*XCompareVolName */
3449 (((struct volintXInfo *)(a_obj1P))->name,
3450 ((struct volintXInfo *)(a_obj2P))->name));
3452 } /*XCompareVolName */
3455 CompareVolID(p1, p2)
3458 volintInfo *arg1, *arg2;
3460 arg1 = (volintInfo *) p1;
3461 arg2 = (volintInfo *) p2;
3462 if (arg1->volid == arg2->volid)
3464 if (arg1->volid > arg2->volid)
3471 /*------------------------------------------------------------------------
3472 * PRIVATE XCompareVolID
3475 * Comparison routine for volume IDs coming from an extended
3479 * a_obj1P : Char ptr to first extended vol info object
3480 * a_obj1P : Char ptr to second extended vol info object
3483 * The value of strcmp() on the volume names within the passed
3484 * objects (i,e., -1, 0, or 1).
3487 * Passed to qsort() as the designated comparison routine.
3491 *------------------------------------------------------------------------*/
3494 XCompareVolID(a_obj1P, a_obj2P)
3495 char *a_obj1P, *a_obj2P;
3497 { /*XCompareVolID */
3499 afs_int32 id1, id2; /*Volume IDs we're comparing */
3501 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3502 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3510 } /*XCompareVolID */
3512 /*------------------------------------------------------------------------
3513 * PRIVATE ListVolumes
3516 * Routine used to list volumes, contacting the Volume Server
3517 * directly, bypassing the VLDB.
3520 * as : Ptr to parsed command line arguments.
3523 * 0 Successful operation
3526 * Nothing interesting.
3530 *------------------------------------------------------------------------*/
3534 register struct cmd_syndesc *as;
3536 afs_int32 apart, int32list, fast;
3537 afs_int32 aserver, code;
3538 volintInfo *pntr, *oldpntr;
3542 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3543 int wantExtendedInfo; /*Do we want extended vol info? */
3546 struct partList dummyPartList;
3554 if (as->parms[3].items)
3556 if (as->parms[4].items)
3560 if (as->parms[2].items)
3566 if (as->parms[5].items) {
3568 * We can't coexist with the fast flag.
3572 "vos: Can't use the -fast and -extended flags together\n");
3577 * We need to turn on ``long'' listings to get the full effect.
3579 wantExtendedInfo = 1;
3582 wantExtendedInfo = 0;
3583 if (as->parms[1].items) {
3584 apart = volutil_GetPartitionID(as->parms[1].items->data);
3586 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3587 as->parms[1].items->data);
3590 dummyPartList.partId[0] = apart;
3591 dummyPartList.partFlags[0] = PARTVALID;
3594 aserver = GetServer(as->parms[0].items->data);
3596 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3597 as->parms[0].items->data);
3602 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3604 PrintError("", code);
3607 "vos : partition %s does not exist on the server\n",
3608 as->parms[1].items->data);
3612 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3614 PrintDiagnostics("listvol", code);
3618 for (i = 0; i < cnt; i++) {
3619 if (dummyPartList.partFlags[i] & PARTVALID) {
3620 if (wantExtendedInfo)
3622 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3626 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3629 PrintDiagnostics("listvol", code);
3634 if (wantExtendedInfo) {
3635 origxInfoP = xInfoP;
3636 base = (char *)xInfoP;
3639 base = (char *)pntr;
3643 if (wantExtendedInfo)
3644 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3646 qsort(base, count, sizeof(volintInfo), CompareVolName);
3648 if (wantExtendedInfo)
3649 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3651 qsort(base, count, sizeof(volintInfo), CompareVolID);
3653 MapPartIdIntoName(dummyPartList.partId[i], pname);
3656 "Total number of volumes on server %s partition %s: %lu \n",
3657 as->parms[0].items->data, pname,
3658 (unsigned long)count);
3659 if (wantExtendedInfo) {
3660 #ifdef FULL_LISTVOL_SWITCH
3661 if (as->parms[6].items)
3662 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3663 count, int32list, fast, quiet);
3665 #endif /* FULL_LISTVOL_SWITCH */
3666 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3667 count, int32list, fast, quiet);
3670 xInfoP = (volintXInfo *) 0;
3672 #ifdef FULL_LISTVOL_SWITCH
3673 if (as->parms[6].items)
3674 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3677 #endif /* FULL_LISTVOL_SWITCH */
3678 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3679 count, int32list, fast, quiet);
3682 pntr = (volintInfo *) 0;
3691 register struct cmd_syndesc *as;
3693 afs_int32 pnum = 0, code; /* part name */
3699 if (as->parms[0].items) {
3700 tserver = GetServer(as->parms[0].items->data);
3702 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3703 as->parms[0].items->data);
3708 if (as->parms[1].items) {
3709 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3711 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3712 as->parms[1].items->data);
3715 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3717 PrintError("", code);
3720 "vos: partition %s does not exist on the server\n",
3721 as->parms[1].items->data);
3728 "The -partition option requires a -server option\n");
3733 if (as->parms[2].items) {
3734 /* Synchronize an individual volume */
3735 volname = as->parms[2].items->data;
3736 code = UV_SyncVolume(tserver, pnum, volname, flags);
3740 "Without a -volume option, the -server option is required\n");
3743 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3747 PrintDiagnostics("syncvldb", code);
3751 /* Print a summary of what we did */
3753 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3755 fprintf(STDOUT, "VLDB synchronized");
3757 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3760 MapPartIdIntoName(pnum, part);
3761 fprintf(STDOUT, " partition %s\n", part);
3763 fprintf(STDOUT, "\n");
3770 register struct cmd_syndesc *as;
3773 afs_int32 pnum, code; /* part name */
3778 tserver = GetServer(as->parms[0].items->data);
3780 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3781 as->parms[0].items->data);
3784 if (as->parms[1].items) {
3785 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3787 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3788 as->parms[1].items->data);
3791 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3793 PrintError("", code);
3796 "vos : partition %s does not exist on the server\n",
3797 as->parms[1].items->data);
3805 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3807 PrintDiagnostics("syncserv", code);
3811 MapPartIdIntoName(pnum, part);
3812 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3813 as->parms[0].items->data, part);
3815 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3816 as->parms[0].items->data);
3825 struct nvldbentry entry;
3828 /* The vlserver will handle names with the .readonly
3829 * and .backup extension as well as volume ids.
3831 vcode = VLDB_GetEntryByName(name, &entry);
3833 PrintError("", vcode);
3836 MapHostToNetwork(&entry);
3837 EnumerateEntry(&entry);
3839 /* Defect #3027: grubby check to handle locked volume.
3840 * If VLOP_ALLOPERS is set, the entry is locked.
3841 * Leave this routine as is, but put in correct check.
3843 if (entry.flags & VLOP_ALLOPERS)
3844 fprintf(STDOUT, " Volume is currently LOCKED \n");
3851 register struct cmd_syndesc *as;
3854 struct nvldbentry entry;
3855 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3857 if (as->parms[3].items) {
3858 /* force flag is on, use the other version */
3859 return NukeVolume(as);
3862 if (as->parms[4].items) {
3866 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3869 PrintError("", err);
3871 fprintf(STDERR, "vos: can't find volume '%s'\n",
3872 as->parms[2].items->data);
3875 part = volutil_GetPartitionID(as->parms[1].items->data);
3877 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3878 as->parms[1].items->data);
3881 server = GetServer(as->parms[0].items->data);
3883 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3884 as->parms[0].items->data);
3887 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3889 PrintError("", code);
3892 "vos : partition %s does not exist on the server\n",
3893 as->parms[1].items->data);
3896 code = VLDB_GetEntryByID(volid, -1, &entry);
3898 if (volid == entry.volumeId[RWVOL])
3899 backupid = entry.volumeId[BACKVOL];
3901 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3902 (unsigned long)volid);
3905 volintInfo *pntr = (volintInfo *) 0;
3908 code = UV_ListOneVolume(server, part, volid, &pntr);
3910 if (volid == pntr->parentID)
3911 backupid = pntr->backupID;
3917 code = UV_VolumeZap(server, part, backupid);
3919 PrintDiagnostics("zap", code);
3922 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3923 (unsigned long)backupid);
3926 code = UV_VolumeZap(server, part, volid);
3928 PrintDiagnostics("zap", code);
3931 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3938 register struct cmd_syndesc *as;
3941 afs_int32 server, code;
3942 transDebugInfo *pntr, *oldpntr;
3947 server = GetServer(as->parms[0].items->data);
3949 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3950 as->parms[0].items->data);
3953 code = UV_VolserStatus(server, &pntr, &count);
3955 PrintDiagnostics("status", code);
3960 fprintf(STDOUT, "No active transactions on %s\n",
3961 as->parms[0].items->data);
3963 fprintf(STDOUT, "Total transactions: %d\n", count);
3965 for (i = 0; i < count; i++) {
3966 /*print out the relevant info */
3967 fprintf(STDOUT, "--------------------------------------\n");
3968 fprintf(STDOUT, "transaction: %lu created: %s",
3969 (unsigned long)pntr->tid, vos_ctime( & pntr->time));
3970 if (pntr->returnCode) {
3971 fprintf(STDOUT, "returnCode: %lu\n",
3972 (unsigned long)pntr->returnCode);
3975 fprintf(STDOUT, "attachFlags: ");
3976 switch (pntr->iflags) {
3978 fprintf(STDOUT, "offline ");
3981 fprintf(STDOUT, "busy ");
3984 fprintf(STDOUT, "readonly ");
3987 fprintf(STDOUT, "create ");
3990 fprintf(STDOUT, "create volid ");
3993 fprintf(STDOUT, "\n");
3996 fprintf(STDOUT, "volumeStatus: ");
3997 switch (pntr->vflags) {
3998 case VTDeleteOnSalvage:
3999 fprintf(STDOUT, "deleteOnSalvage ");
4000 case VTOutOfService:
4001 fprintf(STDOUT, "outOfService ");
4003 fprintf(STDOUT, "deleted ");
4005 fprintf(STDOUT, "\n");
4008 fprintf(STDOUT, "transactionFlags: ");
4009 fprintf(STDOUT, "delete\n");
4011 MapPartIdIntoName(pntr->partition, pname);
4012 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4013 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4014 if (pntr->callValid) {
4016 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
4017 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4018 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4021 fprintf(STDOUT, "--------------------------------------\n");
4022 fprintf(STDOUT, "\n");
4031 register struct cmd_syndesc *as;
4033 afs_int32 code1, code2, code;
4034 struct nvldbentry entry;
4036 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4038 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4039 as->parms[0].items->data);
4042 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4043 if ((!code1) && (!code2)) { /*the newname already exists */
4044 fprintf(STDERR, "vos: volume %s already exists\n",
4045 as->parms[1].items->data);
4049 if (code1 && code2) {
4050 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4051 as->parms[0].items->data, as->parms[1].items->data);
4054 if (!VolNameOK(as->parms[0].items->data)) {
4056 "Illegal volume name %s, should not end in .readonly or .backup\n",
4057 as->parms[0].items->data);
4060 if (!ISNAMEVALID(as->parms[1].items->data)) {
4062 "vos: the new volume name %s exceeds the size limit of %d\n",
4063 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4066 if (!VolNameOK(as->parms[1].items->data)) {
4068 "Illegal volume name %s, should not end in .readonly or .backup\n",
4069 as->parms[1].items->data);
4072 if (IsNumeric(as->parms[1].items->data)) {
4073 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4074 as->parms[1].items->data);
4077 MapHostToNetwork(&entry);
4079 UV_RenameVolume(&entry, as->parms[0].items->data,
4080 as->parms[1].items->data);
4082 PrintDiagnostics("rename", code);
4085 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4086 as->parms[1].items->data);
4090 GetVolumeInfo(volid, server, part, voltype, rentry)
4091 afs_int32 *server, volid, *part, *voltype;
4092 register struct nvldbentry *rentry;
4097 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4100 "Could not fetch the entry for volume %lu from VLDB \n",
4101 (unsigned long)volid);
4102 PrintError("", vcode);
4105 MapHostToNetwork(rentry);
4106 if (volid == rentry->volumeId[ROVOL]) {
4108 for (i = 0; i < rentry->nServers; i++) {
4109 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4110 && !(rentry->serverFlags[i] & RO_DONTUSE))
4115 "RO volume is not found in VLDB entry for volume %lu\n",
4116 (unsigned long)volid);
4120 *server = rentry->serverNumber[index];
4121 *part = rentry->serverPartition[index];
4125 index = Lp_GetRwIndex(rentry);
4128 "RW Volume is not found in VLDB entry for volume %lu\n",
4129 (unsigned long)volid);
4132 if (volid == rentry->volumeId[RWVOL]) {
4134 *server = rentry->serverNumber[index];
4135 *part = rentry->serverPartition[index];
4138 if (volid == rentry->volumeId[BACKVOL]) {
4140 *server = rentry->serverNumber[index];
4141 *part = rentry->serverPartition[index];
4145 "unexpected volume type for volume %lu\n",
4146 (unsigned long)volid);
4152 register struct cmd_syndesc *as;
4158 struct VldbListByAttributes attributes;
4159 nbulkentries arrayEntries;
4160 register struct nvldbentry *vllist;
4161 struct cmd_item *itp;
4164 char prefix[VOLSER_MAXVOLNAME + 1];
4166 afs_int32 totalBack = 0, totalFail = 0, err;
4168 if (as->parms[0].items) { /* -id */
4169 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4171 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4174 for (itp = as->parms[0].items; itp; itp = itp->next) {
4175 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4178 PrintError("", err);
4180 fprintf(STDERR, "vos: can't find volume '%s'\n",
4184 if (as->parms[4].items) { /* -noexecute */
4185 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4190 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4192 fprintf(STDERR, "Could not delete entry for volume %s\n",
4195 "You must specify a RW volume name or ID "
4196 "(the entire VLDB entry will be deleted)\n");
4197 PrintError("", vcode);
4203 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4207 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4208 fprintf(STDERR, "You must specify an option\n");
4212 /* Zero out search attributes */
4213 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4215 if (as->parms[1].items) { /* -prefix */
4216 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4218 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4220 "You must provide -server with the -prefix argument\n");
4225 if (as->parms[2].items) { /* -server */
4227 aserver = GetServer(as->parms[2].items->data);
4229 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4230 as->parms[2].items->data);
4233 attributes.server = ntohl(aserver);
4234 attributes.Mask |= VLLIST_SERVER;
4237 if (as->parms[3].items) { /* -partition */
4238 if (!as->parms[2].items) {
4240 "You must provide -server with the -partition argument\n");
4243 apart = volutil_GetPartitionID(as->parms[3].items->data);
4245 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4246 as->parms[3].items->data);
4249 attributes.partition = apart;
4250 attributes.Mask |= VLLIST_PARTITION;
4253 /* Print status line of what we are doing */
4254 fprintf(STDOUT, "Deleting VLDB entries for ");
4255 if (as->parms[2].items) {
4256 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4258 if (as->parms[3].items) {
4260 MapPartIdIntoName(apart, pname);
4261 fprintf(STDOUT, "partition %s ", pname);
4264 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4266 fprintf(STDOUT, "\n");
4269 /* Get all the VLDB entries on a server and/or partition */
4270 memset(&arrayEntries, 0, sizeof(arrayEntries));
4271 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4273 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4274 PrintError("", vcode);
4278 /* Process each entry */
4279 for (j = 0; j < nentries; j++) {
4280 vllist = &arrayEntries.nbulkentries_val[j];
4282 /* It only deletes the RW volumes */
4283 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4286 "Omitting to delete %s due to prefix %s mismatch\n",
4287 vllist->name, prefix);
4294 if (as->parms[4].items) { /* -noexecute */
4295 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4301 /* Only matches the RW volume name */
4302 avolid = vllist->volumeId[RWVOL];
4303 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4305 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4308 PrintError("", vcode);
4313 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4318 fprintf(STDOUT, "----------------------\n");
4320 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4321 (unsigned long)totalBack, (unsigned long)totalFail);
4322 if (arrayEntries.nbulkentries_val)
4323 free(arrayEntries.nbulkentries_val);
4329 CompareVldbEntryByName(p1, p2)
4332 struct nvldbentry *arg1, *arg2;
4334 arg1 = (struct nvldbentry *)p1;
4335 arg2 = (struct nvldbentry *)p2;
4336 return (strcmp(arg1->name, arg2->name));
4340 static int CompareVldbEntry(p1,p2)
4343 struct nvldbentry *arg1,*arg2;
4346 char comp1[100],comp2[100];
4347 char temp1[20],temp2[20];
4349 arg1 = (struct nvldbentry *)p1;
4350 arg2 = (struct nvldbentry *)p2;
4354 for(i = 0; i < arg1->nServers; i++)
4355 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4356 for(i = 0; i < arg2->nServers; i++)
4357 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4358 if(pos1 == -1 || pos2 == -1){
4362 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4363 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4364 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4365 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4366 strcat(comp1,temp1);
4367 strcat(comp2,temp2);
4368 strcat(comp1,arg1->name);
4369 strcat(comp1,arg2->name);
4370 return(strcmp(comp1,comp2));
4377 struct cmd_syndesc *as;
4380 afs_int32 aserver, code;
4382 struct VldbListByAttributes attributes;
4383 nbulkentries arrayEntries;
4384 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4385 afs_int32 centries, nentries = 0, tarraysize, parraysize;
4388 int quiet, sort, lock;
4389 afs_int32 thisindex, nextindex;
4394 attributes.Mask = 0;
4395 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4396 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4397 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4399 /* If the volume name is given, Use VolumeInfoCmd to look it up
4400 * and not ListAttributes.
4402 if (as->parms[0].items) {
4405 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4408 code = VolumeInfoCmd(as->parms[0].items->data);
4410 PrintError("", code);
4416 /* Server specified */
4417 if (as->parms[1].items) {
4418 aserver = GetServer(as->parms[1].items->data);
4420 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4421 as->parms[1].items->data);
4424 attributes.server = ntohl(aserver);
4425 attributes.Mask |= VLLIST_SERVER;
4428 /* Partition specified */
4429 if (as->parms[2].items) {
4430 apart = volutil_GetPartitionID(as->parms[2].items->data);
4432 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4433 as->parms[2].items->data);
4436 attributes.partition = apart;
4437 attributes.Mask |= VLLIST_PARTITION;
4441 attributes.Mask |= VLLIST_FLAG;
4442 attributes.flag = VLOP_ALLOPERS;
4445 /* Print header information */
4447 MapPartIdIntoName(apart, pname);
4448 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4449 (as->parms[1].items ? "server" : "all"),
4450 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4451 (as->parms[2].items ? " partition " : ""),
4452 (as->parms[2].items ? pname : ""),
4453 (lock ? "which are locked:" : ""));
4456 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4457 memset(&arrayEntries, 0, sizeof(arrayEntries));
4462 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4463 &arrayEntries, &nextindex);
4464 if (vcode == RXGEN_OPCODE) {
4465 /* Vlserver not running with ListAttributesN2. Fall back */
4467 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4471 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4472 PrintError("", vcode);
4475 nentries += centries;
4477 /* We don't sort, so just print the entries now */
4479 for (j = 0; j < centries; j++) { /* process each entry */
4480 vllist = &arrayEntries.nbulkentries_val[j];
4481 MapHostToNetwork(vllist);
4482 EnumerateEntry(vllist);
4484 if (vllist->flags & VLOP_ALLOPERS)
4485 fprintf(STDOUT, " Volume is currently LOCKED \n");
4489 /* So we sort. First we must collect all the entries and keep
4492 else if (centries > 0) {
4494 /* steal away the first bulk entries array */
4495 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4496 tarraysize = centries * sizeof(struct nvldbentry);
4497 arrayEntries.nbulkentries_val = 0;
4499 /* Grow the tarray to keep the extra entries */
4500 parraysize = (centries * sizeof(struct nvldbentry));
4502 (struct nvldbentry *)realloc(tarray,
4503 tarraysize + parraysize);
4506 "Could not allocate enough space for the VLDB entries\n");
4512 memcpy(((char *)tarray) + tarraysize,
4513 (char *)arrayEntries.nbulkentries_val, parraysize);
4514 tarraysize += parraysize;
4518 /* Free the bulk array */
4519 if (arrayEntries.nbulkentries_val) {
4520 free(arrayEntries.nbulkentries_val);
4521 arrayEntries.nbulkentries_val = 0;
4525 /* Here is where we now sort all the entries and print them */
4526 if (sort && (nentries > 0)) {
4527 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4528 CompareVldbEntryByName);
4529 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4530 MapHostToNetwork(vllist);
4531 EnumerateEntry(vllist);
4533 if (vllist->flags & VLOP_ALLOPERS)
4534 fprintf(STDOUT, " Volume is currently LOCKED \n");
4540 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4548 register struct cmd_syndesc *as;
4550 afs_int32 apart = 0, avolid;
4551 afs_int32 aserver = 0, code, aserver1, apart1;
4553 struct VldbListByAttributes attributes;
4554 nbulkentries arrayEntries;
4555 register struct nvldbentry *vllist;
4559 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4560 afs_int32 totalBack = 0;
4561 afs_int32 totalFail = 0;
4562 int previdx = -1, error, same;
4564 struct cmd_item *ti;
4568 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4569 attributes.Mask = 0;
4571 seenprefix = (as->parms[0].items ? 1 : 0);
4572 exclude = (as->parms[3].items ? 1 : 0);
4573 seenxprefix = (as->parms[4].items ? 1 : 0);
4574 noaction = (as->parms[5].items ? 1 : 0);
4576 if (as->parms[1].items) { /* -server */
4577 aserver = GetServer(as->parms[1].items->data);
4579 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4580 as->parms[1].items->data);
4583 attributes.server = ntohl(aserver);
4584 attributes.Mask |= VLLIST_SERVER;
4587 if (as->parms[2].items) { /* -partition */
4588 apart = volutil_GetPartitionID(as->parms[2].items->data);
4590 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4591 as->parms[2].items->data);
4594 attributes.partition = apart;
4595 attributes.Mask |= VLLIST_PARTITION;
4598 /* Check to make sure the prefix and xprefix expressions compile ok */
4600 for (ti = as->parms[0].items; ti; ti = ti->next) {
4601 if (strncmp(ti->data, "^", 1) == 0) {
4602 #ifdef HAVE_POSIX_REGEX
4606 code = regcomp(&re, ti->data, REG_NOSUB);
4608 regerror(code, &re, errbuf, sizeof errbuf);
4610 "Unrecognizable -prefix regular expression: '%s': %s\n",
4616 ccode = (char *)re_comp(ti->data);
4619 "Unrecognizable -prefix regular expression: '%s': %s\n",
4628 for (ti = as->parms[4].items; ti; ti = ti->next) {
4629 if (strncmp(ti->data, "^", 1) == 0) {
4630 #ifdef HAVE_POSIX_REGEX
4634 code = regcomp(&re, ti->data, REG_NOSUB);
4636 regerror(code, &re, errbuf, sizeof errbuf);
4638 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4644 ccode = (char *)re_comp(ti->data);
4647 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4656 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4657 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4659 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4660 PrintError("", vcode);
4664 if (as->parms[1].items || as->parms[2].items || verbose) {
4665 fprintf(STDOUT, "%s up volumes",
4666 (noaction ? "Would have backed" : "Backing"));
4668 if (as->parms[1].items) {
4669 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4670 } else if (as->parms[2].items) {
4671 fprintf(STDOUT, " for all servers");
4674 if (as->parms[2].items) {
4675 MapPartIdIntoName(apart, pname);
4676 fprintf(STDOUT, " partition %s", pname);
4679 if (seenprefix || (!seenprefix && seenxprefix)) {
4680 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4681 ex = (seenprefix ? exclude : !exclude);
4682 exp = (strncmp(ti->data, "^", 1) == 0);
4683 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4684 (exp ? "expression" : "prefix"), ti->data);
4685 for (ti = ti->next; ti; ti = ti->next) {
4686 exp = (strncmp(ti->data, "^", 1) == 0);
4687 printf(" %sor %s '%s'", (ex ? "n" : ""),
4688 (exp ? "expression" : "prefix"), ti->data);
4692 if (seenprefix && seenxprefix) {
4693 ti = as->parms[4].items;
4694 exp = (strncmp(ti->data, "^", 1) == 0);
4695 fprintf(STDOUT, " %swhich match %s '%s'",
4696 (exclude ? "adding those " : "removing those "),
4697 (exp ? "expression" : "prefix"), ti->data);
4698 for (ti = ti->next; ti; ti = ti->next) {
4699 exp = (strncmp(ti->data, "^", 1) == 0);
4700 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4704 fprintf(STDOUT, " .. ");
4706 fprintf(STDOUT, "\n");
4710 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4711 vllist = &arrayEntries.nbulkentries_val[j];
4714 for (ti = as->parms[0].items; ti; ti = ti->next) {
4715 if (strncmp(ti->data, "^", 1) == 0) {
4716 #ifdef HAVE_POSIX_REGEX
4720 /* XXX -- should just do the compile once! */
4721 code = regcomp(&re, ti->data, REG_NOSUB);
4723 regerror(code, &re, errbuf, sizeof errbuf);
4725 "Error in -prefix regular expression: '%s': %s\n",
4729 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4732 ccode = (char *)re_comp(ti->data);
4735 "Error in -prefix regular expression: '%s': %s\n",
4739 match = (re_exec(vllist->name) == 1);
4743 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4753 /* Without the -exclude flag: If it matches the prefix, then
4754 * check if we want to exclude any from xprefix.
4755 * With the -exclude flag: If it matches the prefix, then
4756 * check if we want to add any from xprefix.
4758 if (match && seenxprefix) {
4759 for (ti = as->parms[4].items; ti; ti = ti->next) {
4760 if (strncmp(ti->data, "^", 1) == 0) {
4761 #ifdef HAVE_POSIX_REGEX
4765 /* XXX -- should just do the compile once! */
4766 code = regcomp(&re, ti->data, REG_NOSUB);
4768 regerror(code, &re, errbuf, sizeof errbuf);
4770 "Error in -xprefix regular expression: '%s': %s\n",
4774 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4778 ccode = (char *)re_comp(ti->data);
4781 "Error in -xprefix regular expression: '%s': %s\n",
4785 if (re_exec(vllist->name) == 1) {
4791 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4801 match = !match; /* -exclude will reverse the match */
4803 continue; /* Skip if no match */
4805 /* Print list of volumes to backup */
4807 fprintf(STDOUT, " %s\n", vllist->name);
4811 if (!(vllist->flags & RW_EXISTS)) {
4814 "Omitting to backup %s since RW volume does not exist \n",
4816 fprintf(STDOUT, "\n");
4822 avolid = vllist->volumeId[RWVOL];
4823 MapHostToNetwork(vllist);
4824 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4825 if (aserver1 == -1 || apart1 == -1) {
4826 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4832 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4835 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4841 if ((aserver && !same) || (apart && (apart != apart1))) {
4844 "Omitting to backup %s since the RW is in a different location\n",
4850 time_t now = time(0);
4851 fprintf(STDOUT, "Creating backup volume for %s on %s",
4852 vllist->name, ctime(&now));
4856 code = UV_BackupVolume(aserver1, apart1, avolid);
4858 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4864 fprintf(STDOUT, "\n");
4866 } /* process each vldb entry */
4867 fprintf(STDOUT, "done\n");
4868 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4869 (unsigned long)totalBack, (unsigned long)totalFail);
4871 if (arrayEntries.nbulkentries_val)
4872 free(arrayEntries.nbulkentries_val);
4878 register struct cmd_syndesc *as;
4881 afs_int32 aserver, code;
4883 struct VldbListByAttributes attributes;
4884 nbulkentries arrayEntries;
4885 register struct nvldbentry *vllist;
4894 attributes.Mask = 0;
4896 if (as->parms[0].items) { /* server specified */
4897 aserver = GetServer(as->parms[0].items->data);
4899 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4900 as->parms[0].items->data);
4903 attributes.server = ntohl(aserver);
4904 attributes.Mask |= VLLIST_SERVER;
4906 if (as->parms[1].items) { /* partition specified */
4907 apart = volutil_GetPartitionID(as->parms[1].items->data);
4909 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4910 as->parms[1].items->data);
4913 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4915 PrintError("", code);
4918 "vos : partition %s does not exist on the server\n",
4919 as->parms[1].items->data);
4922 attributes.partition = apart;
4923 attributes.Mask |= VLLIST_PARTITION;
4925 attributes.flag = VLOP_ALLOPERS;
4926 attributes.Mask |= VLLIST_FLAG;
4927 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4928 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4930 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4931 PrintError("", vcode);
4934 for (j = 0; j < nentries; j++) { /* process each entry */
4935 vllist = &arrayEntries.nbulkentries_val[j];
4936 volid = vllist->volumeId[RWVOL];
4938 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4939 LOCKREL_OPCODE | LOCKREL_AFSID |
4942 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4944 PrintError("", vcode);
4949 MapPartIdIntoName(apart, pname);
4952 "Could not lock %lu VLDB entries of %lu locked entries\n",
4953 (unsigned long)totalE, (unsigned long)nentries);
4955 if (as->parms[0].items) {
4957 "Unlocked all the VLDB entries for volumes on server %s ",
4958 as->parms[0].items->data);
4959 if (as->parms[1].items) {
4960 MapPartIdIntoName(apart, pname);
4961 fprintf(STDOUT, "partition %s\n", pname);
4963 fprintf(STDOUT, "\n");
4965 } else if (as->parms[1].items) {
4966 MapPartIdIntoName(apart, pname);
4968 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4973 if (arrayEntries.nbulkentries_val)
4974 free(arrayEntries.nbulkentries_val);
4979 PrintInt64Size(afs_uint64 in)
4981 register afs_uint32 hi, lo;
4982 register char * units;
4983 static char output[16];
4985 SplitInt64(in,hi,lo);
4989 } else if (!(hi & 0xFFFFFC00)) {
4991 lo = (hi << 22) | (lo >> 10);
4992 } else if (!(hi & 0xFFF00000)) {
4994 lo = (hi << 12) | (lo >> 20);
4995 } else if (!(hi & 0xC0000000)) {
4997 lo = (hi << 2) | (lo >> 30);
5002 sprintf(output,"%u %s", lo, units);
5008 register struct cmd_syndesc *as;
5011 afs_int32 aserver, code;
5013 struct diskPartition partition;
5014 struct partList dummyPartList;
5016 int printSummary=0, sumPartitions=0;
5017 afs_uint64 sumFree, sumStorage, tmp;
5020 ZeroInt64(sumStorage);
5022 aserver = GetServer(as->parms[0].items->data);
5024 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5025 as->parms[0].items->data);
5028 if (as->parms[1].items) {
5029 apart = volutil_GetPartitionID(as->parms[1].items->data);
5031 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5032 as->parms[1].items->data);
5035 dummyPartList.partId[0] = apart;
5036 dummyPartList.partFlags[0] = PARTVALID;
5039 if (as->parms[2].items) {
5043 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5045 PrintError("", code);
5048 "vos : partition %s does not exist on the server\n",
5049 as->parms[1].items->data);
5053 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5055 PrintDiagnostics("listpart", code);
5059 for (i = 0; i < cnt; i++) {
5060 if (dummyPartList.partFlags[i] & PARTVALID) {
5061 MapPartIdIntoName(dummyPartList.partId[i], pname);
5062 code = UV_PartitionInfo(aserver, pname, &partition);
5064 fprintf(STDERR, "Could not get information on partition %s\n",
5066 PrintError("", code);
5070 "Free space on partition %s: %d K blocks out of total %d\n",
5071 pname, partition.free, partition.minFree);
5073 FillInt64(tmp,0,partition.free);
5074 AddUInt64(sumFree,tmp,&sumFree);
5075 FillInt64(tmp,0,partition.minFree);
5076 AddUInt64(sumStorage,tmp,&sumStorage);
5081 "Summary: %s free out of ",
5082 PrintInt64Size(sumFree));
5084 "%s on %d partitions\n",
5085 PrintInt64Size(sumStorage),
5093 register struct cmd_syndesc *as;
5096 afs_int32 ip1, ip2, vcode;
5099 ip1 = GetServer(as->parms[0].items->data);
5101 fprintf(STDERR, "vos: invalid host address\n");
5105 if ((as->parms[1].items && as->parms[2].items)
5106 || (!as->parms[1].items && !as->parms[2].items)) {
5108 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5112 if (as->parms[1].items) {
5113 ip2 = GetServer(as->parms[1].items->data);
5115 fprintf(STDERR, "vos: invalid host address\n");
5119 /* Play a trick here. If we are removing an address, ip1 will be -1
5120 * and ip2 will be the original address. This switch prevents an
5121 * older revision vlserver from removing the IP address.
5128 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
5131 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5132 as->parms[0].items->data);
5133 if (vcode == VL_NOENT) {
5135 "vlserver does not support the remove flag or ");
5138 fprintf(STDERR, "Could not change server %s to server %s\n",
5139 as->parms[0].items->data, as->parms[1].items->data);
5141 PrintError("", vcode);
5146 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5147 as->parms[0].items->data);
5149 fprintf(STDOUT, "Changed server %s to server %s\n",
5150 as->parms[0].items->data, as->parms[1].items->data);
5156 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
5157 int print, int noresolve)
5161 struct VLCallBack vlcb;
5164 ListAddrByAttributes m_attrs;
5165 afs_int32 m_nentries, *m_addrp;
5166 afs_int32 base, index;
5170 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5171 printf("UUID: %s\n", buf);
5174 /* print out the list of all the server */
5175 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5176 for (i = 0; i < nentries; i++, addrp++) {
5177 /* If it is a multihomed address, then we will need to
5178 * get the addresses for this multihomed server from
5179 * the vlserver and print them.
5181 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5182 /* Get the list of multihomed fileservers */
5183 base = (*addrp >> 16) & 0xff;
5184 index = (*addrp) & 0xffff;
5186 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5187 && (index <= VL_MHSRV_PERBLK)) {
5188 m_attrs.Mask = VLADDR_INDEX;
5189 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5191 m_addrs.bulkaddrs_val = 0;
5192 m_addrs.bulkaddrs_len = 0;
5194 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, &m_uuid,
5195 &vlcb, &m_nentries, &m_addrs);
5198 "vos: could not list the multi-homed server addresses\n");
5199 PrintError("", vcode);
5202 /* Print the list */
5203 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5204 for (j = 0; j < m_nentries; j++, m_addrp++) {
5205 *m_addrp = htonl(*m_addrp);
5208 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5210 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5214 printf("<unknown>\n");
5223 /* Otherwise, it is a non-multihomed entry and contains
5224 * the IP address of the server - print it.
5226 *addrp = htonl(*addrp);
5229 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5231 printf("%s\n", hostutil_GetNameByINet(*addrp));
5243 register struct cmd_syndesc *as;
5246 afs_int32 i, noresolve = 0, printuuid = 0;
5247 struct VLCallBack vlcb;
5250 ListAddrByAttributes m_attrs;
5251 afsUUID m_uuid, askuuid;
5252 afs_int32 m_nentries;
5254 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5255 m_attrs.Mask = VLADDR_INDEX;
5257 memset(&m_addrs, 0, sizeof(bulkaddrs));
5258 memset(&askuuid, 0, sizeof(afsUUID));
5259 if (as->parms[0].items) {
5261 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5262 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5263 as->parms[0].items->data);
5266 m_attrs.Mask = VLADDR_UUID;
5267 m_attrs.uuid = askuuid;
5269 if (as->parms[1].items) {
5273 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5275 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5276 as->parms[1].items->data);
5279 memcpy(&saddr, he->h_addr, 4);
5280 m_attrs.Mask = VLADDR_IPADDR;
5281 m_attrs.ipaddr = ntohl(saddr);
5283 if (as->parms[2].items) {
5286 if (as->parms[3].items) {
5290 m_addrs.bulkaddrs_val = 0;
5291 m_addrs.bulkaddrs_len = 0;
5294 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries,
5297 fprintf(STDERR, "vos: could not list the server addresses\n");
5298 PrintError("", vcode);
5303 m_addrs.bulkaddrs_val = 0;
5304 m_addrs.bulkaddrs_len = 0;
5310 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5311 &vlcb, &m_nentries, &m_addrs);
5313 if (vcode == VL_NOENT) {
5314 if (m_attrs.Mask == VLADDR_UUID) {
5315 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5316 as->parms[0].items->data);
5318 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5319 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5320 as->parms[1].items->data, m_attrs.ipaddr);
5329 if (vcode == VL_INDEXERANGE) {
5334 fprintf(STDERR, "vos: could not list the server addresses\n");
5335 PrintError("", vcode);
5339 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
5342 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5351 register struct cmd_syndesc *as;
5354 afs_int32 avolid, vcode, err;
5356 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5359 PrintError("", err);
5361 fprintf(STDERR, "vos: can't find volume '%s'\n",
5362 as->parms[0].items->data);
5365 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5367 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5368 as->parms[0].items->data);
5369 PrintError("", vcode);
5372 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5373 as->parms[0].items->data);
5379 register struct cmd_syndesc *as;
5382 afs_int32 partition = -1;
5383 afs_int32 server, volid, code, i, same;
5384 struct nvldbentry entry, storeEntry;
5387 afs_int32 rwserver = 0;
5388 afs_int32 rwpartition;
5390 afs_int32 roserver = 0;
5391 afs_int32 ropartition;
5393 struct rx_connection *aconn;
5396 server = GetServer(as->parms[0].items->data);
5398 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5399 as->parms[0].items->data);
5402 partition = volutil_GetPartitionID(as->parms[1].items->data);
5403 if (partition < 0) {
5404 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5405 as->parms[1].items->data);
5408 if (!IsPartValid(partition, server, &code)) {
5410 PrintError("", code);
5413 "vos : partition %s does not exist on the server\n",
5414 as->parms[1].items->data);
5417 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5420 PrintError("", code);
5422 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5423 as->parms[0].items->data);
5426 if (as->parms[3].items)
5429 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5432 "Could not fetch the entry for volume %lu from VLDB\n",
5433 (unsigned long)volid);
5434 PrintError("convertROtoRW", code);
5438 /* use RO volid even if user specified RW or BK volid */
5440 if (volid != entry.volumeId[ROVOL])
5441 volid = entry.volumeId[ROVOL];
5443 MapHostToNetwork(&entry);
5444 for (i = 0; i < entry.nServers; i++) {
5445 if (entry.serverFlags[i] & ITSRWVOL) {
5447 rwserver = entry.serverNumber[i];
5448 rwpartition = entry.serverPartition[i];
5450 if (entry.serverFlags[i] & ITSROVOL) {
5451 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5454 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5460 roserver = entry.serverNumber[i];
5461 ropartition = entry.serverPartition[i];
5467 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5469 if (ropartition != partition) {
5471 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5472 ropartition, partition);
5477 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5478 hostutil_GetNameByINet(rwserver),
5479 volutil_PartitionName(rwpartition));
5481 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5483 while (!(dc == EOF || dc == '\n'))
5484 dc = getchar(); /* goto end of line */
5485 if ((c != 'y') && (c != 'Y')) {
5486 fprintf(STDERR, "aborted.\n");
5493 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5495 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5496 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5499 "Converting RO volume %lu to RW volume failed with code %d\n",
5500 (unsigned long)volid, code);
5501 PrintError("convertROtoRW ", code);
5504 entry.serverFlags[roindex] = ITSRWVOL;
5505 entry.flags |= RW_EXISTS;
5506 entry.flags &= ~BACK_EXISTS;
5509 if (rwindex != entry.nServers) {
5510 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5511 entry.serverPartition[rwindex] =
5512 entry.serverPartition[entry.nServers];
5513 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5514 entry.serverNumber[entry.nServers] = 0;
5515 entry.serverPartition[entry.nServers] = 0;
5516 entry.serverFlags[entry.nServers] = 0;
5519 entry.flags &= ~RO_EXISTS;
5520 for (i = 0; i < entry.nServers; i++) {
5521 if (entry.serverFlags[i] & ITSROVOL) {
5522 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5523 entry.flags |= RO_EXISTS;
5526 MapNetworkToHost(&entry, &storeEntry);
5528 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5529 (LOCKREL_OPCODE | LOCKREL_AFSID |
5530 LOCKREL_TIMESTAMP));
5533 "Warning: volume converted, but vldb update failed with code %d!\n",
5536 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5538 PrintDiagnostics("unlock", vcode);
5545 register struct cmd_syndesc *as;
5547 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
5548 struct nvldbentry entry;
5549 volintSize vol_size;
5551 rx_SetRxDeadTime(60 * 10);
5552 for (i = 0; i < MAXSERVERS; i++) {
5553 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5556 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5557 if (rxConn->service)
5558 rxConn->service->connDeadTime = rx_connDeadTime;
5561 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5564 PrintError("", err);
5566 fprintf(STDERR, "vos: can't find volume '%s'\n",
5567 as->parms[0].items->data);
5571 if (as->parms[1].items || as->parms[2].items) {
5572 if (!as->parms[1].items || !as->parms[2].items) {
5574 "Must specify both -server and -partition options\n");
5577 aserver = GetServer(as->parms[2].items->data);
5579 fprintf(STDERR, "Invalid server name\n");
5582 apart = volutil_GetPartitionID(as->parms[1].items->data);
5584 fprintf(STDERR, "Invalid partition name\n");
5588 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5595 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5596 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5598 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5599 as->parms[4].items->data, code);
5604 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5606 if (as->parms[3].items) { /* do the dump estimate */
5607 #ifdef AFS_64BIT_ENV
5608 vol_size.dump_size = 0;
5610 FillInt64(vol_size.dump_size,0, 1);
5612 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5614 PrintDiagnostics("size", code);
5617 /* presumably the size info is now gathered in pntr */
5618 /* now we display it */
5620 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5628 PrintDiagnostics(astring, acode)
5632 if (acode == EACCES) {
5634 "You are not authorized to perform the 'vos %s' command (%d)\n",
5637 fprintf(STDERR, "Error in vos %s command.\n", astring);
5638 PrintError("", acode);
5645 MyBeforeProc(as, arock)
5646 struct cmd_syndesc *as;
5649 register char *tcell;
5650 register afs_int32 code;
5651 register afs_int32 sauth;
5653 /* Initialize the ubik_client connection */
5654 rx_SetRxDeadTime(90);
5655 cstruct = (struct ubik_client *)0;
5659 if (as->parms[12].items) /* if -cell specified */
5660 tcell = as->parms[12].items->data;
5661 if (as->parms[14].items) /* -serverauth specified */
5663 if (as->parms[16].items) /* -crypt specified */
5666 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5667 &cstruct, UV_SetSecurity))) {
5668 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5669 (unsigned long)code);
5673 if (as->parms[15].items) /* -verbose flag set */
5683 /* this sucks but it works for now.
5688 #include "AFS_component_version_number.c"
5694 register afs_int32 code;
5696 register struct cmd_syndesc *ts;
5698 #ifdef AFS_AIX32_ENV
5700 * The following signal action for AIX is necessary so that in case of a
5701 * crash (i.e. core is generated) we can include the user's data section
5702 * in the core dump. Unfortunately, by default, only a partial core is
5703 * generated which, in many cases, isn't too useful.
5705 struct sigaction nsa;
5707 sigemptyset(&nsa.sa_mask);
5708 nsa.sa_handler = SIG_DFL;
5709 nsa.sa_flags = SA_FULLDUMP;
5710 sigaction(SIGSEGV, &nsa, NULL);
5713 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5715 cmd_SetBeforeProc(MyBeforeProc, NULL);
5717 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
5718 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5719 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5720 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5721 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5722 "initial quota (KB)");
5724 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5728 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
5729 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5730 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5731 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5735 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
5736 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5737 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5738 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5739 "partition name on source");
5740 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5741 "machine name on destination");
5742 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5743 "partition name on destination");
5744 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5745 "copy live volume without cloning");
5748 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
5749 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5750 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5751 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5752 "partition name on source");
5753 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5754 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5755 "machine name on destination");
5756 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5757 "partition name on destination");
5758 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5759 "leave new volume offline");
5760 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5761 "make new volume read-only");
5762 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5763 "copy live volume without cloning");
5766 ts = cmd_CreateSyntax("shadow", ShadowVolume, 0,
5767 "make or update a shadow volume");
5768 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5769 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5770 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5771 "partition name on source");
5772 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5773 "machine name on destination");
5774 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5775 "partition name on destination");
5776 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5777 "volume name on destination");
5778 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5779 "volume ID on destination");
5780 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5781 "leave shadow volume offline");
5782 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5783 "make shadow volume read-only");
5784 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5785 "copy live volume without cloning");
5786 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5787 "do incremental update if target exists");
5790 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
5791 "make backup of a volume");
5792 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5795 ts = cmd_CreateSyntax("clone", CloneVolume, 0,
5796 "make clone of a volume");
5797 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5798 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5799 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5800 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5801 "volume name on destination");
5802 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5803 "volume ID on destination");
5804 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5805 "leave clone volume offline");
5806 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5807 "make clone volume read-only, not readwrite");
5810 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
5811 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5812 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5813 "force a complete release");
5816 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
5817 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5818 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5819 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5820 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5821 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5822 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5823 "dump a clone of the volume");
5824 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5825 "omit unchanged directories from an incremental dump");
5828 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
5829 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5830 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5831 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5832 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5833 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5834 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5835 "abort | full | incremental");
5836 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5837 "leave restored volume offline");
5838 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5839 "make restored volume read-only");
5840 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
5841 "dump | keep | new");
5842 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
5843 "dump | keep | new");
5846 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
5847 "release lock on VLDB entry for a volume");
5848 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5851 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
5852 "change an RW volume's location in the VLDB");
5853 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5854 "machine name for new location");
5855 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5856 "partition name for new location");
5857 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5860 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5861 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5862 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5863 "partition name for new site");
5864 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5867 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5868 "remove a replication site");
5869 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5870 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5871 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5874 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5875 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5878 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5879 "list volumes on server (bypass VLDB)");
5880 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5881 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5882 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5883 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5884 "list all normal volume fields");
5885 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5886 "generate minimal information");
5887 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5888 "list extended volume fields");
5889 #ifdef FULL_LISTVOL_SWITCH
5890 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5891 "machine readable format");
5892 #endif /* FULL_LISTVOL_SWITCH */
5895 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5896 "synchronize VLDB with server");
5897 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5898 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5899 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5902 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5903 "synchronize server with VLDB");
5904 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5905 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5908 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5909 "everything about the volume");
5910 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5911 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5912 "list extended volume fields");
5913 #ifdef FULL_LISTVOL_SWITCH
5914 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5915 "machine readable format");
5916 #endif /* FULL_LISTVOL_SWITCH */
5918 cmd_CreateAlias(ts, "volinfo");
5920 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5921 "change volume info fields");
5922 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5923 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5924 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5925 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
5928 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5929 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5930 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5931 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5932 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5933 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5936 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5937 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5938 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5939 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5942 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5943 "delete the volume, don't bother with VLDB");
5944 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5945 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5946 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5947 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5948 "force deletion of bad volumes");
5949 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5950 "also delete backup volume if one is found");
5953 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5954 "report on volser status");
5955 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5958 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5959 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5960 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5963 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5964 "list volumes in the VLDB");
5965 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5966 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5967 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5968 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5969 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5970 "generate minimal information");
5971 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5972 "do not alphabetically sort the volume names");
5975 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5976 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5977 "common prefix on volume(s)");
5978 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5979 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5980 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5981 "exclude common prefix volumes");
5982 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5983 "negative prefix on volume(s)");
5984 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5987 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5988 "delete VLDB entry for a volume");
5989 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5990 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5991 "prefix of the volume whose VLDB entry is to be deleted");
5992 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5993 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5994 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
5998 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
5999 "list partition information");
6000 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6001 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6002 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6003 "print storage summary");
6006 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
6007 "unlock all the locked entries in the VLDB");
6008 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6009 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6012 ts = cmd_CreateSyntax("lock", LockEntry, 0,
6013 "lock VLDB entry for a volume");
6014 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6017 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
6018 "change the IP address of a file server");
6019 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6020 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6021 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6022 "remove the IP address from the VLDB");
6025 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
6026 "list the IP address of all file servers registered in the VLDB");
6027 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6028 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6029 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
6030 "don't resolve addresses");
6031 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6032 "print uuid of hosts");
6035 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
6036 "convert a RO volume into a RW volume (after loss of old RW volume)");
6037 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6038 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6039 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6040 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6043 ts = cmd_CreateSyntax("size", Sizes, 0,
6044 "obtain various sizes of the volume.");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6046 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6047 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6048 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6049 "Obtain the size of the dump");
6050 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6053 code = cmd_Dispatch(argc, argv);
6055 /* Shut down the ubik_client and rx connections */
6057 (void)ubik_ClientDestroy(cstruct);
6063 exit((code ? -1 : 0));