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>
25 #include <netinet/in.h>
29 #include <sys/statfs.h>
45 #include <rx/rx_globals.h>
47 #include <afs/vlserver.h>
49 #include <afs/cellconfig.h>
51 #include <afs/afsutil.h>
53 #include <afs/afsint.h>
63 #include "volser_prototypes.h"
65 #ifdef HAVE_POSIX_REGEX
80 struct hostent *hostutil_GetHostByName(register char *ahost);
82 #define COMMONPARMS cmd_Seek(ts, 12);\
83 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
84 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
85 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
86 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
87 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
89 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
93 struct rx_connection *tconn;
95 extern struct ubik_client *cstruct;
97 extern struct rx_connection *UV_Bind();
98 extern int UV_SetSecurity();
99 extern int UV_SetVolumeInfo();
100 extern int vsu_SetCrypt();
102 extern VL_ReleaseLock();
103 extern VL_DeleteEntry();
104 extern VL_ListEntry();
105 extern VL_GetAddrs();
106 extern VL_GetAddrsU();
107 extern VL_ChangeAddr();
109 extern int vsu_ExtractName();
111 extern void EnumerateEntry();
112 extern void SubEnumerateEntry();
115 static struct tqHead busyHead, notokHead;
118 qInit(struct tqHead *ahead)
120 memset((char *)ahead, 0, sizeof(struct tqHead));
126 qPut(struct tqHead *ahead, afs_int32 volid)
130 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
131 elem->next = ahead->next;
139 qGet(struct tqHead *ahead, afs_int32 *volid)
143 if (ahead->count <= 0)
145 *volid = ahead->next->volid;
147 ahead->next = tmp->next;
153 /* returns 1 if <filename> exists else 0 */
155 FileExists(char *filename)
161 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
165 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
173 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
175 VolNameOK(char *name)
180 total = strlen(name);
181 if (!strcmp(&name[total - 9], ".readonly")) {
183 } else if (!strcmp(&name[total - 7], ".backup")) {
190 /* return 1 if name is a number else 0 */
192 IsNumeric(char *name)
200 for (i = 0; i < len; i++) {
201 if (*ptr < '0' || *ptr > '9') {
213 * Parse a server name/address and return the address in HOST BYTE order
216 GetServer(char *aname)
218 register struct hostent *th;
221 register afs_int32 code;
222 char hostname[MAXHOSTCHARS];
224 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
226 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
227 addr = ntohl(addr); /* convert to host order */
229 th = gethostbyname(aname);
232 memcpy(&addr, th->h_addr, sizeof(addr));
235 if (addr == htonl(0x7f000001)) { /* local host */
236 code = gethostname(hostname, MAXHOSTCHARS);
239 th = gethostbyname(hostname); /* returns host byte order */
242 memcpy(&addr, th->h_addr, sizeof(addr));
249 GetVolumeType(char *aname)
252 if (!strcmp(aname, "ro"))
254 else if (!strcmp(aname, "rw"))
256 else if (!strcmp(aname, "bk"))
263 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
265 struct partList dummyPartList;
271 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
274 for (i = 0; i < cnt; i++) {
275 if (dummyPartList.partFlags[i] & PARTVALID)
276 if (dummyPartList.partId[i] == partId)
284 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
285 * associated with <call> */
287 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
289 char *buffer = (char *)0;
294 buffer = (char *)malloc(blksize);
296 fprintf(STDERR, "malloc failed\n");
300 while (!error && !done) {
301 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
304 FD_SET((int)(ufd->handle), &in);
305 /* don't timeout if read blocks */
306 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
308 error = USD_READ(ufd, buffer, blksize, &nbytes);
310 fprintf(STDERR, "File system read failed\n");
317 if (rx_Write(call, buffer, nbytes) != nbytes) {
327 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
328 * writes it out to the volume. */
330 WriteData(struct rx_call *call, char *rock)
335 afs_int32 error, code;
341 if (!filename || !*filename) {
342 usd_StandardInput(&ufd);
346 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
349 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
352 fprintf(STDERR, "Could not access file '%s'\n", filename);
357 code = SendFile(ufd, call, blksize);
364 code = USD_CLOSE(ufd);
366 fprintf(STDERR, "Could not close dump file %s\n",
367 (filename && *filename) ? filename : "STDOUT");
375 /* Receive data from <call> stream into file associated
376 * with <fd> <blksize>
379 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
383 afs_uint32 bytesleft, w;
386 buffer = (char *)malloc(blksize);
388 fprintf(STDERR, "memory allocation failed\n");
392 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
393 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
394 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
397 FD_SET((int)(ufd->handle), &out);
398 /* don't timeout if write blocks */
399 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
402 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
404 fprintf(STDERR, "File system write failed\n");
417 DumpFunction(struct rx_call *call, char *filename)
419 usd_handle_t ufd; /* default is to stdout */
420 afs_int32 error = 0, code;
425 /* Open the output file */
426 if (!filename || !*filename) {
427 usd_StandardOutput(&ufd);
432 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
436 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
439 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
442 fprintf(STDERR, "Could not create file '%s'\n", filename);
443 ERROR_EXIT(VOLSERBADOP);
447 code = ReceiveFile(ufd, call, blksize);
452 /* Close the output file */
454 code = USD_CLOSE(ufd);
456 fprintf(STDERR, "Could not close dump file %s\n",
457 (filename && *filename) ? filename : "STDIN");
467 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
470 afs_int32 server, part;
471 int *totalOK, *totalNotOK, *totalBusy;
472 int fast, longlist, disp;
477 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
478 } else if (longlist) {
479 if (pntr->status == VOK) {
480 fprintf(STDOUT, "%-32s ", pntr->name);
481 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
483 fprintf(STDOUT, "RW ");
485 fprintf(STDOUT, "RO ");
487 fprintf(STDOUT, "BK ");
488 fprintf(STDOUT, "%10d K ", pntr->size);
489 if (pntr->inUse == 1) {
490 fprintf(STDOUT, "On-line");
493 fprintf(STDOUT, "Off-line");
496 if (pntr->needsSalvaged == 1)
497 fprintf(STDOUT, "**needs salvage**");
498 fprintf(STDOUT, "\n");
499 MapPartIdIntoName(part, pname);
500 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
502 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
503 (unsigned long)pntr->parentID,
504 (unsigned long)pntr->cloneID,
505 (unsigned long)pntr->backupID);
506 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
507 fprintf(STDOUT, " Creation %s",
508 ctime((time_t *) & pntr->creationDate));
509 #ifdef FULL_LISTVOL_SWITCH
510 fprintf(STDOUT, " Copy %s",
511 ctime((time_t *) & pntr->copyDate));
512 if (!pntr->backupDate)
513 fprintf(STDOUT, " Backup Never\n");
515 fprintf(STDOUT, " Backup %s",
516 ctime((time_t *) & pntr->backupDate));
517 if (pntr->accessDate)
518 fprintf(STDOUT, " Last Access %s",
519 ctime((time_t *) & pntr->accessDate));
521 if (pntr->updateDate < pntr->creationDate)
522 fprintf(STDOUT, " Last Update %s",
523 ctime((time_t *) & pntr->creationDate));
525 fprintf(STDOUT, " Last Update %s",
526 ctime((time_t *) & pntr->updateDate));
528 " %d accesses in the past day (i.e., vnode references)\n",
530 } else if (pntr->status == VBUSY) {
532 qPut(&busyHead, pntr->volid);
534 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
535 (unsigned long)pntr->volid);
538 qPut(¬okHead, pntr->volid);
540 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
541 (unsigned long)pntr->volid);
543 fprintf(STDOUT, "\n");
544 } else { /* default listing */
545 if (pntr->status == VOK) {
546 fprintf(STDOUT, "%-32s ", pntr->name);
547 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
549 fprintf(STDOUT, "RW ");
551 fprintf(STDOUT, "RO ");
553 fprintf(STDOUT, "BK ");
554 fprintf(STDOUT, "%10d K ", pntr->size);
555 if (pntr->inUse == 1) {
556 fprintf(STDOUT, "On-line");
559 fprintf(STDOUT, "Off-line");
562 if (pntr->needsSalvaged == 1)
563 fprintf(STDOUT, "**needs salvage**");
564 fprintf(STDOUT, "\n");
565 } else if (pntr->status == VBUSY) {
567 qPut(&busyHead, pntr->volid);
569 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
570 (unsigned long)pntr->volid);
573 qPut(¬okHead, pntr->volid);
575 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
576 (unsigned long)pntr->volid);
581 /*------------------------------------------------------------------------
582 * PRIVATE XDisplayFormat
585 * Display the contents of one extended volume info structure.
588 * a_xInfoP : Ptr to extended volume info struct to print.
589 * a_servID : Server ID to print.
590 * a_partID : Partition ID to print.
591 * a_totalOKP : Ptr to total-OK counter.
592 * a_totalNotOKP : Ptr to total-screwed counter.
593 * a_totalBusyP : Ptr to total-busy counter.
594 * a_fast : Fast listing?
595 * a_int32 : Int32 listing?
596 * a_showProblems : Show volume problems?
602 * Nothing interesting.
606 *------------------------------------------------------------------------*/
609 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
610 a_totalBusyP, a_fast, a_int32, a_showProblems)
611 volintXInfo *a_xInfoP;
621 { /*XDisplayFormat */
629 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
630 } else if (a_int32) {
632 * Fully-detailed listing.
634 if (a_xInfoP->status == VOK) {
636 * Volume's status is OK - all the fields are valid.
638 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
639 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
640 if (a_xInfoP->type == 0)
641 fprintf(STDOUT, "RW ");
642 if (a_xInfoP->type == 1)
643 fprintf(STDOUT, "RO ");
644 if (a_xInfoP->type == 2)
645 fprintf(STDOUT, "BK ");
646 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
647 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
648 if (a_xInfoP->inUse == 1) {
649 fprintf(STDOUT, "On-line");
652 fprintf(STDOUT, "Off-line");
655 fprintf(STDOUT, "\n");
656 MapPartIdIntoName(a_partID, pname);
657 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
659 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
660 (unsigned long)a_xInfoP->parentID,
661 (unsigned long)a_xInfoP->cloneID,
662 (unsigned long)a_xInfoP->backupID);
663 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
664 fprintf(STDOUT, " Creation %s",
665 ctime((time_t *) & a_xInfoP->creationDate));
666 #ifdef FULL_LISTVOL_SWITCH
667 fprintf(STDOUT, " Copy %s",
668 ctime((time_t *) & a_xInfoP->copyDate));
669 if (!a_xInfoP->backupDate)
670 fprintf(STDOUT, " Backup Never\n");
672 fprintf(STDOUT, " Backup %s",
673 ctime((time_t *) & a_xInfoP->backupDate));
674 if (a_xInfoP->accessDate)
675 fprintf(STDOUT, " Last Access %s",
676 ctime((time_t *) & a_xInfoP->accessDate));
678 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
679 fprintf(STDOUT, " Last Update %s",
680 ctime((time_t *) & a_xInfoP->creationDate));
682 fprintf(STDOUT, " Last Update %s",
683 ctime((time_t *) & a_xInfoP->updateDate));
685 " %d accesses in the past day (i.e., vnode references)\n",
689 * Print all the read/write and authorship stats.
691 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
693 " |-------------------------------------------|\n");
695 " | Same Network | Diff Network |\n");
697 " |----------|----------|----------|----------|\n");
699 " | Total | Auth | Total | Auth |\n");
701 " |----------|----------|----------|----------|\n");
702 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
703 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
704 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
705 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
706 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
707 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
708 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
709 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
710 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
711 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
713 " |-------------------------------------------|\n\n");
716 " Writes Affecting Authorship\n");
718 " |-------------------------------------------|\n");
720 " | File Authorship | Directory Authorship|\n");
722 " |----------|----------|----------|----------|\n");
724 " | Same | Diff | Same | Diff |\n");
726 " |----------|----------|----------|----------|\n");
727 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
728 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
729 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
730 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
731 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
732 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
733 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
734 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
735 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
736 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
737 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
738 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
739 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
740 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
741 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
742 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
743 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
744 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
745 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
746 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
747 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
748 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
749 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
750 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
751 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
752 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
753 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
754 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
755 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
756 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
758 " |-------------------------------------------|\n");
759 } /*Volume status OK */
760 else if (a_xInfoP->status == VBUSY) {
762 qPut(&busyHead, a_xInfoP->volid);
764 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
765 (unsigned long)a_xInfoP->volid);
769 qPut(¬okHead, a_xInfoP->volid);
771 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
772 (unsigned long)a_xInfoP->volid);
773 } /*Screwed volume */
774 fprintf(STDOUT, "\n");
780 if (a_xInfoP->status == VOK) {
781 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
782 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
783 if (a_xInfoP->type == 0)
784 fprintf(STDOUT, "RW ");
785 if (a_xInfoP->type == 1)
786 fprintf(STDOUT, "RO ");
787 if (a_xInfoP->type == 2)
788 fprintf(STDOUT, "BK ");
789 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
790 if (a_xInfoP->inUse == 1) {
791 fprintf(STDOUT, "On-line");
794 fprintf(STDOUT, "Off-line");
797 fprintf(STDOUT, "\n");
799 else if (a_xInfoP->status == VBUSY) {
801 qPut(&busyHead, a_xInfoP->volid);
803 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
804 (unsigned long)a_xInfoP->volid);
808 qPut(¬okHead, a_xInfoP->volid);
810 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
811 (unsigned long)a_xInfoP->volid);
812 } /*Screwed volume */
813 } /*Default listing */
814 } /*XDisplayFormat */
816 #ifdef FULL_LISTVOL_SWITCH
818 DisplayFormat2(server, partition, pntr)
819 long server, partition;
822 static long server_cache = -1, partition_cache = -1;
823 static char hostname[256], address[32], pname[16];
825 if (server != server_cache) {
829 strcpy(hostname, hostutil_GetNameByINet(server));
830 strcpy(address, inet_ntoa(s));
831 server_cache = server;
833 if (partition != partition_cache) {
834 MapPartIdIntoName(partition, pname);
835 partition_cache = partition;
837 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
838 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
839 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
840 fprintf(STDOUT, "part\t\t%s\n", pname);
841 switch (pntr->status) {
843 fprintf(STDOUT, "status\t\tOK\n");
846 fprintf(STDOUT, "status\t\tBUSY\n");
849 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
852 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
853 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
854 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
855 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
856 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
857 /* 0xD3 is from afs/volume.h since I had trouble including the file */
858 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
859 switch (pntr->type) {
861 fprintf(STDOUT, "type\t\tRW\n");
864 fprintf(STDOUT, "type\t\tRO\n");
867 fprintf(STDOUT, "type\t\tBK\n");
870 fprintf(STDOUT, "type\t\t?\n");
873 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
874 ctime(&pntr->creationDate));
875 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
876 ctime(&pntr->accessDate));
877 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
878 ctime(&pntr->updateDate));
879 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
880 ctime(&pntr->backupDate));
881 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
882 ctime(&pntr->copyDate));
883 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
884 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
885 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
886 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
887 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
888 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
889 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
890 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
891 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
896 DisplayVolumes2(server, partition, pntr, count)
898 long server, partition, count;
902 for (i = 0; i < count; i++) {
903 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
904 DisplayFormat2(server, partition, pntr);
905 fprintf(STDOUT, "END_OF_ENTRY\n\n");
910 #endif /* FULL_LISTVOL_SWITCH */
913 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
914 afs_int32 server, part;
916 afs_int32 count, longlist, fast;
919 int totalOK, totalNotOK, totalBusy, i;
927 for (i = 0; i < count; i++) {
928 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
933 while (busyHead.count) {
934 qGet(&busyHead, &volid);
935 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
936 (unsigned long)volid);
940 while (notokHead.count) {
941 qGet(¬okHead, &volid);
942 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
943 (unsigned long)volid);
947 fprintf(STDOUT, "\n");
950 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
951 totalOK, totalNotOK, totalBusy);
956 /*------------------------------------------------------------------------
957 * PRIVATE XDisplayVolumes
960 * Display extended volume information.
963 * a_servID : Pointer to the Rx call we're performing.
964 * a_partID : Partition for which we want the extended list.
965 * a_xInfoP : Ptr to extended volume info.
966 * a_count : Number of volume records contained above.
967 * a_int32 : Int32 listing generated?
968 * a_fast : Fast listing generated?
969 * a_quiet : Quiet listing generated?
975 * Nothing interesting.
979 *------------------------------------------------------------------------*/
982 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
986 volintXInfo *a_xInfoP;
992 { /*XDisplayVolumes */
994 int totalOK; /*Total OK volumes */
995 int totalNotOK; /*Total screwed volumes */
996 int totalBusy; /*Total busy volumes */
997 int i; /*Loop variable */
998 afs_int32 volid; /*Current volume ID */
1001 * Initialize counters and (global!!) queues.
1010 * Display each volume in the list.
1012 for (i = 0; i < a_count; i++) {
1013 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1014 &totalBusy, a_fast, a_int32, 0);
1019 * If any volumes were found to be busy or screwed, display them.
1022 while (busyHead.count) {
1023 qGet(&busyHead, &volid);
1024 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1025 (unsigned long)volid);
1029 while (notokHead.count) {
1030 qGet(¬okHead, &volid);
1031 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1032 (unsigned long)volid);
1037 fprintf(STDOUT, "\n");
1040 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1041 totalOK, totalNotOK, totalBusy);
1045 } /*XDisplayVolumes */
1047 /* set <server> and <part> to the correct values depending on
1048 * <voltype> and <entry> */
1050 GetServerAndPart(entry, voltype, server, part, previdx)
1051 struct nvldbentry *entry;
1052 afs_int32 *server, *part;
1056 int i, istart, vtype;
1061 /* Doesn't check for non-existance of backup volume */
1062 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1064 istart = 0; /* seach the entire entry */
1067 /* Seach from beginning of entry or pick up where we left off */
1068 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1071 for (i = istart; i < entry->nServers; i++) {
1072 if (entry->serverFlags[i] & vtype) {
1073 *server = entry->serverNumber[i];
1074 *part = entry->serverPartition[i];
1080 /* Didn't find any, return -1 */
1086 PostVolumeStats(entry)
1087 struct nvldbentry *entry;
1089 SubEnumerateEntry(entry);
1090 /* Check for VLOP_ALLOPERS */
1091 if (entry->flags & VLOP_ALLOPERS)
1092 fprintf(STDOUT, " Volume is currently LOCKED \n");
1096 /*------------------------------------------------------------------------
1097 * PRIVATE XVolumeStats
1100 * Display extended volume information.
1103 * a_xInfoP : Ptr to extended volume info.
1104 * a_entryP : Ptr to the volume's VLDB entry.
1105 * a_srvID : Server ID.
1106 * a_partID : Partition ID.
1107 * a_volType : Type of volume to print.
1113 * Nothing interesting.
1117 *------------------------------------------------------------------------*/
1120 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1121 volintXInfo *a_xInfoP;
1122 struct nvldbentry *a_entryP;
1129 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1131 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1132 a_srvID, /*Server ID to print */
1133 a_partID, /*Partition ID to print */
1134 &totalOK, /*Ptr to total-OK counter */
1135 &totalNotOK, /*Ptr to total-screwed counter */
1136 &totalBusy, /*Ptr to total-busy counter */
1137 0, /*Don't do a fast listing */
1138 1, /*Do a long listing */
1139 1); /*Show volume problems */
1145 VolumeStats(pntr, entry, server, part, voltype)
1147 struct nvldbentry *entry;
1149 afs_int32 server, part;
1151 int totalOK, totalNotOK, totalBusy;
1153 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1158 /* command to forcibly remove a volume */
1161 register struct cmd_syndesc *as;
1163 register afs_int32 code;
1164 afs_int32 volID, err;
1169 server = GetServer(tp = as->parms[0].items->data);
1171 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1175 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1177 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1181 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1184 PrintError("", err);
1187 "vos: could not parse '%s' as a numeric volume ID", tp);
1192 "vos: forcibly removing all traces of volume %d, please wait...",
1195 code = UV_NukeVolume(server, partID, volID);
1197 fprintf(STDOUT, "done.\n");
1199 fprintf(STDOUT, "failed with code %d.\n", code);
1204 /*------------------------------------------------------------------------
1205 * PRIVATE ExamineVolume
1208 * Routine used to examine a single volume, contacting the VLDB as
1209 * well as the Volume Server.
1212 * as : Ptr to parsed command line arguments.
1215 * 0 for a successful operation,
1216 * Otherwise, one of the ubik or VolServer error values.
1219 * Nothing interesting.
1223 *------------------------------------------------------------------------
1227 register struct cmd_syndesc *as;
1229 struct nvldbentry entry;
1230 afs_int32 vcode = 0;
1231 volintInfo *pntr = (volintInfo *) 0;
1232 volintXInfo *xInfoP = (volintXInfo *) 0;
1234 afs_int32 code, err, error = 0;
1235 int voltype, foundserv = 0, foundentry = 0;
1236 afs_int32 aserver, apart;
1238 int wantExtendedInfo; /*Do we want extended vol info? */
1240 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1242 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1245 PrintError("", err);
1247 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1248 as->parms[0].items->data);
1253 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1254 (unsigned long)volid);
1257 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1260 "Could not fetch the entry for volume number %lu from VLDB \n",
1261 (unsigned long)volid);
1265 fprintf(STDOUT, "done\n");
1266 MapHostToNetwork(&entry);
1268 if (entry.volumeId[RWVOL] == volid)
1270 else if (entry.volumeId[BACKVOL] == volid)
1272 else /* (entry.volumeId[ROVOL] == volid) */
1275 do { /* do {...} while (voltype == ROVOL) */
1276 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1277 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1278 * If its a RO vol, get the next RO entry.
1280 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1281 &aserver, &apart, &previdx);
1282 if (previdx == -1) { /* searched all entries */
1284 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1285 as->parms[0].items->data);
1292 /* Get information about the volume from the server */
1294 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1295 hostutil_GetNameByINet(aserver));
1298 if (wantExtendedInfo)
1299 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1301 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1303 fprintf(STDOUT, "done\n");
1307 if (code == ENODEV) {
1308 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1309 /* The VLDB says there is no backup volume and its not on disk */
1310 fprintf(STDERR, "Volume %s does not exist\n",
1311 as->parms[0].items->data);
1315 "Volume does not exist on server %s as indicated by the VLDB\n",
1316 hostutil_GetNameByINet(aserver));
1319 PrintDiagnostics("examine", code);
1321 fprintf(STDOUT, "\n");
1324 if (wantExtendedInfo)
1325 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1327 #ifdef FULL_LISTVOL_SWITCH
1328 if (as->parms[2].items) {
1329 DisplayFormat2(aserver, apart, pntr);
1330 EnumerateEntry(&entry);
1332 #endif /* FULL_LISTVOL_SWITCH */
1333 VolumeStats(pntr, &entry, aserver, apart, voltype);
1335 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1336 /* The VLDB says there is no backup volume yet we found one on disk */
1337 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1338 as->parms[0].items->data);
1347 } while (voltype == ROVOL);
1350 fprintf(STDERR, "Dump only information from VLDB\n\n");
1351 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1353 PostVolumeStats(&entry);
1358 /*------------------------------------------------------------------------
1362 * Routine used to change the status of a single volume.
1365 * as : Ptr to parsed command line arguments.
1368 * 0 for a successful operation,
1369 * Otherwise, one of the ubik or VolServer error values.
1372 * Nothing interesting.
1376 *------------------------------------------------------------------------
1380 register struct cmd_syndesc *as;
1382 struct nvldbentry entry;
1383 afs_int32 vcode = 0;
1386 afs_int32 code, err;
1387 afs_int32 aserver, apart;
1390 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1393 PrintError("", err);
1395 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1396 as->parms[0].items->data);
1400 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1403 "Could not fetch the entry for volume number %lu from VLDB \n",
1404 (unsigned long)volid);
1407 MapHostToNetwork(&entry);
1409 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1410 if (previdx == -1) {
1411 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1412 as->parms[0].items->data);
1416 memset(&info, 0, sizeof(info));
1427 if (as->parms[1].items) {
1429 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1431 fprintf(STDERR, "invalid quota value\n");
1435 if (as->parms[2].items) {
1439 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1442 "Could not update volume info fields for volume number %lu\n",
1443 (unsigned long)volid);
1447 /*------------------------------------------------------------------------
1451 * Brings a volume online.
1454 * as : Ptr to parsed command line arguments.
1457 * 0 for a successful operation,
1460 * Nothing interesting.
1464 *------------------------------------------------------------------------
1468 register struct cmd_syndesc *as;
1470 afs_int32 server, partition, volid;
1471 afs_int32 code, err = 0;
1473 server = GetServer(as->parms[0].items->data);
1475 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1476 as->parms[0].items->data);
1480 partition = volutil_GetPartitionID(as->parms[1].items->data);
1481 if (partition < 0) {
1482 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1483 as->parms[1].items->data);
1487 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1490 PrintError("", err);
1492 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1493 as->parms[0].items->data);
1497 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1500 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1507 /*------------------------------------------------------------------------
1508 * PRIVATE volOffline
1511 * Brings a volume offline.
1514 * as : Ptr to parsed command line arguments.
1517 * 0 for a successful operation,
1520 * Nothing interesting.
1524 *------------------------------------------------------------------------
1527 volOffline(register struct cmd_syndesc *as)
1529 afs_int32 server, partition, volid;
1530 afs_int32 code, err = 0;
1531 afs_int32 transflag, sleeptime, transdone;
1533 server = GetServer(as->parms[0].items->data);
1535 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1536 as->parms[0].items->data);
1540 partition = volutil_GetPartitionID(as->parms[1].items->data);
1541 if (partition < 0) {
1542 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1543 as->parms[1].items->data);
1547 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1550 PrintError("", err);
1552 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1553 as->parms[0].items->data);
1557 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1558 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1559 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1560 if (as->parms[4].items && !as->parms[3].items) {
1561 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1566 UV_SetVolume(server, partition, volid, transflag, transdone,
1569 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1577 CreateVolume(register struct cmd_syndesc *as)
1581 afs_int32 volid, code;
1582 struct nvldbentry entry;
1587 tserver = GetServer(as->parms[0].items->data);
1589 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1590 as->parms[0].items->data);
1593 pname = volutil_GetPartitionID(as->parms[1].items->data);
1595 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1596 as->parms[1].items->data);
1599 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
1601 PrintError("", code);
1604 "vos : partition %s does not exist on the server\n",
1605 as->parms[1].items->data);
1608 if (!ISNAMEVALID(as->parms[2].items->data)) {
1610 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1611 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1614 if (!VolNameOK(as->parms[2].items->data)) {
1616 "Illegal volume name %s, should not end in .readonly or .backup\n",
1617 as->parms[2].items->data);
1620 if (IsNumeric(as->parms[2].items->data)) {
1621 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1622 as->parms[2].items->data);
1625 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1627 fprintf(STDERR, "Volume %s already exists\n",
1628 as->parms[2].items->data);
1629 PrintDiagnostics("create", code);
1633 if (as->parms[3].items) {
1634 if (!IsNumeric(as->parms[3].items->data)) {
1635 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1636 as->parms[3].items->data);
1640 code = util_GetInt32(as->parms[3].items->data, "a);
1642 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1648 UV_CreateVolume2(tserver, pname, as->parms[2].items->data, quota, 0,
1651 PrintDiagnostics("create", code);
1654 MapPartIdIntoName(pname, part);
1655 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1656 (unsigned long)volid, part, as->parms[0].items->data);
1663 struct nvldbentry *entry;
1666 afs_int32 error, code, curserver, curpart, volid;
1668 MapHostToNetwork(entry);
1670 for (i = 0; i < entry->nServers; i++) {
1671 curserver = entry->serverNumber[i];
1672 curpart = entry->serverPartition[i];
1673 if (entry->serverFlags[i] & ITSROVOL) {
1674 volid = entry->volumeId[ROVOL];
1676 volid = entry->volumeId[RWVOL];
1678 code = UV_DeleteVolume(curserver, curpart, volid);
1687 struct cmd_syndesc *as;
1689 afs_int32 err, code = 0;
1690 afs_int32 server = 0, partition = -1, volid;
1694 if (as->parms[0].items) {
1695 server = GetServer(as->parms[0].items->data);
1697 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1698 as->parms[0].items->data);
1703 if (as->parms[1].items) {
1704 partition = volutil_GetPartitionID(as->parms[1].items->data);
1705 if (partition < 0) {
1706 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1707 as->parms[1].items->data);
1711 /* Check for validity of the partition */
1712 if (!IsPartValid(partition, server, &code)) {
1714 PrintError("", code);
1717 "vos : partition %s does not exist on the server\n",
1718 as->parms[1].items->data);
1724 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1726 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1727 as->parms[2].items->data);
1729 PrintError("", err);
1733 /* If the server or partition option are not complete, try to fill
1734 * them in from the VLDB entry.
1736 if ((partition == -1) || !server) {
1737 struct nvldbentry entry;
1739 code = VLDB_GetEntryByID(volid, -1, &entry);
1742 "Could not fetch the entry for volume %lu from VLDB\n",
1743 (unsigned long)volid);
1744 PrintError("", code);
1748 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
1749 || ((volid == entry.volumeId[BACKVOL])
1750 && (entry.flags & BACK_EXISTS))) {
1751 idx = Lp_GetRwIndex(&entry);
1752 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
1753 || ((partition != -1)
1754 && (partition != entry.serverPartition[idx]))) {
1755 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1756 as->parms[2].items->data);
1759 } else if ((volid == entry.volumeId[ROVOL])
1760 && (entry.flags & RO_EXISTS)) {
1761 for (idx = -1, j = 0; j < entry.nServers; j++) {
1762 if (entry.serverFlags[j] != ITSROVOL)
1765 if (((server == 0) || (server == entry.serverNumber[j]))
1766 && ((partition == -1)
1767 || (partition == entry.serverPartition[j]))) {
1770 "VLDB: Volume '%s' matches more than one RO\n",
1771 as->parms[2].items->data);
1778 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1779 as->parms[2].items->data);
1783 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1784 as->parms[2].items->data);
1788 server = htonl(entry.serverNumber[idx]);
1789 partition = entry.serverPartition[idx];
1793 code = UV_DeleteVolume(server, partition, volid);
1795 PrintDiagnostics("remove", code);
1799 MapPartIdIntoName(partition, pname);
1800 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
1801 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
1805 #define TESTM 0 /* set for move space tests, clear for production */
1808 register struct cmd_syndesc *as;
1811 afs_int32 volid, fromserver, toserver, frompart, topart, code, err;
1812 char fromPartName[10], toPartName[10];
1814 struct diskPartition partition; /* for space check */
1817 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1820 PrintError("", err);
1822 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1823 as->parms[0].items->data);
1826 fromserver = GetServer(as->parms[1].items->data);
1827 if (fromserver == 0) {
1828 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1829 as->parms[1].items->data);
1832 toserver = GetServer(as->parms[3].items->data);
1833 if (toserver == 0) {
1834 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1835 as->parms[3].items->data);
1838 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1840 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1841 as->parms[2].items->data);
1844 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
1846 PrintError("", code);
1849 "vos : partition %s does not exist on the server\n",
1850 as->parms[2].items->data);
1853 topart = volutil_GetPartitionID(as->parms[4].items->data);
1855 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1856 as->parms[4].items->data);
1859 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
1861 PrintError("", code);
1864 "vos : partition %s does not exist on the server\n",
1865 as->parms[4].items->data);
1870 * check source partition for space to clone volume
1873 MapPartIdIntoName(topart, toPartName);
1874 MapPartIdIntoName(frompart, fromPartName);
1877 * check target partition for space to move volume
1880 code = UV_PartitionInfo(toserver, toPartName, &partition);
1882 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
1886 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
1889 p = (volintInfo *) 0;
1890 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
1892 fprintf(STDERR, "vos:cannot access volume %lu\n",
1893 (unsigned long)volid);
1898 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
1900 if (partition.free <= p->size) {
1902 "vos: no space on target partition %s to move volume %lu\n",
1903 toPartName, (unsigned long)volid);
1910 fprintf(STDOUT, "size test - don't do move\n");
1914 /* successful move still not guaranteed but shoot for it */
1916 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1918 PrintDiagnostics("move", code);
1921 MapPartIdIntoName(topart, toPartName);
1922 MapPartIdIntoName(frompart, fromPartName);
1923 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
1924 (unsigned long)volid, as->parms[1].items->data, fromPartName,
1925 as->parms[3].items->data, toPartName);
1932 register struct cmd_syndesc *as;
1934 afs_int32 volid, fromserver, toserver, frompart, topart, code, err;
1935 char fromPartName[10], toPartName[10], *tovolume;
1936 struct nvldbentry entry;
1937 struct diskPartition partition; /* for space check */
1940 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1943 PrintError("", err);
1945 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1946 as->parms[0].items->data);
1949 fromserver = GetServer(as->parms[1].items->data);
1950 if (fromserver == 0) {
1951 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1952 as->parms[1].items->data);
1956 toserver = GetServer(as->parms[4].items->data);
1957 if (toserver == 0) {
1958 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1959 as->parms[3].items->data);
1963 tovolume = as->parms[3].items->data;
1964 if (!ISNAMEVALID(tovolume)) {
1966 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1967 tovolume, VOLSER_OLDMAXVOLNAME - 10);
1970 if (!VolNameOK(tovolume)) {
1972 "Illegal volume name %s, should not end in .readonly or .backup\n",
1976 if (IsNumeric(tovolume)) {
1977 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1981 code = VLDB_GetEntryByName(tovolume, &entry);
1983 fprintf(STDERR, "Volume %s already exists\n", tovolume);
1984 PrintDiagnostics("copy", code);
1988 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1990 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1991 as->parms[2].items->data);
1994 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
1996 PrintError("", code);
1999 "vos : partition %s does not exist on the server\n",
2000 as->parms[2].items->data);
2004 topart = volutil_GetPartitionID(as->parms[5].items->data);
2006 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2007 as->parms[4].items->data);
2010 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2012 PrintError("", code);
2015 "vos : partition %s does not exist on the server\n",
2016 as->parms[4].items->data);
2021 * check source partition for space to clone volume
2024 MapPartIdIntoName(topart, toPartName);
2025 MapPartIdIntoName(frompart, fromPartName);
2028 * check target partition for space to move volume
2031 code = UV_PartitionInfo(toserver, toPartName, &partition);
2033 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2037 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2040 p = (volintInfo *) 0;
2041 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2043 fprintf(STDERR, "vos:cannot access volume %lu\n",
2044 (unsigned long)volid);
2049 if (partition.free <= p->size) {
2051 "vos: no space on target partition %s to copy volume %lu\n",
2052 toPartName, (unsigned long)volid);
2058 /* successful copy still not guaranteed but shoot for it */
2061 UV_CopyVolume(volid, fromserver, frompart, tovolume, toserver,
2064 PrintDiagnostics("copy", code);
2067 MapPartIdIntoName(topart, toPartName);
2068 MapPartIdIntoName(frompart, fromPartName);
2069 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2070 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2071 tovolume, as->parms[4].items->data, toPartName);
2079 register struct cmd_syndesc *as;
2081 afs_int32 avolid, aserver, apart, vtype, code, err;
2082 struct nvldbentry entry;
2084 afs_int32 buvolid, buserver, bupart, butype;
2085 struct nvldbentry buentry;
2087 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2090 PrintError("", err);
2092 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2093 as->parms[0].items->data);
2096 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2100 /* verify this is a readwrite volume */
2102 if (vtype != RWVOL) {
2103 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2107 /* is there a backup volume already? */
2109 if (entry.flags & BACK_EXISTS) {
2110 /* yep, where is it? */
2112 buvolid = entry.volumeId[BACKVOL];
2113 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2118 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2121 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2127 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2128 (unsigned long)buvolid, (unsigned long)buserver);
2133 /* nope, carry on */
2135 code = UV_BackupVolume(aserver, apart, avolid);
2138 PrintDiagnostics("backup", code);
2141 fprintf(STDOUT, "Created backup volume for %s \n",
2142 as->parms[0].items->data);
2148 register struct cmd_syndesc *as;
2151 struct nvldbentry entry;
2152 afs_int32 avolid, aserver, apart, vtype, code, err;
2155 if (as->parms[1].items)
2157 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2160 PrintError("", err);
2162 fprintf(STDERR, "vos: can't find volume '%s'\n",
2163 as->parms[0].items->data);
2166 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2170 if (vtype != RWVOL) {
2171 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2175 if (!ISNAMEVALID(entry.name)) {
2177 "Volume name %s is too long, rename before releasing\n",
2182 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2184 PrintDiagnostics("release", code);
2187 fprintf(STDOUT, "Released volume %s successfully\n",
2188 as->parms[0].items->data);
2194 register struct cmd_syndesc *as;
2197 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
2198 char filename[NameLen];
2199 struct nvldbentry entry;
2201 rx_SetRxDeadTime(60 * 10);
2202 for (i = 0; i < MAXSERVERS; i++) {
2203 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2206 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2207 if (rxConn->service)
2208 rxConn->service->connDeadTime = rx_connDeadTime;
2211 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2214 PrintError("", err);
2216 fprintf(STDERR, "vos: can't find volume '%s'\n",
2217 as->parms[0].items->data);
2221 if (as->parms[3].items || as->parms[4].items) {
2222 if (!as->parms[3].items || !as->parms[4].items) {
2224 "Must specify both -server and -partition options\n");
2227 aserver = GetServer(as->parms[3].items->data);
2229 fprintf(STDERR, "Invalid server name\n");
2232 apart = volutil_GetPartitionID(as->parms[4].items->data);
2234 fprintf(STDERR, "Invalid partition name\n");
2238 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2243 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2244 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2246 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2247 as->parms[1].items->data, code);
2251 if (as->parms[2].items) {
2252 strcpy(filename, as->parms[2].items->data);
2254 strcpy(filename, "");
2257 if (as->parms[5].items) {
2259 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2260 DumpFunction, filename);
2263 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2267 PrintDiagnostics("dump", code);
2270 if (strcmp(filename, ""))
2271 fprintf(STDERR, "Dumped volume %s in file %s\n",
2272 as->parms[0].items->data, filename);
2274 fprintf(STDERR, "Dumped volume %s in stdout \n",
2275 as->parms[0].items->data);
2286 register struct cmd_syndesc *as;
2289 afs_int32 avolid, aserver, apart, code, vcode, err;
2290 afs_int32 aoverwrite = ASK;
2291 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2293 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2294 char volname[VOLSER_MAXVOLNAME + 1];
2295 struct nvldbentry entry;
2299 if (as->parms[4].items) {
2300 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2303 PrintError("", err);
2305 fprintf(STDERR, "vos: can't find volume '%s'\n",
2306 as->parms[4].items->data);
2312 if (as->parms[5].items) {
2313 if ((strcmp(as->parms[5].items->data, "a") == 0)
2314 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2316 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2317 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2319 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2320 || (strcmp(as->parms[5].items->data, "inc") == 0)
2321 || (strcmp(as->parms[5].items->data, "increment") == 0)
2322 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2325 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2326 as->parms[5].items->data);
2330 if (as->parms[6].items)
2332 if (as->parms[7].items) {
2337 aserver = GetServer(as->parms[0].items->data);
2339 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2340 as->parms[0].items->data);
2343 apart = volutil_GetPartitionID(as->parms[1].items->data);
2345 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2346 as->parms[1].items->data);
2349 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2351 PrintError("", code);
2354 "vos : partition %s does not exist on the server\n",
2355 as->parms[1].items->data);
2358 strcpy(avolname, as->parms[2].items->data);
2359 if (!ISNAMEVALID(avolname)) {
2361 "vos: the name of the volume %s exceeds the size limit\n",
2365 if (!VolNameOK(avolname)) {
2367 "Illegal volume name %s, should not end in .readonly or .backup\n",
2371 if (as->parms[3].items) {
2372 strcpy(afilename, as->parms[3].items->data);
2373 if (!FileExists(afilename)) {
2374 fprintf(STDERR, "Can't access file %s\n", afilename);
2378 strcpy(afilename, "");
2381 /* Check if volume exists or not */
2383 vsu_ExtractName(volname, avolname);
2384 vcode = VLDB_GetEntryByName(volname, &entry);
2385 if (vcode) { /* no volume - do a full restore */
2386 restoreflags = RV_FULLRST;
2387 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2389 "Volume does not exist; Will perform a full restore\n");
2392 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
2393 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
2394 restoreflags = RV_FULLRST;
2395 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2397 "%s Volume does not exist; Will perform a full restore\n",
2398 readonly ? "RO" : "RW");
2401 avolid = entry.volumeId[voltype];
2402 } else if (entry.volumeId[voltype] != 0
2403 && entry.volumeId[voltype] != avolid) {
2404 avolid = entry.volumeId[voltype];
2408 else { /* volume exists - do we do a full incremental or abort */
2409 int Oserver, Opart, Otype, vol_elsewhere = 0;
2410 struct nvldbentry Oentry;
2414 avolid = entry.volumeId[voltype];
2415 } else if (entry.volumeId[voltype] != 0
2416 && entry.volumeId[voltype] != avolid) {
2417 avolid = entry.volumeId[voltype];
2420 /* A file name was specified - check if volume is on another partition */
2421 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
2425 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
2428 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
2432 if (!vcode || (Opart != apart))
2435 if (aoverwrite == ASK) {
2436 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
2438 "Volume exists and no -overwrite option specified; Aborting restore command\n");
2442 /* Ask what to do */
2443 if (vol_elsewhere) {
2445 "The volume %s %u already exists on a different server/part\n",
2446 volname, entry.volumeId[voltype]);
2448 "Do you want to do a full restore or abort? [fa](a): ");
2451 "The volume %s %u already exists in the VLDB\n",
2452 volname, entry.volumeId[voltype]);
2454 "Do you want to do a full/incremental restore or abort? [fia](a): ");
2457 while (!(dc == EOF || dc == '\n'))
2458 dc = getchar(); /* goto end of line */
2459 if ((c == 'f') || (c == 'F'))
2461 else if ((c == 'i') || (c == 'I'))
2467 if (aoverwrite == ABORT) {
2468 fprintf(STDERR, "Volume exists; Aborting restore command\n");
2470 } else if (aoverwrite == FULL) {
2471 restoreflags = RV_FULLRST;
2473 "Volume exists; Will delete and perform full restore\n");
2474 } else if (aoverwrite == INC) {
2476 if (vol_elsewhere) {
2478 "%s volume %lu already exists on a different server/part; not allowed\n",
2479 readonly ? "RO" : "RW", (unsigned long)avolid);
2485 restoreflags |= RV_OFFLINE;
2487 restoreflags |= RV_RDONLY;
2489 UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags,
2490 WriteData, afilename);
2492 PrintDiagnostics("restore", code);
2495 MapPartIdIntoName(apart, apartName);
2498 * patch typo here - originally "parms[1]", should be "parms[0]"
2501 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
2502 as->parms[0].items->data, apartName);
2508 register struct cmd_syndesc *as;
2511 afs_int32 avolid, code, err;
2513 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2516 PrintError("", err);
2518 fprintf(STDERR, "vos: can't find volume '%s'\n",
2519 as->parms[0].items->data);
2523 code = UV_LockRelease(avolid);
2525 PrintDiagnostics("unlock", code);
2528 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
2529 as->parms[0].items->data);
2535 register struct cmd_syndesc *as;
2537 afs_int32 avolid, aserver, apart, code, err;
2538 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2540 vsu_ExtractName(avolname, as->parms[2].items->data);;
2541 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2544 PrintError("", err);
2546 fprintf(STDERR, "vos: can't find volume '%s'\n",
2547 as->parms[2].items->data);
2550 aserver = GetServer(as->parms[0].items->data);
2552 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2553 as->parms[0].items->data);
2556 apart = volutil_GetPartitionID(as->parms[1].items->data);
2558 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2559 as->parms[1].items->data);
2562 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2564 PrintError("", code);
2567 "vos : partition %s does not exist on the server\n",
2568 as->parms[1].items->data);
2571 code = UV_AddSite(aserver, apart, avolid);
2573 PrintDiagnostics("addsite", code);
2576 MapPartIdIntoName(apart, apartName);
2577 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
2578 as->parms[0].items->data, apartName, as->parms[2].items->data);
2584 register struct cmd_syndesc *as;
2587 afs_int32 avolid, aserver, apart, code, err;
2588 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2590 vsu_ExtractName(avolname, as->parms[2].items->data);
2591 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2594 PrintError("", err);
2596 fprintf(STDERR, "vos: can't find volume '%s'\n",
2597 as->parms[2].items->data);
2600 aserver = GetServer(as->parms[0].items->data);
2602 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2603 as->parms[0].items->data);
2606 apart = volutil_GetPartitionID(as->parms[1].items->data);
2608 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2609 as->parms[1].items->data);
2613 *skip the partition validity check, since it is possible that the partition
2614 *has since been decomissioned.
2617 if (!IsPartValid(apart,aserver,&code)){
2618 if(code) PrintError("",code);
2619 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2623 code = UV_RemoveSite(aserver, apart, avolid);
2625 PrintDiagnostics("remsite", code);
2628 MapPartIdIntoName(apart, apartName);
2629 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
2630 as->parms[0].items->data, apartName, as->parms[2].items->data);
2636 register struct cmd_syndesc *as;
2638 afs_int32 avolid, aserver, apart, code, err;
2641 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2644 PrintError("", err);
2646 fprintf(STDERR, "vos: can't find volume '%s'\n",
2647 as->parms[2].items->data);
2650 aserver = GetServer(as->parms[0].items->data);
2652 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2653 as->parms[0].items->data);
2656 apart = volutil_GetPartitionID(as->parms[1].items->data);
2658 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2659 as->parms[1].items->data);
2662 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2664 PrintError("", code);
2667 "vos : partition %s does not exist on the server\n",
2668 as->parms[1].items->data);
2671 code = UV_ChangeLocation(aserver, apart, avolid);
2673 PrintDiagnostics("addsite", code);
2676 MapPartIdIntoName(apart, apartName);
2677 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
2678 as->parms[0].items->data, apartName, as->parms[2].items->data);
2684 register struct cmd_syndesc *as;
2686 afs_int32 aserver, code;
2687 struct partList dummyPartList;
2692 aserver = GetServer(as->parms[0].items->data);
2694 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2695 as->parms[0].items->data);
2700 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
2702 PrintDiagnostics("listpart", code);
2706 fprintf(STDOUT, "The partitions on the server are:\n");
2707 for (i = 0; i < cnt; i++) {
2708 if (dummyPartList.partFlags[i] & PARTVALID) {
2709 memset(pname, 0, sizeof(pname));
2710 MapPartIdIntoName(dummyPartList.partId[i], pname);
2711 fprintf(STDOUT, " %10s ", pname);
2713 if ((i % 5) == 0 && (i != 0))
2714 fprintf(STDOUT, "\n");
2717 fprintf(STDOUT, "\n");
2718 fprintf(STDOUT, "Total: %d\n", total);
2724 CompareVolName(p1, p2)
2727 volintInfo *arg1, *arg2;
2729 arg1 = (volintInfo *) p1;
2730 arg2 = (volintInfo *) p2;
2731 return (strcmp(arg1->name, arg2->name));
2735 /*------------------------------------------------------------------------
2736 * PRIVATE XCompareVolName
2739 * Comparison routine for volume names coming from an extended
2743 * a_obj1P : Char ptr to first extended vol info object
2744 * a_obj1P : Char ptr to second extended vol info object
2747 * The value of strcmp() on the volume names within the passed
2748 * objects (i,e., -1, 0, or 1).
2751 * Passed to qsort() as the designated comparison routine.
2755 *------------------------------------------------------------------------*/
2758 XCompareVolName(a_obj1P, a_obj2P)
2759 char *a_obj1P, *a_obj2P;
2761 { /*XCompareVolName */
2764 (((struct volintXInfo *)(a_obj1P))->name,
2765 ((struct volintXInfo *)(a_obj2P))->name));
2767 } /*XCompareVolName */
2770 CompareVolID(p1, p2)
2773 volintInfo *arg1, *arg2;
2775 arg1 = (volintInfo *) p1;
2776 arg2 = (volintInfo *) p2;
2777 if (arg1->volid == arg2->volid)
2779 if (arg1->volid > arg2->volid)
2786 /*------------------------------------------------------------------------
2787 * PRIVATE XCompareVolID
2790 * Comparison routine for volume IDs coming from an extended
2794 * a_obj1P : Char ptr to first extended vol info object
2795 * a_obj1P : Char ptr to second extended vol info object
2798 * The value of strcmp() on the volume names within the passed
2799 * objects (i,e., -1, 0, or 1).
2802 * Passed to qsort() as the designated comparison routine.
2806 *------------------------------------------------------------------------*/
2809 XCompareVolID(a_obj1P, a_obj2P)
2810 char *a_obj1P, *a_obj2P;
2812 { /*XCompareVolID */
2814 afs_int32 id1, id2; /*Volume IDs we're comparing */
2816 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2817 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2825 } /*XCompareVolID */
2827 /*------------------------------------------------------------------------
2828 * PRIVATE ListVolumes
2831 * Routine used to list volumes, contacting the Volume Server
2832 * directly, bypassing the VLDB.
2835 * as : Ptr to parsed command line arguments.
2838 * 0 Successful operation
2841 * Nothing interesting.
2845 *------------------------------------------------------------------------*/
2849 register struct cmd_syndesc *as;
2851 afs_int32 apart, int32list, fast;
2852 afs_int32 aserver, code;
2853 volintInfo *pntr, *oldpntr;
2857 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
2858 int wantExtendedInfo; /*Do we want extended vol info? */
2861 struct partList dummyPartList;
2869 if (as->parms[3].items)
2871 if (as->parms[4].items)
2875 if (as->parms[2].items)
2881 if (as->parms[5].items) {
2883 * We can't coexist with the fast flag.
2887 "vos: Can't use the -fast and -extended flags together\n");
2892 * We need to turn on ``long'' listings to get the full effect.
2894 wantExtendedInfo = 1;
2897 wantExtendedInfo = 0;
2898 if (as->parms[1].items) {
2899 apart = volutil_GetPartitionID(as->parms[1].items->data);
2901 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2902 as->parms[1].items->data);
2905 dummyPartList.partId[0] = apart;
2906 dummyPartList.partFlags[0] = PARTVALID;
2909 aserver = GetServer(as->parms[0].items->data);
2911 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2912 as->parms[0].items->data);
2917 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2919 PrintError("", code);
2922 "vos : partition %s does not exist on the server\n",
2923 as->parms[1].items->data);
2927 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
2929 PrintDiagnostics("listvol", code);
2933 for (i = 0; i < cnt; i++) {
2934 if (dummyPartList.partFlags[i] & PARTVALID) {
2935 if (wantExtendedInfo)
2937 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
2941 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
2944 PrintDiagnostics("listvol", code);
2949 if (wantExtendedInfo) {
2950 origxInfoP = xInfoP;
2951 base = (char *)xInfoP;
2954 base = (char *)pntr;
2958 if (wantExtendedInfo)
2959 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2961 qsort(base, count, sizeof(volintInfo), CompareVolName);
2963 if (wantExtendedInfo)
2964 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2966 qsort(base, count, sizeof(volintInfo), CompareVolID);
2968 MapPartIdIntoName(dummyPartList.partId[i], pname);
2971 "Total number of volumes on server %s partition %s: %lu \n",
2972 as->parms[0].items->data, pname,
2973 (unsigned long)count);
2974 if (wantExtendedInfo) {
2975 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
2976 count, int32list, fast, quiet);
2979 xInfoP = (volintXInfo *) 0;
2981 #ifdef FULL_LISTVOL_SWITCH
2982 if (as->parms[6].items)
2983 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
2986 #endif /* FULL_LISTVOL_SWITCH */
2987 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
2988 count, int32list, fast, quiet);
2991 pntr = (volintInfo *) 0;
3000 register struct cmd_syndesc *as;
3002 afs_int32 pname, code; /* part name */
3008 if (as->parms[0].items) {
3009 tserver = GetServer(as->parms[0].items->data);
3011 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3012 as->parms[0].items->data);
3017 if (as->parms[1].items) {
3018 pname = volutil_GetPartitionID(as->parms[1].items->data);
3020 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3021 as->parms[1].items->data);
3024 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
3026 PrintError("", code);
3029 "vos: partition %s does not exist on the server\n",
3030 as->parms[1].items->data);
3037 "The -partition option requires a -server option\n");
3042 if (as->parms[2].items) {
3043 /* Synchronize an individual volume */
3044 volname = as->parms[2].items->data;
3045 code = UV_SyncVolume(tserver, pname, volname, flags);
3049 "Without a -volume option, the -server option is required\n");
3052 code = UV_SyncVldb(tserver, pname, flags, 0 /*unused */ );
3056 PrintDiagnostics("syncvldb", code);
3060 /* Print a summary of what we did */
3062 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3064 fprintf(STDOUT, "VLDB synchronized");
3066 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3069 MapPartIdIntoName(pname, part);
3070 fprintf(STDOUT, " partition %s\n", part);
3072 fprintf(STDOUT, "\n");
3079 register struct cmd_syndesc *as;
3082 afs_int32 pname, code; /* part name */
3087 tserver = GetServer(as->parms[0].items->data);
3089 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3090 as->parms[0].items->data);
3093 if (as->parms[1].items) {
3094 pname = volutil_GetPartitionID(as->parms[1].items->data);
3096 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3097 as->parms[1].items->data);
3100 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
3102 PrintError("", code);
3105 "vos : partition %s does not exist on the server\n",
3106 as->parms[1].items->data);
3112 code = UV_SyncServer(tserver, pname, flags, 0 /*unused */ );
3114 PrintDiagnostics("syncserv", code);
3118 MapPartIdIntoName(pname, part);
3119 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3120 as->parms[0].items->data, part);
3122 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3123 as->parms[0].items->data);
3132 struct nvldbentry entry;
3135 /* The vlserver will handle names with the .readonly
3136 * and .backup extension as well as volume ids.
3138 vcode = VLDB_GetEntryByName(name, &entry);
3140 PrintError("", vcode);
3143 MapHostToNetwork(&entry);
3144 EnumerateEntry(&entry);
3146 /* Defect #3027: grubby check to handle locked volume.
3147 * If VLOP_ALLOPERS is set, the entry is locked.
3148 * Leave this routine as is, but put in correct check.
3150 if (entry.flags & VLOP_ALLOPERS)
3151 fprintf(STDOUT, " Volume is currently LOCKED \n");
3158 register struct cmd_syndesc *as;
3161 struct nvldbentry entry;
3162 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3164 if (as->parms[3].items) {
3165 /* force flag is on, use the other version */
3166 return NukeVolume(as);
3169 if (as->parms[4].items) {
3173 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3176 PrintError("", err);
3178 fprintf(STDERR, "vos: can't find volume '%s'\n",
3179 as->parms[2].items->data);
3182 part = volutil_GetPartitionID(as->parms[1].items->data);
3184 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3185 as->parms[1].items->data);
3188 server = GetServer(as->parms[0].items->data);
3190 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3191 as->parms[0].items->data);
3194 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3196 PrintError("", code);
3199 "vos : partition %s does not exist on the server\n",
3200 as->parms[1].items->data);
3203 code = VLDB_GetEntryByID(volid, -1, &entry);
3205 if (volid == entry.volumeId[RWVOL])
3206 backupid = entry.volumeId[BACKVOL];
3208 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3209 (unsigned long)volid);
3212 volintInfo *pntr = (volintInfo *) 0;
3215 code = UV_ListOneVolume(server, part, volid, &pntr);
3217 if (volid == pntr->parentID)
3218 backupid = pntr->backupID;
3224 code = UV_VolumeZap(server, part, backupid);
3226 PrintDiagnostics("zap", code);
3229 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3230 (unsigned long)backupid);
3233 code = UV_VolumeZap(server, part, volid);
3235 PrintDiagnostics("zap", code);
3238 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3245 register struct cmd_syndesc *as;
3248 afs_int32 server, code;
3249 transDebugInfo *pntr, *oldpntr;
3254 server = GetServer(as->parms[0].items->data);
3256 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3257 as->parms[0].items->data);
3260 code = UV_VolserStatus(server, &pntr, &count);
3262 PrintDiagnostics("status", code);
3267 fprintf(STDOUT, "No active transactions on %s\n",
3268 as->parms[0].items->data);
3270 fprintf(STDOUT, "Total transactions: %d\n", count);
3272 for (i = 0; i < count; i++) {
3273 /*print out the relevant info */
3274 fprintf(STDOUT, "--------------------------------------\n");
3275 fprintf(STDOUT, "transaction: %lu created: %s",
3276 (unsigned long)pntr->tid, ctime((time_t *) & pntr->time));
3277 if (pntr->returnCode) {
3278 fprintf(STDOUT, "returnCode: %lu\n",
3279 (unsigned long)pntr->returnCode);
3282 fprintf(STDOUT, "attachFlags: ");
3283 switch (pntr->iflags) {
3285 fprintf(STDOUT, "offline ");
3288 fprintf(STDOUT, "busy ");
3291 fprintf(STDOUT, "readonly ");
3294 fprintf(STDOUT, "create ");
3297 fprintf(STDOUT, "create volid ");
3300 fprintf(STDOUT, "\n");
3303 fprintf(STDOUT, "volumeStatus: ");
3304 switch (pntr->vflags) {
3305 case VTDeleteOnSalvage:
3306 fprintf(STDOUT, "deleteOnSalvage ");
3307 case VTOutOfService:
3308 fprintf(STDOUT, "outOfService ");
3310 fprintf(STDOUT, "deleted ");
3312 fprintf(STDOUT, "\n");
3315 fprintf(STDOUT, "transactionFlags: ");
3316 fprintf(STDOUT, "delete\n");
3318 MapPartIdIntoName(pntr->partition, pname);
3319 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
3320 (unsigned long)pntr->volid, pname, pntr->lastProcName);
3321 if (pntr->callValid) {
3323 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3324 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
3325 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
3328 fprintf(STDOUT, "--------------------------------------\n");
3329 fprintf(STDOUT, "\n");
3338 register struct cmd_syndesc *as;
3340 afs_int32 code1, code2, code;
3341 struct nvldbentry entry;
3343 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
3345 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
3346 as->parms[0].items->data);
3349 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
3350 if ((!code1) && (!code2)) { /*the newname already exists */
3351 fprintf(STDERR, "vos: volume %s already exists\n",
3352 as->parms[1].items->data);
3356 if (code1 && code2) {
3357 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
3358 as->parms[0].items->data, as->parms[1].items->data);
3361 if (!VolNameOK(as->parms[0].items->data)) {
3363 "Illegal volume name %s, should not end in .readonly or .backup\n",
3364 as->parms[0].items->data);
3367 if (!ISNAMEVALID(as->parms[1].items->data)) {
3369 "vos: the new volume name %s exceeds the size limit of %d\n",
3370 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
3373 if (!VolNameOK(as->parms[1].items->data)) {
3375 "Illegal volume name %s, should not end in .readonly or .backup\n",
3376 as->parms[1].items->data);
3379 if (IsNumeric(as->parms[1].items->data)) {
3380 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
3381 as->parms[1].items->data);
3384 MapHostToNetwork(&entry);
3386 UV_RenameVolume(&entry, as->parms[0].items->data,
3387 as->parms[1].items->data);
3389 PrintDiagnostics("rename", code);
3392 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
3393 as->parms[1].items->data);
3397 GetVolumeInfo(volid, server, part, voltype, rentry)
3398 afs_int32 *server, volid, *part, *voltype;
3399 register struct nvldbentry *rentry;
3404 vcode = VLDB_GetEntryByID(volid, -1, rentry);
3407 "Could not fetch the entry for volume %lu from VLDB \n",
3408 (unsigned long)volid);
3409 PrintError("", vcode);
3412 MapHostToNetwork(rentry);
3413 if (volid == rentry->volumeId[ROVOL]) {
3415 for (i = 0; i < rentry->nServers; i++) {
3416 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
3417 && !(rentry->serverFlags[i] & RO_DONTUSE))
3422 "RO volume is not found in VLDB entry for volume %lu\n",
3423 (unsigned long)volid);
3427 *server = rentry->serverNumber[index];
3428 *part = rentry->serverPartition[index];
3432 index = Lp_GetRwIndex(rentry);
3435 "RW Volume is not found in VLDB entry for volume %lu\n",
3436 (unsigned long)volid);
3439 if (volid == rentry->volumeId[RWVOL]) {
3441 *server = rentry->serverNumber[index];
3442 *part = rentry->serverPartition[index];
3445 if (volid == rentry->volumeId[BACKVOL]) {
3447 *server = rentry->serverNumber[index];
3448 *part = rentry->serverPartition[index];
3452 "unexpected volume type for volume %lu\n",
3453 (unsigned long)volid);
3459 register struct cmd_syndesc *as;
3465 struct VldbListByAttributes attributes;
3466 nbulkentries arrayEntries;
3467 register struct nvldbentry *vllist;
3468 struct cmd_item *itp;
3471 char prefix[VOLSER_MAXVOLNAME + 1];
3473 afs_int32 totalBack = 0, totalFail = 0, err;
3475 if (as->parms[0].items) { /* -id */
3476 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
3478 "You cannot use -server, -partition, or -prefix with the -id argument\n");
3481 for (itp = as->parms[0].items; itp; itp = itp->next) {
3482 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
3485 PrintError("", err);
3487 fprintf(STDERR, "vos: can't find volume '%s'\n",
3491 if (as->parms[4].items) { /* -noexecute */
3492 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3497 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3499 fprintf(STDERR, "Could not delete entry for volume %s\n",
3502 "You must specify a RW volume name or ID "
3503 "(the entire VLDB entry will be deleted)\n");
3504 PrintError("", vcode);
3510 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
3514 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
3515 fprintf(STDERR, "You must specify an option\n");
3519 /* Zero out search attributes */
3520 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3522 if (as->parms[1].items) { /* -prefix */
3523 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
3525 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
3527 "You must provide -server with the -prefix argument\n");
3532 if (as->parms[2].items) { /* -server */
3534 aserver = GetServer(as->parms[2].items->data);
3536 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3537 as->parms[2].items->data);
3540 attributes.server = ntohl(aserver);
3541 attributes.Mask |= VLLIST_SERVER;
3544 if (as->parms[3].items) { /* -partition */
3545 if (!as->parms[2].items) {
3547 "You must provide -server with the -partition argument\n");
3550 apart = volutil_GetPartitionID(as->parms[3].items->data);
3552 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3553 as->parms[3].items->data);
3556 attributes.partition = apart;
3557 attributes.Mask |= VLLIST_PARTITION;
3560 /* Print status line of what we are doing */
3561 fprintf(STDOUT, "Deleting VLDB entries for ");
3562 if (as->parms[2].items) {
3563 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
3565 if (as->parms[3].items) {
3567 MapPartIdIntoName(apart, pname);
3568 fprintf(STDOUT, "partition %s ", pname);
3571 fprintf(STDOUT, "which are prefixed with %s ", prefix);
3573 fprintf(STDOUT, "\n");
3576 /* Get all the VLDB entries on a server and/or partition */
3577 memset(&arrayEntries, 0, sizeof(arrayEntries));
3578 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3580 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3581 PrintError("", vcode);
3585 /* Process each entry */
3586 for (j = 0; j < nentries; j++) {
3587 vllist = &arrayEntries.nbulkentries_val[j];
3589 /* It only deletes the RW volumes */
3590 if (strncmp(vllist->name, prefix, strlen(prefix))) {
3593 "Omitting to delete %s due to prefix %s mismatch\n",
3594 vllist->name, prefix);
3601 if (as->parms[4].items) { /* -noexecute */
3602 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3608 /* Only matches the RW volume name */
3609 avolid = vllist->volumeId[RWVOL];
3610 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3612 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
3615 PrintError("", vcode);
3620 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
3625 fprintf(STDOUT, "----------------------\n");
3627 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
3628 (unsigned long)totalBack, (unsigned long)totalFail);
3629 if (arrayEntries.nbulkentries_val)
3630 free(arrayEntries.nbulkentries_val);
3636 CompareVldbEntryByName(p1, p2)
3639 struct nvldbentry *arg1, *arg2;
3641 arg1 = (struct nvldbentry *)p1;
3642 arg2 = (struct nvldbentry *)p2;
3643 return (strcmp(arg1->name, arg2->name));
3647 static int CompareVldbEntry(p1,p2)
3650 struct nvldbentry *arg1,*arg2;
3653 char comp1[100],comp2[100];
3654 char temp1[20],temp2[20];
3656 arg1 = (struct nvldbentry *)p1;
3657 arg2 = (struct nvldbentry *)p2;
3661 for(i = 0; i < arg1->nServers; i++)
3662 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
3663 for(i = 0; i < arg2->nServers; i++)
3664 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
3665 if(pos1 == -1 || pos2 == -1){
3669 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
3670 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
3671 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
3672 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
3673 strcat(comp1,temp1);
3674 strcat(comp2,temp2);
3675 strcat(comp1,arg1->name);
3676 strcat(comp1,arg2->name);
3677 return(strcmp(comp1,comp2));
3684 struct cmd_syndesc *as;
3687 afs_int32 aserver, code;
3689 struct VldbListByAttributes attributes;
3690 nbulkentries arrayEntries;
3691 struct nvldbentry *vllist, *tarray = 0, *ttarray;
3692 afs_int32 centries, nentries = 0, tarraysize, parraysize;
3695 int quiet, sort, lock;
3696 afs_int32 thisindex, nextindex;
3701 attributes.Mask = 0;
3702 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
3703 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
3704 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
3706 /* If the volume name is given, Use VolumeInfoCmd to look it up
3707 * and not ListAttributes.
3709 if (as->parms[0].items) {
3712 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
3715 code = VolumeInfoCmd(as->parms[0].items->data);
3717 PrintError("", code);
3723 /* Server specified */
3724 if (as->parms[1].items) {
3725 aserver = GetServer(as->parms[1].items->data);
3727 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3728 as->parms[1].items->data);
3731 attributes.server = ntohl(aserver);
3732 attributes.Mask |= VLLIST_SERVER;
3735 /* Partition specified */
3736 if (as->parms[2].items) {
3737 apart = volutil_GetPartitionID(as->parms[2].items->data);
3739 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3740 as->parms[2].items->data);
3743 attributes.partition = apart;
3744 attributes.Mask |= VLLIST_PARTITION;
3748 attributes.Mask |= VLLIST_FLAG;
3749 attributes.flag = VLOP_ALLOPERS;
3752 /* Print header information */
3754 MapPartIdIntoName(apart, pname);
3755 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
3756 (as->parms[1].items ? "server" : "all"),
3757 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3758 (as->parms[2].items ? " partition " : ""),
3759 (as->parms[2].items ? pname : ""),
3760 (lock ? "which are locked:" : ""));
3763 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3764 memset(&arrayEntries, 0, sizeof(arrayEntries));
3769 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
3770 &arrayEntries, &nextindex);
3771 if (vcode == RXGEN_OPCODE) {
3772 /* Vlserver not running with ListAttributesN2. Fall back */
3774 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3778 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3779 PrintError("", vcode);
3782 nentries += centries;
3784 /* We don't sort, so just print the entries now */
3786 for (j = 0; j < centries; j++) { /* process each entry */
3787 vllist = &arrayEntries.nbulkentries_val[j];
3788 MapHostToNetwork(vllist);
3789 EnumerateEntry(vllist);
3791 if (vllist->flags & VLOP_ALLOPERS)
3792 fprintf(STDOUT, " Volume is currently LOCKED \n");
3796 /* So we sort. First we must collect all the entries and keep
3799 else if (centries > 0) {
3801 /* steal away the first bulk entries array */
3802 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3803 tarraysize = centries * sizeof(struct nvldbentry);
3804 arrayEntries.nbulkentries_val = 0;
3806 /* Grow the tarray to keep the extra entries */
3807 parraysize = (centries * sizeof(struct nvldbentry));
3809 (struct nvldbentry *)realloc(tarray,
3810 tarraysize + parraysize);
3813 "Could not allocate enough space for the VLDB entries\n");
3819 memcpy(((char *)tarray) + tarraysize,
3820 (char *)arrayEntries.nbulkentries_val, parraysize);
3821 tarraysize += parraysize;
3825 /* Free the bulk array */
3826 if (arrayEntries.nbulkentries_val) {
3827 free(arrayEntries.nbulkentries_val);
3828 arrayEntries.nbulkentries_val = 0;
3832 /* Here is where we now sort all the entries and print them */
3833 if (sort && (nentries > 0)) {
3834 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
3835 CompareVldbEntryByName);
3836 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
3837 MapHostToNetwork(vllist);
3838 EnumerateEntry(vllist);
3840 if (vllist->flags & VLOP_ALLOPERS)
3841 fprintf(STDOUT, " Volume is currently LOCKED \n");
3847 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
3855 register struct cmd_syndesc *as;
3857 afs_int32 apart = 0, avolid;
3858 afs_int32 aserver = 0, code, aserver1, apart1;
3860 struct VldbListByAttributes attributes;
3861 nbulkentries arrayEntries;
3862 register struct nvldbentry *vllist;
3866 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3867 afs_int32 totalBack = 0;
3868 afs_int32 totalFail = 0;
3869 int previdx = -1, error, same;
3871 struct cmd_item *ti;
3875 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3876 attributes.Mask = 0;
3878 seenprefix = (as->parms[0].items ? 1 : 0);
3879 exclude = (as->parms[3].items ? 1 : 0);
3880 seenxprefix = (as->parms[4].items ? 1 : 0);
3881 noaction = (as->parms[5].items ? 1 : 0);
3883 if (as->parms[1].items) { /* -server */
3884 aserver = GetServer(as->parms[1].items->data);
3886 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3887 as->parms[1].items->data);
3890 attributes.server = ntohl(aserver);
3891 attributes.Mask |= VLLIST_SERVER;
3894 if (as->parms[2].items) { /* -partition */
3895 apart = volutil_GetPartitionID(as->parms[2].items->data);
3897 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3898 as->parms[2].items->data);
3901 attributes.partition = apart;
3902 attributes.Mask |= VLLIST_PARTITION;
3905 /* Check to make sure the prefix and xprefix expressions compile ok */
3907 for (ti = as->parms[0].items; ti; ti = ti->next) {
3908 if (strncmp(ti->data, "^", 1) == 0) {
3909 #ifdef HAVE_POSIX_REGEX
3913 code = regcomp(&re, ti->data, REG_NOSUB);
3915 regerror(code, &re, errbuf, sizeof errbuf);
3917 "Unrecognizable -prefix regular expression: '%s': %s\n",
3923 ccode = (char *)re_comp(ti->data);
3926 "Unrecognizable -prefix regular expression: '%s': %s\n",
3935 for (ti = as->parms[4].items; ti; ti = ti->next) {
3936 if (strncmp(ti->data, "^", 1) == 0) {
3937 #ifdef HAVE_POSIX_REGEX
3941 code = regcomp(&re, ti->data, REG_NOSUB);
3943 regerror(code, &re, errbuf, sizeof errbuf);
3945 "Unrecognizable -xprefix regular expression: '%s': %s\n",
3951 ccode = (char *)re_comp(ti->data);
3954 "Unrecognizable -xprefix regular expression: '%s': %s\n",
3963 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3964 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3966 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3967 PrintError("", vcode);
3971 if (as->parms[1].items || as->parms[2].items || verbose) {
3972 fprintf(STDOUT, "%s up volumes",
3973 (noaction ? "Would have backed" : "Backing"));
3975 if (as->parms[1].items) {
3976 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
3977 } else if (as->parms[2].items) {
3978 fprintf(STDOUT, " for all servers");
3981 if (as->parms[2].items) {
3982 MapPartIdIntoName(apart, pname);
3983 fprintf(STDOUT, " partition %s", pname);
3986 if (seenprefix || (!seenprefix && seenxprefix)) {
3987 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3988 ex = (seenprefix ? exclude : !exclude);
3989 exp = (strncmp(ti->data, "^", 1) == 0);
3990 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
3991 (exp ? "expression" : "prefix"), ti->data);
3992 for (ti = ti->next; ti; ti = ti->next) {
3993 exp = (strncmp(ti->data, "^", 1) == 0);
3994 printf(" %sor %s '%s'", (ex ? "n" : ""),
3995 (exp ? "expression" : "prefix"), ti->data);
3999 if (seenprefix && seenxprefix) {
4000 ti = as->parms[4].items;
4001 exp = (strncmp(ti->data, "^", 1) == 0);
4002 fprintf(STDOUT, " %swhich match %s '%s'",
4003 (exclude ? "adding those " : "removing those "),
4004 (exp ? "expression" : "prefix"), ti->data);
4005 for (ti = ti->next; ti; ti = ti->next) {
4006 exp = (strncmp(ti->data, "^", 1) == 0);
4007 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4011 fprintf(STDOUT, " .. ");
4013 fprintf(STDOUT, "\n");
4017 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4018 vllist = &arrayEntries.nbulkentries_val[j];
4021 for (ti = as->parms[0].items; ti; ti = ti->next) {
4022 if (strncmp(ti->data, "^", 1) == 0) {
4023 #ifdef HAVE_POSIX_REGEX
4027 /* XXX -- should just do the compile once! */
4028 code = regcomp(&re, ti->data, REG_NOSUB);
4030 regerror(code, &re, errbuf, sizeof errbuf);
4032 "Error in -prefix regular expression: '%s': %s\n",
4036 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4039 ccode = (char *)re_comp(ti->data);
4042 "Error in -prefix regular expression: '%s': %s\n",
4046 match = (re_exec(vllist->name) == 1);
4050 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4060 /* Without the -exclude flag: If it matches the prefix, then
4061 * check if we want to exclude any from xprefix.
4062 * With the -exclude flag: If it matches the prefix, then
4063 * check if we want to add any from xprefix.
4065 if (match && seenxprefix) {
4066 for (ti = as->parms[4].items; ti; ti = ti->next) {
4067 if (strncmp(ti->data, "^", 1) == 0) {
4068 #ifdef HAVE_POSIX_REGEX
4072 /* XXX -- should just do the compile once! */
4073 code = regcomp(&re, ti->data, REG_NOSUB);
4075 regerror(code, &re, errbuf, sizeof errbuf);
4077 "Error in -xprefix regular expression: '%s': %s\n",
4081 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4085 ccode = (char *)re_comp(ti->data);
4088 "Error in -xprefix regular expression: '%s': %s\n",
4092 if (re_exec(vllist->name) == 1) {
4098 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4108 match = !match; /* -exclude will reverse the match */
4110 continue; /* Skip if no match */
4112 /* Print list of volumes to backup */
4114 fprintf(STDOUT, " %s\n", vllist->name);
4118 if (!(vllist->flags & RW_EXISTS)) {
4121 "Omitting to backup %s since RW volume does not exist \n",
4123 fprintf(STDOUT, "\n");
4129 avolid = vllist->volumeId[RWVOL];
4130 MapHostToNetwork(vllist);
4131 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4132 if (aserver1 == -1 || apart1 == -1) {
4133 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4139 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4142 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4148 if ((aserver && !same) || (apart && (apart != apart1))) {
4151 "Omitting to backup %s since the RW is in a different location\n",
4157 time_t now = time(0);
4158 fprintf(STDOUT, "Creating backup volume for %s on %s",
4159 vllist->name, ctime(&now));
4163 code = UV_BackupVolume(aserver1, apart1, avolid);
4165 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4171 fprintf(STDOUT, "\n");
4173 } /* process each vldb entry */
4174 fprintf(STDOUT, "done\n");
4175 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4176 (unsigned long)totalBack, (unsigned long)totalFail);
4178 if (arrayEntries.nbulkentries_val)
4179 free(arrayEntries.nbulkentries_val);
4185 register struct cmd_syndesc *as;
4188 afs_int32 aserver, code;
4190 struct VldbListByAttributes attributes;
4191 nbulkentries arrayEntries;
4192 register struct nvldbentry *vllist;
4201 attributes.Mask = 0;
4203 if (as->parms[0].items) { /* server specified */
4204 aserver = GetServer(as->parms[0].items->data);
4206 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4207 as->parms[0].items->data);
4210 attributes.server = ntohl(aserver);
4211 attributes.Mask |= VLLIST_SERVER;
4213 if (as->parms[1].items) { /* partition specified */
4214 apart = volutil_GetPartitionID(as->parms[1].items->data);
4216 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4217 as->parms[1].items->data);
4220 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4222 PrintError("", code);
4225 "vos : partition %s does not exist on the server\n",
4226 as->parms[1].items->data);
4229 attributes.partition = apart;
4230 attributes.Mask |= VLLIST_PARTITION;
4232 attributes.flag = VLOP_ALLOPERS;
4233 attributes.Mask |= VLLIST_FLAG;
4234 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4235 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4237 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4238 PrintError("", vcode);
4241 for (j = 0; j < nentries; j++) { /* process each entry */
4242 vllist = &arrayEntries.nbulkentries_val[j];
4243 volid = vllist->volumeId[RWVOL];
4245 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4246 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4248 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4250 PrintError("", vcode);
4255 MapPartIdIntoName(apart, pname);
4258 "Could not lock %lu VLDB entries of %lu locked entries\n",
4259 (unsigned long)totalE, (unsigned long)nentries);
4261 if (as->parms[0].items) {
4263 "Unlocked all the VLDB entries for volumes on server %s ",
4264 as->parms[0].items->data);
4265 if (as->parms[1].items) {
4266 MapPartIdIntoName(apart, pname);
4267 fprintf(STDOUT, "partition %s\n", pname);
4269 fprintf(STDOUT, "\n");
4271 } else if (as->parms[1].items) {
4272 MapPartIdIntoName(apart, pname);
4274 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4279 if (arrayEntries.nbulkentries_val)
4280 free(arrayEntries.nbulkentries_val);
4286 register struct cmd_syndesc *as;
4289 afs_int32 aserver, code;
4291 struct diskPartition partition;
4292 struct partList dummyPartList;
4296 aserver = GetServer(as->parms[0].items->data);
4298 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4299 as->parms[0].items->data);
4302 if (as->parms[1].items) {
4303 apart = volutil_GetPartitionID(as->parms[1].items->data);
4305 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4306 as->parms[1].items->data);
4309 dummyPartList.partId[0] = apart;
4310 dummyPartList.partFlags[0] = PARTVALID;
4314 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4316 PrintError("", code);
4319 "vos : partition %s does not exist on the server\n",
4320 as->parms[1].items->data);
4324 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
4326 PrintDiagnostics("listpart", code);
4330 for (i = 0; i < cnt; i++) {
4331 if (dummyPartList.partFlags[i] & PARTVALID) {
4332 MapPartIdIntoName(dummyPartList.partId[i], pname);
4333 code = UV_PartitionInfo(aserver, pname, &partition);
4335 fprintf(STDERR, "Could not get information on partition %s\n",
4337 PrintError("", code);
4341 "Free space on partition %s: %d K blocks out of total %d\n",
4342 pname, partition.free, partition.minFree);
4350 register struct cmd_syndesc *as;
4353 afs_int32 ip1, ip2, vcode;
4356 ip1 = GetServer(as->parms[0].items->data);
4358 fprintf(STDERR, "vos: invalid host address\n");
4362 if ((as->parms[1].items && as->parms[2].items)
4363 || (!as->parms[1].items && !as->parms[2].items)) {
4365 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
4369 if (as->parms[1].items) {
4370 ip2 = GetServer(as->parms[1].items->data);
4372 fprintf(STDERR, "vos: invalid host address\n");
4376 /* Play a trick here. If we are removing an address, ip1 will be -1
4377 * and ip2 will be the original address. This switch prevents an
4378 * older revision vlserver from removing the IP address.
4385 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
4388 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
4389 as->parms[0].items->data);
4390 if (vcode == VL_NOENT) {
4392 "vlserver does not support the remove flag or ");
4395 fprintf(STDERR, "Could not change server %s to server %s\n",
4396 as->parms[0].items->data, as->parms[1].items->data);
4398 PrintError("", vcode);
4403 fprintf(STDOUT, "Removed server %s from the VLDB\n",
4404 as->parms[0].items->data);
4406 fprintf(STDOUT, "Changed server %s to server %s\n",
4407 as->parms[0].items->data, as->parms[1].items->data);
4413 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
4414 int print, int noresolve)
4420 ListAddrByAttributes m_attrs;
4421 afs_int32 m_unique, m_nentries, *m_addrp;
4422 afs_int32 base, index;
4426 afsUUID_to_string(m_uuid, buf, sizeof(buf));
4427 printf("UUID: %s\n", buf);
4430 /* print out the list of all the server */
4431 addrp = (afs_int32 *) addrs->bulkaddrs_val;
4432 for (i = 0; i < nentries; i++, addrp++) {
4433 /* If it is a multihomed address, then we will need to
4434 * get the addresses for this multihomed server from
4435 * the vlserver and print them.
4437 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
4438 /* Get the list of multihomed fileservers */
4439 base = (*addrp >> 16) & 0xff;
4440 index = (*addrp) & 0xffff;
4442 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
4443 && (index <= VL_MHSRV_PERBLK)) {
4444 m_attrs.Mask = VLADDR_INDEX;
4445 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
4447 m_addrs.bulkaddrs_val = 0;
4448 m_addrs.bulkaddrs_len = 0;
4450 ubik_Call(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
4451 &m_unique, &m_nentries, &m_addrs);
4454 "vos: could not list the multi-homed server addresses\n");
4455 PrintError("", vcode);
4458 /* Print the list */
4459 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
4460 for (j = 0; j < m_nentries; j++, m_addrp++) {
4461 *m_addrp = htonl(*m_addrp);
4464 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
4466 printf("%s ", hostutil_GetNameByINet(*m_addrp));
4470 printf("<unknown>\n");
4479 /* Otherwise, it is a non-multihomed entry and contains
4480 * the IP address of the server - print it.
4482 *addrp = htonl(*addrp);
4485 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
4487 printf("%s\n", hostutil_GetNameByINet(*addrp));
4499 register struct cmd_syndesc *as;
4502 afs_int32 i, noresolve = 0, printuuid = 0;
4505 ListAddrByAttributes m_attrs;
4506 afsUUID m_uuid, askuuid;
4507 afs_int32 m_unique, m_nentries;
4509 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
4510 m_attrs.Mask = VLADDR_INDEX;
4512 memset(&m_addrs, 0, sizeof(bulkaddrs));
4513 memset(&askuuid, 0, sizeof(afsUUID));
4514 if (as->parms[0].items) {
4516 afsUUID_from_string(as->parms[0].items->data, &askuuid);
4517 m_attrs.Mask = VLADDR_UUID;
4518 m_attrs.uuid = askuuid;
4520 if (as->parms[1].items) {
4524 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
4526 fprintf(stderr, "Can't get host info for '%s'\n",
4527 as->parms[1].items->data);
4530 memcpy(&saddr, he->h_addr, 4);
4531 m_attrs.Mask = VLADDR_IPADDR;
4532 m_attrs.ipaddr = ntohl(saddr);
4534 if (as->parms[2].items) {
4537 if (as->parms[3].items) {
4541 m_addrs.bulkaddrs_val = 0;
4542 m_addrs.bulkaddrs_len = 0;
4545 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &m_unique, &nentries,
4548 fprintf(STDERR, "vos: could not list the server addresses\n");
4549 PrintError("", vcode);
4554 m_addrs.bulkaddrs_val = 0;
4555 m_addrs.bulkaddrs_len = 0;
4561 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
4562 &m_unique, &m_nentries, &m_addrs);
4563 if (vcode == VL_NOENT) {
4569 if (vcode == VL_INDEXERANGE) {
4574 fprintf(STDERR, "vos: could not list the server addresses\n");
4575 PrintError("", vcode);
4579 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
4582 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
4591 register struct cmd_syndesc *as;
4594 afs_int32 avolid, vcode, err;
4596 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4599 PrintError("", err);
4601 fprintf(STDERR, "vos: can't find volume '%s'\n",
4602 as->parms[0].items->data);
4605 vcode = ubik_Call(VL_SetLock, cstruct, 0, avolid, -1, VLOP_DELETE);
4607 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
4608 as->parms[0].items->data);
4609 PrintError("", vcode);
4612 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
4613 as->parms[0].items->data);
4619 register struct cmd_syndesc *as;
4622 afs_int32 partition = -1;
4623 afs_int32 server, volid, code, i, same;
4624 struct nvldbentry entry, storeEntry;
4627 afs_int32 rwserver = 0;
4628 afs_int32 rwpartition;
4630 afs_int32 roserver = 0;
4631 afs_int32 ropartition;
4633 struct rx_connection *aconn;
4636 server = GetServer(as->parms[0].items->data);
4638 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4639 as->parms[0].items->data);
4642 partition = volutil_GetPartitionID(as->parms[1].items->data);
4643 if (partition < 0) {
4644 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4645 as->parms[1].items->data);
4648 if (!IsPartValid(partition, server, &code)) {
4650 PrintError("", code);
4653 "vos : partition %s does not exist on the server\n",
4654 as->parms[1].items->data);
4657 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
4660 PrintError("", code);
4662 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
4663 as->parms[0].items->data);
4666 if (as->parms[3].items)
4669 vcode = VLDB_GetEntryByID(volid, -1, &entry);
4672 "Could not fetch the entry for volume %lu from VLDB\n",
4673 (unsigned long)volid);
4674 PrintError("convertROtoRW", code);
4678 /* use RO volid even if user specified RW or BK volid */
4680 if (volid != entry.volumeId[ROVOL])
4681 volid = entry.volumeId[ROVOL];
4683 MapHostToNetwork(&entry);
4684 for (i = 0; i < entry.nServers; i++) {
4685 if (entry.serverFlags[i] & ITSRWVOL) {
4687 rwserver = entry.serverNumber[i];
4688 rwpartition = entry.serverPartition[i];
4690 if (entry.serverFlags[i] & ITSROVOL) {
4691 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
4694 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4700 roserver = entry.serverNumber[i];
4701 ropartition = entry.serverPartition[i];
4707 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
4709 if (ropartition != partition) {
4711 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
4712 ropartition, partition);
4717 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
4718 hostutil_GetNameByINet(rwserver),
4719 volutil_PartitionName(rwpartition));
4721 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
4723 while (!(dc == EOF || dc == '\n'))
4724 dc = getchar(); /* goto end of line */
4725 if ((c != 'y') && (c != 'Y')) {
4726 fprintf(STDERR, "aborted.\n");
4733 ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL,
4735 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4736 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
4739 "Converting RO volume %lu to RW volume failed with code %d\n",
4740 (unsigned long)volid, code);
4741 PrintError("convertROtoRW ", code);
4744 entry.serverFlags[roindex] = ITSRWVOL;
4745 entry.flags |= RW_EXISTS;
4746 entry.flags &= ~BACK_EXISTS;
4749 if (rwindex != entry.nServers) {
4750 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
4751 entry.serverPartition[rwindex] =
4752 entry.serverPartition[entry.nServers];
4753 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
4754 entry.serverNumber[entry.nServers] = 0;
4755 entry.serverPartition[entry.nServers] = 0;
4756 entry.serverFlags[entry.nServers] = 0;
4759 entry.flags &= ~RO_EXISTS;
4760 for (i = 0; i < entry.nServers; i++) {
4761 if (entry.serverFlags[i] & ITSROVOL) {
4762 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
4763 entry.flags |= RO_EXISTS;
4766 MapNetworkToHost(&entry, &storeEntry);
4768 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
4769 (LOCKREL_OPCODE | LOCKREL_AFSID |
4770 LOCKREL_TIMESTAMP));
4773 "Warning: volume converted, but vldb update failed with code %d!\n",
4776 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
4778 PrintDiagnostics("unlock", vcode);
4785 register struct cmd_syndesc *as;
4787 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
4788 struct nvldbentry entry;
4789 volintSize vol_size;
4791 rx_SetRxDeadTime(60 * 10);
4792 for (i = 0; i < MAXSERVERS; i++) {
4793 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
4796 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
4797 if (rxConn->service)
4798 rxConn->service->connDeadTime = rx_connDeadTime;
4801 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4804 PrintError("", err);
4806 fprintf(STDERR, "vos: can't find volume '%s'\n",
4807 as->parms[0].items->data);
4811 if (as->parms[1].items || as->parms[2].items) {
4812 if (!as->parms[1].items || !as->parms[2].items) {
4814 "Must specify both -server and -partition options\n");
4817 aserver = GetServer(as->parms[2].items->data);
4819 fprintf(STDERR, "Invalid server name\n");
4822 apart = volutil_GetPartitionID(as->parms[1].items->data);
4824 fprintf(STDERR, "Invalid partition name\n");
4828 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
4835 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
4836 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
4838 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
4839 as->parms[1].items->data, code);
4844 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
4846 if (as->parms[3].items) { /* do the dump estimate */
4847 #ifdef AFS_64BIT_ENV
4848 vol_size.dump_size = 0;
4850 FillInt64(vol_size.dump_size,0, 1);
4852 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
4854 PrintDiagnostics("size", code);
4857 /* presumably the size info is now gathered in pntr */
4858 /* now we display it */
4860 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
4868 PrintDiagnostics(astring, acode)
4872 if (acode == EACCES) {
4874 "You are not authorized to perform the 'vos %s' command (%d)\n",
4877 fprintf(STDERR, "Error in vos %s command.\n", astring);
4878 PrintError("", acode);
4885 MyBeforeProc(as, arock)
4886 struct cmd_syndesc *as;
4889 register char *tcell;
4890 register afs_int32 code;
4891 register afs_int32 sauth;
4893 /* Initialize the ubik_client connection */
4894 rx_SetRxDeadTime(90);
4895 cstruct = (struct ubik_client *)0;
4899 if (as->parms[12].items) /* if -cell specified */
4900 tcell = as->parms[12].items->data;
4901 if (as->parms[14].items) /* -serverauth specified */
4903 if (as->parms[16].items) /* -crypt specified */
4906 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
4907 &cstruct, UV_SetSecurity))) {
4908 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
4909 (unsigned long)code);
4913 if (as->parms[15].items) /* -verbose flag set */
4923 /* this sucks but it works for now.
4928 #include "AFS_component_version_number.c"
4934 register afs_int32 code;
4936 register struct cmd_syndesc *ts;
4938 #ifdef AFS_AIX32_ENV
4940 * The following signal action for AIX is necessary so that in case of a
4941 * crash (i.e. core is generated) we can include the user's data section
4942 * in the core dump. Unfortunately, by default, only a partial core is
4943 * generated which, in many cases, isn't too useful.
4945 struct sigaction nsa;
4947 sigemptyset(&nsa.sa_mask);
4948 nsa.sa_handler = SIG_DFL;
4949 nsa.sa_flags = SA_FULLDUMP;
4950 sigaction(SIGSEGV, &nsa, NULL);
4953 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
4955 cmd_SetBeforeProc(MyBeforeProc, NULL);
4957 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
4958 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4959 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4960 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
4961 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
4962 "initial quota (KB)");
4964 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
4968 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
4969 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
4970 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
4971 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4975 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
4976 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4977 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4978 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
4979 "partition name on source");
4980 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
4981 "machine name on destination");
4982 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
4983 "partition name on destination");
4986 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
4987 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
4988 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4989 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
4990 "partition name on source");
4991 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
4992 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
4993 "machine name on destination");
4994 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
4995 "partition name on destination");
4998 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
4999 "make backup of a volume");
5000 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5003 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
5004 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5005 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5006 "force a complete release");
5009 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
5010 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5011 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5012 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5013 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5014 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5015 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5016 "dump a clone of the volume");
5019 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
5020 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5021 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5022 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5023 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5024 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5025 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5026 "abort | full | incremental");
5027 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5028 "leave restored volume offline");
5029 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5030 "make restored volume read-only");
5033 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
5034 "release lock on VLDB entry for a volume");
5035 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5038 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
5039 "change an RW volume's location in the VLDB");
5040 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5041 "machine name for new location");
5042 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5043 "partition name for new location");
5044 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5047 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5048 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5049 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5050 "partition name for new site");
5051 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5054 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5055 "remove a replication site");
5056 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5057 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5058 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5061 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5062 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5065 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5066 "list volumes on server (bypass VLDB)");
5067 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5068 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5069 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5070 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5071 "list all normal volume fields");
5072 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5073 "generate minimal information");
5074 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5075 "list extended volume fields");
5076 #ifdef FULL_LISTVOL_SWITCH
5077 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5078 "machine readable format");
5079 #endif /* FULL_LISTVOL_SWITCH */
5082 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5083 "synchronize VLDB with server");
5084 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5085 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5086 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5089 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5090 "synchronize server with VLDB");
5091 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5092 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5095 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5096 "everything about the volume");
5097 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5098 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5099 "list extended volume fields");
5100 #ifdef FULL_LISTVOL_SWITCH
5101 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5102 "machine readable format");
5103 #endif /* FULL_LISTVOL_SWITCH */
5105 cmd_CreateAlias(ts, "volinfo");
5107 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5108 "change volume info fields");
5109 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5110 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5111 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5114 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5115 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5116 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5117 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5118 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5119 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5122 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5123 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5124 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5125 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5128 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5129 "delete the volume, don't bother with VLDB");
5130 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5131 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5132 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5133 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5134 "force deletion of bad volumes");
5135 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5136 "also delete backup volume if one is found");
5139 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5140 "report on volser status");
5141 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5144 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5145 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5146 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5149 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5150 "list volumes in the VLDB");
5151 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5152 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5153 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5154 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5155 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5156 "generate minimal information");
5157 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5158 "do not alphabetically sort the volume names");
5161 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5162 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5163 "common prefix on volume(s)");
5164 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5165 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5166 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5167 "exclude common prefix volumes");
5168 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5169 "negative prefix on volume(s)");
5170 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5173 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5174 "delete VLDB entry for a volume");
5175 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5176 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5177 "prefix of the volume whose VLDB entry is to be deleted");
5178 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5179 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5180 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
5184 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
5185 "list partition information");
5186 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5187 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5190 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
5191 "unlock all the locked entries in the VLDB");
5192 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5193 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5196 ts = cmd_CreateSyntax("lock", LockEntry, 0,
5197 "lock VLDB entry for a volume");
5198 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5201 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
5202 "change the IP address of a file server");
5203 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
5204 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
5205 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
5206 "remove the IP address from the VLDB");
5209 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
5210 "list the IP address of all file servers registered in the VLDB");
5211 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
5212 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
5213 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
5214 "don't resolve addresses");
5215 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
5216 "print uuid of hosts");
5219 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
5220 "convert a RO volume into a RW volume (after loss of old RW volume)");
5221 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5222 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5223 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5224 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
5227 ts = cmd_CreateSyntax("size", Sizes, 0,
5228 "obtain various sizes of the volume.");
5229 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5230 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5231 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5232 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
5233 "Obtain the size of the dump");
5234 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5237 code = cmd_Dispatch(argc, argv);
5239 /* Shut down the ubik_client and rx connections */
5241 (void)ubik_ClientDestroy(cstruct);
5247 exit((code ? -1 : 0));