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>
26 #include <arpa/inet.h>
30 #include <sys/statfs.h>
46 #include <rx/rx_globals.h>
48 #include <afs/vlserver.h>
50 #include <afs/cellconfig.h>
52 #include <afs/afsutil.h>
54 #include <afs/afsint.h>
64 #include "volser_prototypes.h"
66 #ifdef HAVE_POSIX_REGEX
80 #define COMMONPARMS cmd_Seek(ts, 12);\
81 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
82 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
83 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
84 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
85 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
87 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
91 struct rx_connection *tconn;
93 extern struct ubik_client *cstruct;
96 static struct tqHead busyHead, notokHead;
99 qInit(struct tqHead *ahead)
101 memset((char *)ahead, 0, sizeof(struct tqHead));
107 qPut(struct tqHead *ahead, afs_int32 volid)
111 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
112 elem->next = ahead->next;
120 qGet(struct tqHead *ahead, afs_int32 *volid)
124 if (ahead->count <= 0)
126 *volid = ahead->next->volid;
128 ahead->next = tmp->next;
134 /* returns 1 if <filename> exists else 0 */
136 FileExists(char *filename)
142 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
146 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
154 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
156 VolNameOK(char *name)
161 total = strlen(name);
162 if (!strcmp(&name[total - 9], ".readonly")) {
164 } else if (!strcmp(&name[total - 7], ".backup")) {
171 /* return 1 if name is a number else 0 */
173 IsNumeric(char *name)
181 for (i = 0; i < len; i++) {
182 if (*ptr < '0' || *ptr > '9') {
194 * Parse a server name/address and return the address in HOST BYTE order
197 GetServer(char *aname)
199 register struct hostent *th;
202 register afs_int32 code;
203 char hostname[MAXHOSTCHARS];
205 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
207 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
208 addr = ntohl(addr); /* convert to host order */
210 th = gethostbyname(aname);
213 memcpy(&addr, th->h_addr, sizeof(addr));
216 if (addr == htonl(0x7f000001)) { /* local host */
217 code = gethostname(hostname, MAXHOSTCHARS);
220 th = gethostbyname(hostname); /* returns host byte order */
223 memcpy(&addr, th->h_addr, sizeof(addr));
230 GetVolumeType(char *aname)
233 if (!strcmp(aname, "ro"))
235 else if (!strcmp(aname, "rw"))
237 else if (!strcmp(aname, "bk"))
244 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
246 struct partList dummyPartList;
252 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
255 for (i = 0; i < cnt; i++) {
256 if (dummyPartList.partFlags[i] & PARTVALID)
257 if (dummyPartList.partId[i] == partId)
265 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
266 * associated with <call> */
268 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
270 char *buffer = (char *)0;
275 buffer = (char *)malloc(blksize);
277 fprintf(STDERR, "malloc failed\n");
281 while (!error && !done) {
282 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
285 FD_SET((int)(ufd->handle), &in);
286 /* don't timeout if read blocks */
287 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
289 error = USD_READ(ufd, buffer, blksize, &nbytes);
291 fprintf(STDERR, "File system read failed\n");
298 if (rx_Write(call, buffer, nbytes) != nbytes) {
308 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
309 * writes it out to the volume. */
311 WriteData(struct rx_call *call, char *rock)
316 afs_int32 error, code;
322 if (!filename || !*filename) {
323 usd_StandardInput(&ufd);
327 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
330 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
333 fprintf(STDERR, "Could not access file '%s'\n", filename);
338 code = SendFile(ufd, call, blksize);
345 code = USD_CLOSE(ufd);
347 fprintf(STDERR, "Could not close dump file %s\n",
348 (filename && *filename) ? filename : "STDOUT");
356 /* Receive data from <call> stream into file associated
357 * with <fd> <blksize>
360 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
364 afs_uint32 bytesleft, w;
367 buffer = (char *)malloc(blksize);
369 fprintf(STDERR, "memory allocation failed\n");
373 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
374 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
375 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
378 FD_SET((int)(ufd->handle), &out);
379 /* don't timeout if write blocks */
380 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
383 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
385 fprintf(STDERR, "File system write failed\n");
398 DumpFunction(struct rx_call *call, char *filename)
400 usd_handle_t ufd; /* default is to stdout */
401 afs_int32 error = 0, code;
406 /* Open the output file */
407 if (!filename || !*filename) {
408 usd_StandardOutput(&ufd);
413 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
417 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
420 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
423 fprintf(STDERR, "Could not create file '%s'\n", filename);
424 ERROR_EXIT(VOLSERBADOP);
428 code = ReceiveFile(ufd, call, blksize);
433 /* Close the output file */
435 code = USD_CLOSE(ufd);
437 fprintf(STDERR, "Could not close dump file %s\n",
438 (filename && *filename) ? filename : "STDIN");
448 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
451 afs_int32 server, part;
452 int *totalOK, *totalNotOK, *totalBusy;
453 int fast, longlist, disp;
458 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
459 } else if (longlist) {
460 if (pntr->status == VOK) {
461 fprintf(STDOUT, "%-32s ", pntr->name);
462 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
464 fprintf(STDOUT, "RW ");
466 fprintf(STDOUT, "RO ");
468 fprintf(STDOUT, "BK ");
469 fprintf(STDOUT, "%10d K ", pntr->size);
470 if (pntr->inUse == 1) {
471 fprintf(STDOUT, "On-line");
474 fprintf(STDOUT, "Off-line");
477 if (pntr->needsSalvaged == 1)
478 fprintf(STDOUT, "**needs salvage**");
479 fprintf(STDOUT, "\n");
480 MapPartIdIntoName(part, pname);
481 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
483 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
484 (unsigned long)pntr->parentID,
485 (unsigned long)pntr->cloneID,
486 (unsigned long)pntr->backupID);
487 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
488 fprintf(STDOUT, " Creation %s",
489 ctime((time_t *) & pntr->creationDate));
490 #ifdef FULL_LISTVOL_SWITCH
491 fprintf(STDOUT, " Copy %s",
492 ctime((time_t *) & pntr->copyDate));
493 if (!pntr->backupDate)
494 fprintf(STDOUT, " Backup Never\n");
496 fprintf(STDOUT, " Backup %s",
497 ctime((time_t *) & pntr->backupDate));
498 if (pntr->accessDate)
499 fprintf(STDOUT, " Last Access %s",
500 ctime((time_t *) & pntr->accessDate));
502 if (!pntr->updateDate)
503 fprintf(STDOUT, " Last Update Never\n");
505 fprintf(STDOUT, " Last Update %s",
506 ctime((time_t *) & pntr->updateDate));
508 " %d accesses in the past day (i.e., vnode references)\n",
511 } else if (pntr->status == VBUSY) {
513 qPut(&busyHead, pntr->volid);
515 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
516 (unsigned long)pntr->volid);
519 qPut(¬okHead, pntr->volid);
521 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
522 (unsigned long)pntr->volid);
524 fprintf(STDOUT, "\n");
525 } else { /* default listing */
526 if (pntr->status == VOK) {
527 fprintf(STDOUT, "%-32s ", pntr->name);
528 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
530 fprintf(STDOUT, "RW ");
532 fprintf(STDOUT, "RO ");
534 fprintf(STDOUT, "BK ");
535 fprintf(STDOUT, "%10d K ", pntr->size);
536 if (pntr->inUse == 1) {
537 fprintf(STDOUT, "On-line");
540 fprintf(STDOUT, "Off-line");
543 if (pntr->needsSalvaged == 1)
544 fprintf(STDOUT, "**needs salvage**");
545 fprintf(STDOUT, "\n");
546 } else if (pntr->status == VBUSY) {
548 qPut(&busyHead, pntr->volid);
550 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
551 (unsigned long)pntr->volid);
554 qPut(¬okHead, pntr->volid);
556 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
557 (unsigned long)pntr->volid);
562 /*------------------------------------------------------------------------
563 * PRIVATE XDisplayFormat
566 * Display the contents of one extended volume info structure.
569 * a_xInfoP : Ptr to extended volume info struct to print.
570 * a_servID : Server ID to print.
571 * a_partID : Partition ID to print.
572 * a_totalOKP : Ptr to total-OK counter.
573 * a_totalNotOKP : Ptr to total-screwed counter.
574 * a_totalBusyP : Ptr to total-busy counter.
575 * a_fast : Fast listing?
576 * a_int32 : Int32 listing?
577 * a_showProblems : Show volume problems?
583 * Nothing interesting.
587 *------------------------------------------------------------------------*/
590 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
591 a_totalBusyP, a_fast, a_int32, a_showProblems)
592 volintXInfo *a_xInfoP;
602 { /*XDisplayFormat */
610 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
611 } else if (a_int32) {
613 * Fully-detailed listing.
615 if (a_xInfoP->status == VOK) {
617 * Volume's status is OK - all the fields are valid.
619 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
620 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
621 if (a_xInfoP->type == 0)
622 fprintf(STDOUT, "RW ");
623 if (a_xInfoP->type == 1)
624 fprintf(STDOUT, "RO ");
625 if (a_xInfoP->type == 2)
626 fprintf(STDOUT, "BK ");
627 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
628 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
629 if (a_xInfoP->inUse == 1) {
630 fprintf(STDOUT, "On-line");
633 fprintf(STDOUT, "Off-line");
636 fprintf(STDOUT, "\n");
637 MapPartIdIntoName(a_partID, pname);
638 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
640 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
641 (unsigned long)a_xInfoP->parentID,
642 (unsigned long)a_xInfoP->cloneID,
643 (unsigned long)a_xInfoP->backupID);
644 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
645 fprintf(STDOUT, " Creation %s",
646 ctime((time_t *) & a_xInfoP->creationDate));
647 #ifdef FULL_LISTVOL_SWITCH
648 fprintf(STDOUT, " Copy %s",
649 ctime((time_t *) & a_xInfoP->copyDate));
650 if (!a_xInfoP->backupDate)
651 fprintf(STDOUT, " Backup Never\n");
653 fprintf(STDOUT, " Backup %s",
654 ctime((time_t *) & a_xInfoP->backupDate));
655 if (a_xInfoP->accessDate)
656 fprintf(STDOUT, " Last Access %s",
657 ctime((time_t *) & a_xInfoP->accessDate));
659 if (!a_xInfoP->updateDate)
660 fprintf(STDOUT, " Last Update Never\n");
662 fprintf(STDOUT, " Last Update %s",
663 ctime((time_t *) & a_xInfoP->updateDate));
665 " %d accesses in the past day (i.e., vnode references)\n",
670 * Print all the read/write and authorship stats.
672 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
674 " |-------------------------------------------|\n");
676 " | Same Network | Diff Network |\n");
678 " |----------|----------|----------|----------|\n");
680 " | Total | Auth | Total | Auth |\n");
682 " |----------|----------|----------|----------|\n");
683 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
684 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
685 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
686 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
687 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
688 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
689 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
690 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
691 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
692 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
694 " |-------------------------------------------|\n\n");
697 " Writes Affecting Authorship\n");
699 " |-------------------------------------------|\n");
701 " | File Authorship | Directory Authorship|\n");
703 " |----------|----------|----------|----------|\n");
705 " | Same | Diff | Same | Diff |\n");
707 " |----------|----------|----------|----------|\n");
708 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
709 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
710 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
711 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
712 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
713 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
714 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
715 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
716 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
717 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
718 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
719 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
720 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
721 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
722 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
723 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
724 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
725 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
726 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
727 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
728 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
729 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
730 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
731 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
732 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
733 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
734 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
735 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
736 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
737 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
739 " |-------------------------------------------|\n");
740 } /*Volume status OK */
741 else if (a_xInfoP->status == VBUSY) {
743 qPut(&busyHead, a_xInfoP->volid);
745 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
746 (unsigned long)a_xInfoP->volid);
750 qPut(¬okHead, a_xInfoP->volid);
752 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
753 (unsigned long)a_xInfoP->volid);
754 } /*Screwed volume */
755 fprintf(STDOUT, "\n");
761 if (a_xInfoP->status == VOK) {
762 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
763 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
764 if (a_xInfoP->type == 0)
765 fprintf(STDOUT, "RW ");
766 if (a_xInfoP->type == 1)
767 fprintf(STDOUT, "RO ");
768 if (a_xInfoP->type == 2)
769 fprintf(STDOUT, "BK ");
770 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
771 if (a_xInfoP->inUse == 1) {
772 fprintf(STDOUT, "On-line");
775 fprintf(STDOUT, "Off-line");
778 fprintf(STDOUT, "\n");
780 else if (a_xInfoP->status == VBUSY) {
782 qPut(&busyHead, a_xInfoP->volid);
784 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
785 (unsigned long)a_xInfoP->volid);
789 qPut(¬okHead, a_xInfoP->volid);
791 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
792 (unsigned long)a_xInfoP->volid);
793 } /*Screwed volume */
794 } /*Default listing */
795 } /*XDisplayFormat */
797 #ifdef FULL_LISTVOL_SWITCH
799 DisplayFormat2(server, partition, pntr)
800 long server, partition;
803 static long server_cache = -1, partition_cache = -1;
804 static char hostname[256], address[32], pname[16];
806 if (server != server_cache) {
810 strcpy(hostname, hostutil_GetNameByINet(server));
811 strcpy(address, inet_ntoa(s));
812 server_cache = server;
814 if (partition != partition_cache) {
815 MapPartIdIntoName(partition, pname);
816 partition_cache = partition;
820 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
821 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
822 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
823 fprintf(STDOUT, "part\t\t%s\n", pname);
824 switch (pntr->status) {
826 fprintf(STDOUT, "status\t\tOK\n");
829 fprintf(STDOUT, "status\t\tBUSY\n");
832 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
835 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
836 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
837 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
838 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
839 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
840 /* 0xD3 is from afs/volume.h since I had trouble including the file */
841 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
842 switch (pntr->type) {
844 fprintf(STDOUT, "type\t\tRW\n");
847 fprintf(STDOUT, "type\t\tRO\n");
850 fprintf(STDOUT, "type\t\tBK\n");
853 fprintf(STDOUT, "type\t\t?\n");
856 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
857 ctime(&pntr->creationDate));
858 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
859 ctime(&pntr->accessDate));
860 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
861 ctime(&pntr->updateDate));
862 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
863 ctime(&pntr->backupDate));
864 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
865 ctime(&pntr->copyDate));
866 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
867 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
868 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
869 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
870 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
871 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
872 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
873 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
874 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
879 DisplayVolumes2(server, partition, pntr, count)
881 long server, partition, count;
885 for (i = 0; i < count; i++) {
886 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
887 DisplayFormat2(server, partition, pntr);
888 fprintf(STDOUT, "END_OF_ENTRY\n\n");
893 #endif /* FULL_LISTVOL_SWITCH */
896 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
897 afs_int32 server, part;
899 afs_int32 count, longlist, fast;
902 int totalOK, totalNotOK, totalBusy, i;
910 for (i = 0; i < count; i++) {
911 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
916 while (busyHead.count) {
917 qGet(&busyHead, &volid);
918 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
919 (unsigned long)volid);
923 while (notokHead.count) {
924 qGet(¬okHead, &volid);
925 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
926 (unsigned long)volid);
930 fprintf(STDOUT, "\n");
933 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
934 totalOK, totalNotOK, totalBusy);
939 /*------------------------------------------------------------------------
940 * PRIVATE XDisplayVolumes
943 * Display extended volume information.
946 * a_servID : Pointer to the Rx call we're performing.
947 * a_partID : Partition for which we want the extended list.
948 * a_xInfoP : Ptr to extended volume info.
949 * a_count : Number of volume records contained above.
950 * a_int32 : Int32 listing generated?
951 * a_fast : Fast listing generated?
952 * a_quiet : Quiet listing generated?
958 * Nothing interesting.
962 *------------------------------------------------------------------------*/
965 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
969 volintXInfo *a_xInfoP;
975 { /*XDisplayVolumes */
977 int totalOK; /*Total OK volumes */
978 int totalNotOK; /*Total screwed volumes */
979 int totalBusy; /*Total busy volumes */
980 int i; /*Loop variable */
981 afs_int32 volid; /*Current volume ID */
984 * Initialize counters and (global!!) queues.
993 * Display each volume in the list.
995 for (i = 0; i < a_count; i++) {
996 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
997 &totalBusy, a_fast, a_int32, 0);
1002 * If any volumes were found to be busy or screwed, display them.
1005 while (busyHead.count) {
1006 qGet(&busyHead, &volid);
1007 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1008 (unsigned long)volid);
1012 while (notokHead.count) {
1013 qGet(¬okHead, &volid);
1014 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1015 (unsigned long)volid);
1020 fprintf(STDOUT, "\n");
1023 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1024 totalOK, totalNotOK, totalBusy);
1028 } /*XDisplayVolumes */
1030 /* set <server> and <part> to the correct values depending on
1031 * <voltype> and <entry> */
1033 GetServerAndPart(entry, voltype, server, part, previdx)
1034 struct nvldbentry *entry;
1035 afs_int32 *server, *part;
1039 int i, istart, vtype;
1044 /* Doesn't check for non-existance of backup volume */
1045 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1047 istart = 0; /* seach the entire entry */
1050 /* Seach from beginning of entry or pick up where we left off */
1051 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1054 for (i = istart; i < entry->nServers; i++) {
1055 if (entry->serverFlags[i] & vtype) {
1056 *server = entry->serverNumber[i];
1057 *part = entry->serverPartition[i];
1063 /* Didn't find any, return -1 */
1069 PostVolumeStats(entry)
1070 struct nvldbentry *entry;
1072 SubEnumerateEntry(entry);
1073 /* Check for VLOP_ALLOPERS */
1074 if (entry->flags & VLOP_ALLOPERS)
1075 fprintf(STDOUT, " Volume is currently LOCKED \n");
1079 /*------------------------------------------------------------------------
1080 * PRIVATE XVolumeStats
1083 * Display extended volume information.
1086 * a_xInfoP : Ptr to extended volume info.
1087 * a_entryP : Ptr to the volume's VLDB entry.
1088 * a_srvID : Server ID.
1089 * a_partID : Partition ID.
1090 * a_volType : Type of volume to print.
1096 * Nothing interesting.
1100 *------------------------------------------------------------------------*/
1103 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1104 volintXInfo *a_xInfoP;
1105 struct nvldbentry *a_entryP;
1112 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1114 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1115 a_srvID, /*Server ID to print */
1116 a_partID, /*Partition ID to print */
1117 &totalOK, /*Ptr to total-OK counter */
1118 &totalNotOK, /*Ptr to total-screwed counter */
1119 &totalBusy, /*Ptr to total-busy counter */
1120 0, /*Don't do a fast listing */
1121 1, /*Do a long listing */
1122 1); /*Show volume problems */
1128 VolumeStats(pntr, entry, server, part, voltype)
1130 struct nvldbentry *entry;
1132 afs_int32 server, part;
1134 int totalOK, totalNotOK, totalBusy;
1136 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1141 /* command to forcibly remove a volume */
1144 register struct cmd_syndesc *as;
1146 register afs_int32 code;
1147 afs_int32 volID, err;
1152 server = GetServer(tp = as->parms[0].items->data);
1154 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1158 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1160 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1164 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1167 PrintError("", err);
1170 "vos: could not parse '%s' as a numeric volume ID", tp);
1175 "vos: forcibly removing all traces of volume %d, please wait...",
1178 code = UV_NukeVolume(server, partID, volID);
1180 fprintf(STDOUT, "done.\n");
1182 fprintf(STDOUT, "failed with code %d.\n", code);
1187 /*------------------------------------------------------------------------
1188 * PRIVATE ExamineVolume
1191 * Routine used to examine a single volume, contacting the VLDB as
1192 * well as the Volume Server.
1195 * as : Ptr to parsed command line arguments.
1198 * 0 for a successful operation,
1199 * Otherwise, one of the ubik or VolServer error values.
1202 * Nothing interesting.
1206 *------------------------------------------------------------------------
1210 register struct cmd_syndesc *as;
1212 struct nvldbentry entry;
1213 afs_int32 vcode = 0;
1214 volintInfo *pntr = (volintInfo *) 0;
1215 volintXInfo *xInfoP = (volintXInfo *) 0;
1217 afs_int32 code, err, error = 0;
1218 int voltype, foundserv = 0, foundentry = 0;
1219 afs_int32 aserver, apart;
1221 int wantExtendedInfo; /*Do we want extended vol info? */
1223 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1225 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1228 PrintError("", err);
1230 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1231 as->parms[0].items->data);
1236 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1237 (unsigned long)volid);
1240 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1243 "Could not fetch the entry for volume number %lu from VLDB \n",
1244 (unsigned long)volid);
1248 fprintf(STDOUT, "done\n");
1249 MapHostToNetwork(&entry);
1251 if (entry.volumeId[RWVOL] == volid)
1253 else if (entry.volumeId[BACKVOL] == volid)
1255 else /* (entry.volumeId[ROVOL] == volid) */
1258 do { /* do {...} while (voltype == ROVOL) */
1259 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1260 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1261 * If its a RO vol, get the next RO entry.
1263 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1264 &aserver, &apart, &previdx);
1265 if (previdx == -1) { /* searched all entries */
1267 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1268 as->parms[0].items->data);
1275 /* Get information about the volume from the server */
1277 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1278 hostutil_GetNameByINet(aserver));
1281 if (wantExtendedInfo)
1282 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1284 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1286 fprintf(STDOUT, "done\n");
1290 if (code == ENODEV) {
1291 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1292 /* The VLDB says there is no backup volume and its not on disk */
1293 fprintf(STDERR, "Volume %s does not exist\n",
1294 as->parms[0].items->data);
1298 "Volume does not exist on server %s as indicated by the VLDB\n",
1299 hostutil_GetNameByINet(aserver));
1302 PrintDiagnostics("examine", code);
1304 fprintf(STDOUT, "\n");
1307 if (wantExtendedInfo)
1308 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1310 #ifdef FULL_LISTVOL_SWITCH
1311 if (as->parms[2].items) {
1312 DisplayFormat2(aserver, apart, pntr);
1313 EnumerateEntry(&entry);
1315 #endif /* FULL_LISTVOL_SWITCH */
1316 VolumeStats(pntr, &entry, aserver, apart, voltype);
1318 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1319 /* The VLDB says there is no backup volume yet we found one on disk */
1320 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1321 as->parms[0].items->data);
1330 } while (voltype == ROVOL);
1333 fprintf(STDERR, "Dump only information from VLDB\n\n");
1334 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1336 PostVolumeStats(&entry);
1341 /*------------------------------------------------------------------------
1345 * Routine used to change the status of a single volume.
1348 * as : Ptr to parsed command line arguments.
1351 * 0 for a successful operation,
1352 * Otherwise, one of the ubik or VolServer error values.
1355 * Nothing interesting.
1359 *------------------------------------------------------------------------
1363 register struct cmd_syndesc *as;
1365 struct nvldbentry entry;
1366 afs_int32 vcode = 0;
1369 afs_int32 code, err;
1370 afs_int32 aserver, apart;
1373 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1376 PrintError("", err);
1378 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1379 as->parms[0].items->data);
1383 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1386 "Could not fetch the entry for volume number %lu from VLDB \n",
1387 (unsigned long)volid);
1390 MapHostToNetwork(&entry);
1392 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1393 if (previdx == -1) {
1394 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1395 as->parms[0].items->data);
1399 init_volintInfo(&info);
1403 if (as->parms[1].items) {
1405 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1407 fprintf(STDERR, "invalid quota value\n");
1411 if (as->parms[2].items) {
1415 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1418 "Could not update volume info fields for volume number %lu\n",
1419 (unsigned long)volid);
1423 /*------------------------------------------------------------------------
1427 * Brings a volume online.
1430 * as : Ptr to parsed command line arguments.
1433 * 0 for a successful operation,
1436 * Nothing interesting.
1440 *------------------------------------------------------------------------
1444 register struct cmd_syndesc *as;
1446 afs_int32 server, partition, volid;
1447 afs_int32 code, err = 0;
1449 server = GetServer(as->parms[0].items->data);
1451 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1452 as->parms[0].items->data);
1456 partition = volutil_GetPartitionID(as->parms[1].items->data);
1457 if (partition < 0) {
1458 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1459 as->parms[1].items->data);
1463 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1466 PrintError("", err);
1468 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1469 as->parms[0].items->data);
1473 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1476 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1483 /*------------------------------------------------------------------------
1484 * PRIVATE volOffline
1487 * Brings a volume offline.
1490 * as : Ptr to parsed command line arguments.
1493 * 0 for a successful operation,
1496 * Nothing interesting.
1500 *------------------------------------------------------------------------
1503 volOffline(register struct cmd_syndesc *as)
1505 afs_int32 server, partition, volid;
1506 afs_int32 code, err = 0;
1507 afs_int32 transflag, sleeptime, transdone;
1509 server = GetServer(as->parms[0].items->data);
1511 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1512 as->parms[0].items->data);
1516 partition = volutil_GetPartitionID(as->parms[1].items->data);
1517 if (partition < 0) {
1518 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1519 as->parms[1].items->data);
1523 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1526 PrintError("", err);
1528 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1529 as->parms[0].items->data);
1533 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1534 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1535 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1536 if (as->parms[4].items && !as->parms[3].items) {
1537 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1542 UV_SetVolume(server, partition, volid, transflag, transdone,
1545 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1553 CreateVolume(register struct cmd_syndesc *as)
1557 afs_int32 volid, code;
1558 struct nvldbentry entry;
1563 tserver = GetServer(as->parms[0].items->data);
1565 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1566 as->parms[0].items->data);
1569 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1571 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1572 as->parms[1].items->data);
1575 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1577 PrintError("", code);
1580 "vos : partition %s does not exist on the server\n",
1581 as->parms[1].items->data);
1584 if (!ISNAMEVALID(as->parms[2].items->data)) {
1586 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1587 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1590 if (!VolNameOK(as->parms[2].items->data)) {
1592 "Illegal volume name %s, should not end in .readonly or .backup\n",
1593 as->parms[2].items->data);
1596 if (IsNumeric(as->parms[2].items->data)) {
1597 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1598 as->parms[2].items->data);
1601 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1603 fprintf(STDERR, "Volume %s already exists\n",
1604 as->parms[2].items->data);
1605 PrintDiagnostics("create", code);
1609 if (as->parms[3].items) {
1610 if (!IsNumeric(as->parms[3].items->data)) {
1611 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1612 as->parms[3].items->data);
1616 code = util_GetInt32(as->parms[3].items->data, "a);
1618 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1624 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1627 PrintDiagnostics("create", code);
1630 MapPartIdIntoName(pnum, part);
1631 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1632 (unsigned long)volid, part, as->parms[0].items->data);
1639 struct nvldbentry *entry;
1642 afs_int32 error, code, curserver, curpart, volid;
1644 MapHostToNetwork(entry);
1646 for (i = 0; i < entry->nServers; i++) {
1647 curserver = entry->serverNumber[i];
1648 curpart = entry->serverPartition[i];
1649 if (entry->serverFlags[i] & ITSROVOL) {
1650 volid = entry->volumeId[ROVOL];
1652 volid = entry->volumeId[RWVOL];
1654 code = UV_DeleteVolume(curserver, curpart, volid);
1663 struct cmd_syndesc *as;
1665 afs_int32 err, code = 0;
1666 afs_int32 server = 0, partition = -1, volid;
1670 if (as->parms[0].items) {
1671 server = GetServer(as->parms[0].items->data);
1673 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1674 as->parms[0].items->data);
1679 if (as->parms[1].items) {
1680 partition = volutil_GetPartitionID(as->parms[1].items->data);
1681 if (partition < 0) {
1682 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1683 as->parms[1].items->data);
1687 /* Check for validity of the partition */
1688 if (!IsPartValid(partition, server, &code)) {
1690 PrintError("", code);
1693 "vos : partition %s does not exist on the server\n",
1694 as->parms[1].items->data);
1700 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1702 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1703 as->parms[2].items->data);
1705 PrintError("", err);
1709 /* If the server or partition option are not complete, try to fill
1710 * them in from the VLDB entry.
1712 if ((partition == -1) || !server) {
1713 struct nvldbentry entry;
1715 code = VLDB_GetEntryByID(volid, -1, &entry);
1718 "Could not fetch the entry for volume %lu from VLDB\n",
1719 (unsigned long)volid);
1720 PrintError("", code);
1724 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
1725 || ((volid == entry.volumeId[BACKVOL])
1726 && (entry.flags & BACK_EXISTS))) {
1727 idx = Lp_GetRwIndex(&entry);
1728 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
1729 || ((partition != -1)
1730 && (partition != entry.serverPartition[idx]))) {
1731 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1732 as->parms[2].items->data);
1735 } else if ((volid == entry.volumeId[ROVOL])
1736 && (entry.flags & RO_EXISTS)) {
1737 for (idx = -1, j = 0; j < entry.nServers; j++) {
1738 if (entry.serverFlags[j] != ITSROVOL)
1741 if (((server == 0) || (server == entry.serverNumber[j]))
1742 && ((partition == -1)
1743 || (partition == entry.serverPartition[j]))) {
1746 "VLDB: Volume '%s' matches more than one RO\n",
1747 as->parms[2].items->data);
1754 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1755 as->parms[2].items->data);
1759 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1760 as->parms[2].items->data);
1764 server = htonl(entry.serverNumber[idx]);
1765 partition = entry.serverPartition[idx];
1769 code = UV_DeleteVolume(server, partition, volid);
1771 PrintDiagnostics("remove", code);
1775 MapPartIdIntoName(partition, pname);
1776 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
1777 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
1781 #define TESTM 0 /* set for move space tests, clear for production */
1784 register struct cmd_syndesc *as;
1787 afs_int32 volid, fromserver, toserver, frompart, topart;
1788 afs_int32 flags, code, err;
1789 char fromPartName[10], toPartName[10];
1791 struct diskPartition partition; /* for space check */
1794 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1797 PrintError("", err);
1799 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1800 as->parms[0].items->data);
1803 fromserver = GetServer(as->parms[1].items->data);
1804 if (fromserver == 0) {
1805 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1806 as->parms[1].items->data);
1809 toserver = GetServer(as->parms[3].items->data);
1810 if (toserver == 0) {
1811 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1812 as->parms[3].items->data);
1815 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1817 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1818 as->parms[2].items->data);
1821 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
1823 PrintError("", code);
1826 "vos : partition %s does not exist on the server\n",
1827 as->parms[2].items->data);
1830 topart = volutil_GetPartitionID(as->parms[4].items->data);
1832 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1833 as->parms[4].items->data);
1836 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
1838 PrintError("", code);
1841 "vos : partition %s does not exist on the server\n",
1842 as->parms[4].items->data);
1847 if (as->parms[5].items) flags |= RV_NOCLONE;
1850 * check source partition for space to clone volume
1853 MapPartIdIntoName(topart, toPartName);
1854 MapPartIdIntoName(frompart, fromPartName);
1857 * check target partition for space to move volume
1860 code = UV_PartitionInfo(toserver, toPartName, &partition);
1862 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
1866 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
1869 p = (volintInfo *) 0;
1870 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
1872 fprintf(STDERR, "vos:cannot access volume %lu\n",
1873 (unsigned long)volid);
1878 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
1880 if (partition.free <= p->size) {
1882 "vos: no space on target partition %s to move volume %lu\n",
1883 toPartName, (unsigned long)volid);
1890 fprintf(STDOUT, "size test - don't do move\n");
1894 /* successful move still not guaranteed but shoot for it */
1897 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
1899 PrintDiagnostics("move", code);
1902 MapPartIdIntoName(topart, toPartName);
1903 MapPartIdIntoName(frompart, fromPartName);
1904 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
1905 (unsigned long)volid, as->parms[1].items->data, fromPartName,
1906 as->parms[3].items->data, toPartName);
1913 register struct cmd_syndesc *as;
1915 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
1916 char fromPartName[10], toPartName[10], *tovolume;
1917 struct nvldbentry entry;
1918 struct diskPartition partition; /* for space check */
1921 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1924 PrintError("", err);
1926 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1927 as->parms[0].items->data);
1930 fromserver = GetServer(as->parms[1].items->data);
1931 if (fromserver == 0) {
1932 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1933 as->parms[1].items->data);
1937 toserver = GetServer(as->parms[4].items->data);
1938 if (toserver == 0) {
1939 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1940 as->parms[4].items->data);
1944 tovolume = as->parms[3].items->data;
1945 if (!ISNAMEVALID(tovolume)) {
1947 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1948 tovolume, VOLSER_OLDMAXVOLNAME - 10);
1951 if (!VolNameOK(tovolume)) {
1953 "Illegal volume name %s, should not end in .readonly or .backup\n",
1957 if (IsNumeric(tovolume)) {
1958 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1962 code = VLDB_GetEntryByName(tovolume, &entry);
1964 fprintf(STDERR, "Volume %s already exists\n", tovolume);
1965 PrintDiagnostics("copy", code);
1969 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1971 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1972 as->parms[2].items->data);
1975 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
1977 PrintError("", code);
1980 "vos : partition %s does not exist on the server\n",
1981 as->parms[2].items->data);
1985 topart = volutil_GetPartitionID(as->parms[5].items->data);
1987 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1988 as->parms[5].items->data);
1991 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
1993 PrintError("", code);
1996 "vos : partition %s does not exist on the server\n",
1997 as->parms[5].items->data);
2002 if (as->parms[6].items) flags |= RV_OFFLINE;
2003 if (as->parms[7].items) flags |= RV_RDONLY;
2004 if (as->parms[8].items) flags |= RV_NOCLONE;
2006 MapPartIdIntoName(topart, toPartName);
2007 MapPartIdIntoName(frompart, fromPartName);
2010 * check target partition for space to move volume
2013 code = UV_PartitionInfo(toserver, toPartName, &partition);
2015 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2019 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2022 p = (volintInfo *) 0;
2023 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2025 fprintf(STDERR, "vos:cannot access volume %lu\n",
2026 (unsigned long)volid);
2031 if (partition.free <= p->size) {
2033 "vos: no space on target partition %s to copy volume %lu\n",
2034 toPartName, (unsigned long)volid);
2040 /* successful copy still not guaranteed but shoot for it */
2043 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2046 PrintDiagnostics("copy", code);
2049 MapPartIdIntoName(topart, toPartName);
2050 MapPartIdIntoName(frompart, fromPartName);
2051 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2052 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2053 tovolume, as->parms[4].items->data, toPartName);
2061 register struct cmd_syndesc *as;
2063 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2064 afs_int32 code, err, flags;
2065 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2066 struct nvldbentry entry;
2067 struct diskPartition partition; /* for space check */
2070 p = (volintInfo *) 0;
2071 q = (volintInfo *) 0;
2073 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2076 PrintError("", err);
2078 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2079 as->parms[0].items->data);
2082 fromserver = GetServer(as->parms[1].items->data);
2083 if (fromserver == 0) {
2084 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2085 as->parms[1].items->data);
2089 toserver = GetServer(as->parms[3].items->data);
2090 if (toserver == 0) {
2091 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2092 as->parms[3].items->data);
2096 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2098 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2099 as->parms[2].items->data);
2102 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2104 PrintError("", code);
2107 "vos : partition %s does not exist on the server\n",
2108 as->parms[2].items->data);
2112 topart = volutil_GetPartitionID(as->parms[4].items->data);
2114 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2115 as->parms[4].items->data);
2118 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2120 PrintError("", code);
2123 "vos : partition %s does not exist on the server\n",
2124 as->parms[4].items->data);
2128 if (as->parms[5].items) {
2129 tovolume = as->parms[5].items->data;
2130 if (!ISNAMEVALID(tovolume)) {
2132 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2133 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2136 if (!VolNameOK(tovolume)) {
2138 "Illegal volume name %s, should not end in .readonly or .backup\n",
2142 if (IsNumeric(tovolume)) {
2144 "Illegal volume name %s, should not be a number\n",
2149 /* use actual name of source volume */
2150 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2152 fprintf(STDERR, "vos:cannot access volume %lu\n",
2153 (unsigned long)volid);
2156 strcpy(toVolName, p->name);
2157 tovolume = toVolName;
2158 /* save p for size checks later */
2161 if (as->parms[6].items) {
2162 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2165 PrintError("", err);
2167 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2168 as->parms[6].items->data);
2174 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2177 PrintError("", err);
2179 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2188 if (as->parms[7].items) flags |= RV_OFFLINE;
2189 if (as->parms[8].items) flags |= RV_RDONLY;
2190 if (as->parms[9].items) flags |= RV_NOCLONE;
2191 if (as->parms[10].items) flags |= RV_CPINCR;
2193 MapPartIdIntoName(topart, toPartName);
2194 MapPartIdIntoName(frompart, fromPartName);
2197 * check target partition for space to move volume
2200 code = UV_PartitionInfo(toserver, toPartName, &partition);
2202 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2206 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2209 /* Don't do this again if we did it above */
2211 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2213 fprintf(STDERR, "vos:cannot access volume %lu\n",
2214 (unsigned long)volid);
2219 /* OK if this fails */
2220 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2222 /* Treat existing volume size as "free" */
2224 p->size = (q->size < p->size) ? p->size - q->size : 0;
2226 if (partition.free <= p->size) {
2228 "vos: no space on target partition %s to copy volume %lu\n",
2229 toPartName, (unsigned long)volid);
2237 /* successful copy still not guaranteed but shoot for it */
2240 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2241 topart, tovolid, flags);
2243 PrintDiagnostics("shadow", code);
2246 MapPartIdIntoName(topart, toPartName);
2247 MapPartIdIntoName(frompart, fromPartName);
2248 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2249 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2250 as->parms[3].items->data, toPartName);
2258 register struct cmd_syndesc *as;
2260 afs_int32 server, part, volid, cloneid, voltype;
2261 char partName[10], *volname;
2262 afs_int32 code, err, flags;
2263 struct nvldbentry entry;
2265 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2268 PrintError("", err);
2270 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2271 as->parms[0].items->data);
2275 if (as->parms[1].items || as->parms[2].items) {
2276 if (!as->parms[1].items || !as->parms[2].items) {
2278 "Must specify both -server and -partition options\n");
2281 server = GetServer(as->parms[1].items->data);
2283 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2284 as->parms[1].items->data);
2287 part = volutil_GetPartitionID(as->parms[2].items->data);
2289 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2290 as->parms[2].items->data);
2293 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2295 PrintError("", code);
2298 "vos : partition %s does not exist on the server\n",
2299 as->parms[2].items->data);
2303 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2309 if (as->parms[3].items) {
2310 volname = as->parms[3].items->data;
2311 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2313 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2314 volname, VOLSER_OLDMAXVOLNAME - 1);
2317 if (!VolNameOK(volname)) {
2319 "Illegal volume name %s, should not end in .readonly or .backup\n",
2323 if (IsNumeric(volname)) {
2325 "Illegal volume name %s, should not be a number\n",
2332 if (as->parms[4].items) {
2333 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2336 PrintError("", err);
2338 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2339 as->parms[4].items->data);
2345 if (as->parms[5].items) flags |= RV_OFFLINE;
2346 if (as->parms[6].items) flags |= RV_RDONLY;
2350 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2353 PrintDiagnostics("clone", code);
2356 MapPartIdIntoName(part, partName);
2357 fprintf(STDOUT, "Created clone for volume %lu\n",
2358 as->parms[0].items->data);
2366 register struct cmd_syndesc *as;
2368 afs_int32 avolid, aserver, apart, vtype, code, err;
2369 struct nvldbentry entry;
2371 afs_int32 buvolid, buserver, bupart, butype;
2372 struct nvldbentry buentry;
2374 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2377 PrintError("", err);
2379 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2380 as->parms[0].items->data);
2383 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2387 /* verify this is a readwrite volume */
2389 if (vtype != RWVOL) {
2390 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2394 /* is there a backup volume already? */
2396 if (entry.flags & BACK_EXISTS) {
2397 /* yep, where is it? */
2399 buvolid = entry.volumeId[BACKVOL];
2400 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2405 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2408 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2414 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2415 (unsigned long)buvolid, (unsigned long)buserver);
2420 /* nope, carry on */
2422 code = UV_BackupVolume(aserver, apart, avolid);
2425 PrintDiagnostics("backup", code);
2428 fprintf(STDOUT, "Created backup volume for %s \n",
2429 as->parms[0].items->data);
2435 register struct cmd_syndesc *as;
2438 struct nvldbentry entry;
2439 afs_int32 avolid, aserver, apart, vtype, code, err;
2442 if (as->parms[1].items)
2444 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2447 PrintError("", err);
2449 fprintf(STDERR, "vos: can't find volume '%s'\n",
2450 as->parms[0].items->data);
2453 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2457 if (vtype != RWVOL) {
2458 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2462 if (!ISNAMEVALID(entry.name)) {
2464 "Volume name %s is too long, rename before releasing\n",
2469 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2471 PrintDiagnostics("release", code);
2474 fprintf(STDOUT, "Released volume %s successfully\n",
2475 as->parms[0].items->data);
2481 register struct cmd_syndesc *as;
2484 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
2485 char filename[NameLen];
2486 struct nvldbentry entry;
2488 rx_SetRxDeadTime(60 * 10);
2489 for (i = 0; i < MAXSERVERS; i++) {
2490 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2493 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2494 if (rxConn->service)
2495 rxConn->service->connDeadTime = rx_connDeadTime;
2498 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2501 PrintError("", err);
2503 fprintf(STDERR, "vos: can't find volume '%s'\n",
2504 as->parms[0].items->data);
2508 if (as->parms[3].items || as->parms[4].items) {
2509 if (!as->parms[3].items || !as->parms[4].items) {
2511 "Must specify both -server and -partition options\n");
2514 aserver = GetServer(as->parms[3].items->data);
2516 fprintf(STDERR, "Invalid server name\n");
2519 apart = volutil_GetPartitionID(as->parms[4].items->data);
2521 fprintf(STDERR, "Invalid partition name\n");
2525 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2530 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2531 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2533 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2534 as->parms[1].items->data, code);
2538 if (as->parms[2].items) {
2539 strcpy(filename, as->parms[2].items->data);
2541 strcpy(filename, "");
2544 if (as->parms[5].items) {
2546 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2547 DumpFunction, filename);
2550 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2554 PrintDiagnostics("dump", code);
2557 if (strcmp(filename, ""))
2558 fprintf(STDERR, "Dumped volume %s in file %s\n",
2559 as->parms[0].items->data, filename);
2561 fprintf(STDERR, "Dumped volume %s in stdout \n",
2562 as->parms[0].items->data);
2577 register struct cmd_syndesc *as;
2580 afs_int32 avolid, aserver, apart, code, vcode, err;
2581 afs_int32 aoverwrite = ASK;
2582 afs_int32 acreation = 0, alastupdate = 0;
2583 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2585 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2586 char volname[VOLSER_MAXVOLNAME + 1];
2587 struct nvldbentry entry;
2591 if (as->parms[4].items) {
2592 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2595 PrintError("", err);
2597 fprintf(STDERR, "vos: can't find volume '%s'\n",
2598 as->parms[4].items->data);
2604 if (as->parms[5].items) {
2605 if ((strcmp(as->parms[5].items->data, "a") == 0)
2606 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2608 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2609 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2611 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2612 || (strcmp(as->parms[5].items->data, "inc") == 0)
2613 || (strcmp(as->parms[5].items->data, "increment") == 0)
2614 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2617 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2618 as->parms[5].items->data);
2622 if (as->parms[6].items)
2624 if (as->parms[7].items) {
2629 if (as->parms[8].items) {
2630 if ((strcmp(as->parms[8].items->data, "d") == 0)
2631 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2632 acreation = TS_DUMP;
2633 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2634 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2635 acreation = TS_KEEP;
2636 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2637 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2640 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2641 as->parms[8].items->data);
2646 if (as->parms[9].items) {
2647 if ((strcmp(as->parms[9].items->data, "d") == 0)
2648 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2649 alastupdate = TS_DUMP;
2650 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2651 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2652 alastupdate = TS_KEEP;
2653 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2654 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2655 alastupdate = TS_NEW;
2657 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2658 as->parms[9].items->data);
2663 aserver = GetServer(as->parms[0].items->data);
2665 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2666 as->parms[0].items->data);
2669 apart = volutil_GetPartitionID(as->parms[1].items->data);
2671 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2672 as->parms[1].items->data);
2675 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2677 PrintError("", code);
2680 "vos : partition %s does not exist on the server\n",
2681 as->parms[1].items->data);
2684 strcpy(avolname, as->parms[2].items->data);
2685 if (!ISNAMEVALID(avolname)) {
2687 "vos: the name of the volume %s exceeds the size limit\n",
2691 if (!VolNameOK(avolname)) {
2693 "Illegal volume name %s, should not end in .readonly or .backup\n",
2697 if (as->parms[3].items) {
2698 strcpy(afilename, as->parms[3].items->data);
2699 if (!FileExists(afilename)) {
2700 fprintf(STDERR, "Can't access file %s\n", afilename);
2704 strcpy(afilename, "");
2707 /* Check if volume exists or not */
2709 vsu_ExtractName(volname, avolname);
2710 vcode = VLDB_GetEntryByName(volname, &entry);
2711 if (vcode) { /* no volume - do a full restore */
2712 restoreflags = RV_FULLRST;
2713 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2715 "Volume does not exist; Will perform a full restore\n");
2718 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
2719 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
2720 restoreflags = RV_FULLRST;
2721 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2723 "%s Volume does not exist; Will perform a full restore\n",
2724 readonly ? "RO" : "RW");
2727 avolid = entry.volumeId[voltype];
2728 } else if (entry.volumeId[voltype] != 0
2729 && entry.volumeId[voltype] != avolid) {
2730 avolid = entry.volumeId[voltype];
2734 else { /* volume exists - do we do a full incremental or abort */
2735 int Oserver, Opart, Otype, vol_elsewhere = 0;
2736 struct nvldbentry Oentry;
2740 avolid = entry.volumeId[voltype];
2741 } else if (entry.volumeId[voltype] != 0
2742 && entry.volumeId[voltype] != avolid) {
2743 avolid = entry.volumeId[voltype];
2746 /* A file name was specified - check if volume is on another partition */
2747 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
2751 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
2754 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
2758 if (!vcode || (Opart != apart))
2761 if (aoverwrite == ASK) {
2762 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
2764 "Volume exists and no -overwrite option specified; Aborting restore command\n");
2768 /* Ask what to do */
2769 if (vol_elsewhere) {
2771 "The volume %s %u already exists on a different server/part\n",
2772 volname, entry.volumeId[voltype]);
2774 "Do you want to do a full restore or abort? [fa](a): ");
2777 "The volume %s %u already exists in the VLDB\n",
2778 volname, entry.volumeId[voltype]);
2780 "Do you want to do a full/incremental restore or abort? [fia](a): ");
2783 while (!(dc == EOF || dc == '\n'))
2784 dc = getchar(); /* goto end of line */
2785 if ((c == 'f') || (c == 'F'))
2787 else if ((c == 'i') || (c == 'I'))
2793 if (aoverwrite == ABORT) {
2794 fprintf(STDERR, "Volume exists; Aborting restore command\n");
2796 } else if (aoverwrite == FULL) {
2797 restoreflags = RV_FULLRST;
2799 "Volume exists; Will delete and perform full restore\n");
2800 } else if (aoverwrite == INC) {
2802 if (vol_elsewhere) {
2804 "%s volume %lu already exists on a different server/part; not allowed\n",
2805 readonly ? "RO" : "RW", (unsigned long)avolid);
2811 restoreflags |= RV_OFFLINE;
2813 restoreflags |= RV_RDONLY;
2815 switch (acreation) {
2817 restoreflags |= RV_CRDUMP;
2820 restoreflags |= RV_CRKEEP;
2823 restoreflags |= RV_CRNEW;
2826 if (aoverwrite == FULL)
2827 restoreflags |= RV_CRNEW;
2829 restoreflags |= RV_CRKEEP;
2832 switch (alastupdate) {
2834 restoreflags |= RV_LUDUMP;
2837 restoreflags |= RV_LUKEEP;
2840 restoreflags |= RV_LUNEW;
2843 restoreflags |= RV_LUKEEP;
2847 UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags,
2848 WriteData, afilename);
2850 PrintDiagnostics("restore", code);
2853 MapPartIdIntoName(apart, apartName);
2856 * patch typo here - originally "parms[1]", should be "parms[0]"
2859 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
2860 as->parms[0].items->data, apartName);
2866 register struct cmd_syndesc *as;
2869 afs_int32 avolid, code, err;
2871 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2874 PrintError("", err);
2876 fprintf(STDERR, "vos: can't find volume '%s'\n",
2877 as->parms[0].items->data);
2881 code = UV_LockRelease(avolid);
2883 PrintDiagnostics("unlock", code);
2886 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
2887 as->parms[0].items->data);
2893 register struct cmd_syndesc *as;
2895 afs_int32 avolid, aserver, apart, code, err;
2896 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2898 vsu_ExtractName(avolname, as->parms[2].items->data);;
2899 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2902 PrintError("", err);
2904 fprintf(STDERR, "vos: can't find volume '%s'\n",
2905 as->parms[2].items->data);
2908 aserver = GetServer(as->parms[0].items->data);
2910 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2911 as->parms[0].items->data);
2914 apart = volutil_GetPartitionID(as->parms[1].items->data);
2916 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2917 as->parms[1].items->data);
2920 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2922 PrintError("", code);
2925 "vos : partition %s does not exist on the server\n",
2926 as->parms[1].items->data);
2929 code = UV_AddSite(aserver, apart, avolid);
2931 PrintDiagnostics("addsite", code);
2934 MapPartIdIntoName(apart, apartName);
2935 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
2936 as->parms[0].items->data, apartName, as->parms[2].items->data);
2942 register struct cmd_syndesc *as;
2945 afs_int32 avolid, aserver, apart, code, err;
2946 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2948 vsu_ExtractName(avolname, as->parms[2].items->data);
2949 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2952 PrintError("", err);
2954 fprintf(STDERR, "vos: can't find volume '%s'\n",
2955 as->parms[2].items->data);
2958 aserver = GetServer(as->parms[0].items->data);
2960 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2961 as->parms[0].items->data);
2964 apart = volutil_GetPartitionID(as->parms[1].items->data);
2966 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2967 as->parms[1].items->data);
2971 *skip the partition validity check, since it is possible that the partition
2972 *has since been decomissioned.
2975 if (!IsPartValid(apart,aserver,&code)){
2976 if(code) PrintError("",code);
2977 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2981 code = UV_RemoveSite(aserver, apart, avolid);
2983 PrintDiagnostics("remsite", code);
2986 MapPartIdIntoName(apart, apartName);
2987 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
2988 as->parms[0].items->data, apartName, as->parms[2].items->data);
2994 register struct cmd_syndesc *as;
2996 afs_int32 avolid, aserver, apart, code, err;
2999 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3002 PrintError("", err);
3004 fprintf(STDERR, "vos: can't find volume '%s'\n",
3005 as->parms[2].items->data);
3008 aserver = GetServer(as->parms[0].items->data);
3010 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3011 as->parms[0].items->data);
3014 apart = volutil_GetPartitionID(as->parms[1].items->data);
3016 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3017 as->parms[1].items->data);
3020 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3022 PrintError("", code);
3025 "vos : partition %s does not exist on the server\n",
3026 as->parms[1].items->data);
3029 code = UV_ChangeLocation(aserver, apart, avolid);
3031 PrintDiagnostics("addsite", code);
3034 MapPartIdIntoName(apart, apartName);
3035 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3036 as->parms[0].items->data, apartName, as->parms[2].items->data);
3042 register struct cmd_syndesc *as;
3044 afs_int32 aserver, code;
3045 struct partList dummyPartList;
3050 aserver = GetServer(as->parms[0].items->data);
3052 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3053 as->parms[0].items->data);
3058 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3060 PrintDiagnostics("listpart", code);
3064 fprintf(STDOUT, "The partitions on the server are:\n");
3065 for (i = 0; i < cnt; i++) {
3066 if (dummyPartList.partFlags[i] & PARTVALID) {
3067 memset(pname, 0, sizeof(pname));
3068 MapPartIdIntoName(dummyPartList.partId[i], pname);
3069 fprintf(STDOUT, " %10s ", pname);
3071 if ((i % 5) == 0 && (i != 0))
3072 fprintf(STDOUT, "\n");
3075 fprintf(STDOUT, "\n");
3076 fprintf(STDOUT, "Total: %d\n", total);
3082 CompareVolName(p1, p2)
3085 volintInfo *arg1, *arg2;
3087 arg1 = (volintInfo *) p1;
3088 arg2 = (volintInfo *) p2;
3089 return (strcmp(arg1->name, arg2->name));
3093 /*------------------------------------------------------------------------
3094 * PRIVATE XCompareVolName
3097 * Comparison routine for volume names coming from an extended
3101 * a_obj1P : Char ptr to first extended vol info object
3102 * a_obj1P : Char ptr to second extended vol info object
3105 * The value of strcmp() on the volume names within the passed
3106 * objects (i,e., -1, 0, or 1).
3109 * Passed to qsort() as the designated comparison routine.
3113 *------------------------------------------------------------------------*/
3116 XCompareVolName(a_obj1P, a_obj2P)
3117 char *a_obj1P, *a_obj2P;
3119 { /*XCompareVolName */
3122 (((struct volintXInfo *)(a_obj1P))->name,
3123 ((struct volintXInfo *)(a_obj2P))->name));
3125 } /*XCompareVolName */
3128 CompareVolID(p1, p2)
3131 volintInfo *arg1, *arg2;
3133 arg1 = (volintInfo *) p1;
3134 arg2 = (volintInfo *) p2;
3135 if (arg1->volid == arg2->volid)
3137 if (arg1->volid > arg2->volid)
3144 /*------------------------------------------------------------------------
3145 * PRIVATE XCompareVolID
3148 * Comparison routine for volume IDs coming from an extended
3152 * a_obj1P : Char ptr to first extended vol info object
3153 * a_obj1P : Char ptr to second extended vol info object
3156 * The value of strcmp() on the volume names within the passed
3157 * objects (i,e., -1, 0, or 1).
3160 * Passed to qsort() as the designated comparison routine.
3164 *------------------------------------------------------------------------*/
3167 XCompareVolID(a_obj1P, a_obj2P)
3168 char *a_obj1P, *a_obj2P;
3170 { /*XCompareVolID */
3172 afs_int32 id1, id2; /*Volume IDs we're comparing */
3174 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3175 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3183 } /*XCompareVolID */
3185 /*------------------------------------------------------------------------
3186 * PRIVATE ListVolumes
3189 * Routine used to list volumes, contacting the Volume Server
3190 * directly, bypassing the VLDB.
3193 * as : Ptr to parsed command line arguments.
3196 * 0 Successful operation
3199 * Nothing interesting.
3203 *------------------------------------------------------------------------*/
3207 register struct cmd_syndesc *as;
3209 afs_int32 apart, int32list, fast;
3210 afs_int32 aserver, code;
3211 volintInfo *pntr, *oldpntr;
3215 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3216 int wantExtendedInfo; /*Do we want extended vol info? */
3219 struct partList dummyPartList;
3227 if (as->parms[3].items)
3229 if (as->parms[4].items)
3233 if (as->parms[2].items)
3239 if (as->parms[5].items) {
3241 * We can't coexist with the fast flag.
3245 "vos: Can't use the -fast and -extended flags together\n");
3250 * We need to turn on ``long'' listings to get the full effect.
3252 wantExtendedInfo = 1;
3255 wantExtendedInfo = 0;
3256 if (as->parms[1].items) {
3257 apart = volutil_GetPartitionID(as->parms[1].items->data);
3259 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3260 as->parms[1].items->data);
3263 dummyPartList.partId[0] = apart;
3264 dummyPartList.partFlags[0] = PARTVALID;
3267 aserver = GetServer(as->parms[0].items->data);
3269 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3270 as->parms[0].items->data);
3275 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3277 PrintError("", code);
3280 "vos : partition %s does not exist on the server\n",
3281 as->parms[1].items->data);
3285 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3287 PrintDiagnostics("listvol", code);
3291 for (i = 0; i < cnt; i++) {
3292 if (dummyPartList.partFlags[i] & PARTVALID) {
3293 if (wantExtendedInfo)
3295 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3299 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3302 PrintDiagnostics("listvol", code);
3307 if (wantExtendedInfo) {
3308 origxInfoP = xInfoP;
3309 base = (char *)xInfoP;
3312 base = (char *)pntr;
3316 if (wantExtendedInfo)
3317 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3319 qsort(base, count, sizeof(volintInfo), CompareVolName);
3321 if (wantExtendedInfo)
3322 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3324 qsort(base, count, sizeof(volintInfo), CompareVolID);
3326 MapPartIdIntoName(dummyPartList.partId[i], pname);
3329 "Total number of volumes on server %s partition %s: %lu \n",
3330 as->parms[0].items->data, pname,
3331 (unsigned long)count);
3332 if (wantExtendedInfo) {
3333 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3334 count, int32list, fast, quiet);
3337 xInfoP = (volintXInfo *) 0;
3339 #ifdef FULL_LISTVOL_SWITCH
3340 if (as->parms[6].items)
3341 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3344 #endif /* FULL_LISTVOL_SWITCH */
3345 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3346 count, int32list, fast, quiet);
3349 pntr = (volintInfo *) 0;
3358 register struct cmd_syndesc *as;
3360 afs_int32 pnum = 0, code; /* part name */
3366 if (as->parms[0].items) {
3367 tserver = GetServer(as->parms[0].items->data);
3369 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3370 as->parms[0].items->data);
3375 if (as->parms[1].items) {
3376 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3378 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3379 as->parms[1].items->data);
3382 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3384 PrintError("", code);
3387 "vos: partition %s does not exist on the server\n",
3388 as->parms[1].items->data);
3395 "The -partition option requires a -server option\n");
3400 if (as->parms[2].items) {
3401 /* Synchronize an individual volume */
3402 volname = as->parms[2].items->data;
3403 code = UV_SyncVolume(tserver, pnum, volname, flags);
3407 "Without a -volume option, the -server option is required\n");
3410 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3414 PrintDiagnostics("syncvldb", code);
3418 /* Print a summary of what we did */
3420 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3422 fprintf(STDOUT, "VLDB synchronized");
3424 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3427 MapPartIdIntoName(pnum, part);
3428 fprintf(STDOUT, " partition %s\n", part);
3430 fprintf(STDOUT, "\n");
3437 register struct cmd_syndesc *as;
3440 afs_int32 pnum, code; /* part name */
3445 tserver = GetServer(as->parms[0].items->data);
3447 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3448 as->parms[0].items->data);
3451 if (as->parms[1].items) {
3452 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3454 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3455 as->parms[1].items->data);
3458 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3460 PrintError("", code);
3463 "vos : partition %s does not exist on the server\n",
3464 as->parms[1].items->data);
3472 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3474 PrintDiagnostics("syncserv", code);
3478 MapPartIdIntoName(pnum, part);
3479 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3480 as->parms[0].items->data, part);
3482 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3483 as->parms[0].items->data);
3492 struct nvldbentry entry;
3495 /* The vlserver will handle names with the .readonly
3496 * and .backup extension as well as volume ids.
3498 vcode = VLDB_GetEntryByName(name, &entry);
3500 PrintError("", vcode);
3503 MapHostToNetwork(&entry);
3504 EnumerateEntry(&entry);
3506 /* Defect #3027: grubby check to handle locked volume.
3507 * If VLOP_ALLOPERS is set, the entry is locked.
3508 * Leave this routine as is, but put in correct check.
3510 if (entry.flags & VLOP_ALLOPERS)
3511 fprintf(STDOUT, " Volume is currently LOCKED \n");
3518 register struct cmd_syndesc *as;
3521 struct nvldbentry entry;
3522 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3524 if (as->parms[3].items) {
3525 /* force flag is on, use the other version */
3526 return NukeVolume(as);
3529 if (as->parms[4].items) {
3533 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3536 PrintError("", err);
3538 fprintf(STDERR, "vos: can't find volume '%s'\n",
3539 as->parms[2].items->data);
3542 part = volutil_GetPartitionID(as->parms[1].items->data);
3544 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3545 as->parms[1].items->data);
3548 server = GetServer(as->parms[0].items->data);
3550 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3551 as->parms[0].items->data);
3554 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3556 PrintError("", code);
3559 "vos : partition %s does not exist on the server\n",
3560 as->parms[1].items->data);
3563 code = VLDB_GetEntryByID(volid, -1, &entry);
3565 if (volid == entry.volumeId[RWVOL])
3566 backupid = entry.volumeId[BACKVOL];
3568 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3569 (unsigned long)volid);
3572 volintInfo *pntr = (volintInfo *) 0;
3575 code = UV_ListOneVolume(server, part, volid, &pntr);
3577 if (volid == pntr->parentID)
3578 backupid = pntr->backupID;
3584 code = UV_VolumeZap(server, part, backupid);
3586 PrintDiagnostics("zap", code);
3589 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3590 (unsigned long)backupid);
3593 code = UV_VolumeZap(server, part, volid);
3595 PrintDiagnostics("zap", code);
3598 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3605 register struct cmd_syndesc *as;
3608 afs_int32 server, code;
3609 transDebugInfo *pntr, *oldpntr;
3614 server = GetServer(as->parms[0].items->data);
3616 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3617 as->parms[0].items->data);
3620 code = UV_VolserStatus(server, &pntr, &count);
3622 PrintDiagnostics("status", code);
3627 fprintf(STDOUT, "No active transactions on %s\n",
3628 as->parms[0].items->data);
3630 fprintf(STDOUT, "Total transactions: %d\n", count);
3632 for (i = 0; i < count; i++) {
3633 /*print out the relevant info */
3634 fprintf(STDOUT, "--------------------------------------\n");
3635 fprintf(STDOUT, "transaction: %lu created: %s",
3636 (unsigned long)pntr->tid, ctime((time_t *) & pntr->time));
3637 if (pntr->returnCode) {
3638 fprintf(STDOUT, "returnCode: %lu\n",
3639 (unsigned long)pntr->returnCode);
3642 fprintf(STDOUT, "attachFlags: ");
3643 switch (pntr->iflags) {
3645 fprintf(STDOUT, "offline ");
3648 fprintf(STDOUT, "busy ");
3651 fprintf(STDOUT, "readonly ");
3654 fprintf(STDOUT, "create ");
3657 fprintf(STDOUT, "create volid ");
3660 fprintf(STDOUT, "\n");
3663 fprintf(STDOUT, "volumeStatus: ");
3664 switch (pntr->vflags) {
3665 case VTDeleteOnSalvage:
3666 fprintf(STDOUT, "deleteOnSalvage ");
3667 case VTOutOfService:
3668 fprintf(STDOUT, "outOfService ");
3670 fprintf(STDOUT, "deleted ");
3672 fprintf(STDOUT, "\n");
3675 fprintf(STDOUT, "transactionFlags: ");
3676 fprintf(STDOUT, "delete\n");
3678 MapPartIdIntoName(pntr->partition, pname);
3679 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
3680 (unsigned long)pntr->volid, pname, pntr->lastProcName);
3681 if (pntr->callValid) {
3683 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3684 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
3685 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
3688 fprintf(STDOUT, "--------------------------------------\n");
3689 fprintf(STDOUT, "\n");
3698 register struct cmd_syndesc *as;
3700 afs_int32 code1, code2, code;
3701 struct nvldbentry entry;
3703 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
3705 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
3706 as->parms[0].items->data);
3709 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
3710 if ((!code1) && (!code2)) { /*the newname already exists */
3711 fprintf(STDERR, "vos: volume %s already exists\n",
3712 as->parms[1].items->data);
3716 if (code1 && code2) {
3717 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
3718 as->parms[0].items->data, as->parms[1].items->data);
3721 if (!VolNameOK(as->parms[0].items->data)) {
3723 "Illegal volume name %s, should not end in .readonly or .backup\n",
3724 as->parms[0].items->data);
3727 if (!ISNAMEVALID(as->parms[1].items->data)) {
3729 "vos: the new volume name %s exceeds the size limit of %d\n",
3730 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
3733 if (!VolNameOK(as->parms[1].items->data)) {
3735 "Illegal volume name %s, should not end in .readonly or .backup\n",
3736 as->parms[1].items->data);
3739 if (IsNumeric(as->parms[1].items->data)) {
3740 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
3741 as->parms[1].items->data);
3744 MapHostToNetwork(&entry);
3746 UV_RenameVolume(&entry, as->parms[0].items->data,
3747 as->parms[1].items->data);
3749 PrintDiagnostics("rename", code);
3752 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
3753 as->parms[1].items->data);
3757 GetVolumeInfo(volid, server, part, voltype, rentry)
3758 afs_int32 *server, volid, *part, *voltype;
3759 register struct nvldbentry *rentry;
3764 vcode = VLDB_GetEntryByID(volid, -1, rentry);
3767 "Could not fetch the entry for volume %lu from VLDB \n",
3768 (unsigned long)volid);
3769 PrintError("", vcode);
3772 MapHostToNetwork(rentry);
3773 if (volid == rentry->volumeId[ROVOL]) {
3775 for (i = 0; i < rentry->nServers; i++) {
3776 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
3777 && !(rentry->serverFlags[i] & RO_DONTUSE))
3782 "RO volume is not found in VLDB entry for volume %lu\n",
3783 (unsigned long)volid);
3787 *server = rentry->serverNumber[index];
3788 *part = rentry->serverPartition[index];
3792 index = Lp_GetRwIndex(rentry);
3795 "RW Volume is not found in VLDB entry for volume %lu\n",
3796 (unsigned long)volid);
3799 if (volid == rentry->volumeId[RWVOL]) {
3801 *server = rentry->serverNumber[index];
3802 *part = rentry->serverPartition[index];
3805 if (volid == rentry->volumeId[BACKVOL]) {
3807 *server = rentry->serverNumber[index];
3808 *part = rentry->serverPartition[index];
3812 "unexpected volume type for volume %lu\n",
3813 (unsigned long)volid);
3819 register struct cmd_syndesc *as;
3825 struct VldbListByAttributes attributes;
3826 nbulkentries arrayEntries;
3827 register struct nvldbentry *vllist;
3828 struct cmd_item *itp;
3831 char prefix[VOLSER_MAXVOLNAME + 1];
3833 afs_int32 totalBack = 0, totalFail = 0, err;
3835 if (as->parms[0].items) { /* -id */
3836 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
3838 "You cannot use -server, -partition, or -prefix with the -id argument\n");
3841 for (itp = as->parms[0].items; itp; itp = itp->next) {
3842 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
3845 PrintError("", err);
3847 fprintf(STDERR, "vos: can't find volume '%s'\n",
3851 if (as->parms[4].items) { /* -noexecute */
3852 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3857 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3859 fprintf(STDERR, "Could not delete entry for volume %s\n",
3862 "You must specify a RW volume name or ID "
3863 "(the entire VLDB entry will be deleted)\n");
3864 PrintError("", vcode);
3870 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
3874 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
3875 fprintf(STDERR, "You must specify an option\n");
3879 /* Zero out search attributes */
3880 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3882 if (as->parms[1].items) { /* -prefix */
3883 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
3885 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
3887 "You must provide -server with the -prefix argument\n");
3892 if (as->parms[2].items) { /* -server */
3894 aserver = GetServer(as->parms[2].items->data);
3896 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3897 as->parms[2].items->data);
3900 attributes.server = ntohl(aserver);
3901 attributes.Mask |= VLLIST_SERVER;
3904 if (as->parms[3].items) { /* -partition */
3905 if (!as->parms[2].items) {
3907 "You must provide -server with the -partition argument\n");
3910 apart = volutil_GetPartitionID(as->parms[3].items->data);
3912 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3913 as->parms[3].items->data);
3916 attributes.partition = apart;
3917 attributes.Mask |= VLLIST_PARTITION;
3920 /* Print status line of what we are doing */
3921 fprintf(STDOUT, "Deleting VLDB entries for ");
3922 if (as->parms[2].items) {
3923 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
3925 if (as->parms[3].items) {
3927 MapPartIdIntoName(apart, pname);
3928 fprintf(STDOUT, "partition %s ", pname);
3931 fprintf(STDOUT, "which are prefixed with %s ", prefix);
3933 fprintf(STDOUT, "\n");
3936 /* Get all the VLDB entries on a server and/or partition */
3937 memset(&arrayEntries, 0, sizeof(arrayEntries));
3938 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3940 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3941 PrintError("", vcode);
3945 /* Process each entry */
3946 for (j = 0; j < nentries; j++) {
3947 vllist = &arrayEntries.nbulkentries_val[j];
3949 /* It only deletes the RW volumes */
3950 if (strncmp(vllist->name, prefix, strlen(prefix))) {
3953 "Omitting to delete %s due to prefix %s mismatch\n",
3954 vllist->name, prefix);
3961 if (as->parms[4].items) { /* -noexecute */
3962 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3968 /* Only matches the RW volume name */
3969 avolid = vllist->volumeId[RWVOL];
3970 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3972 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
3975 PrintError("", vcode);
3980 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
3985 fprintf(STDOUT, "----------------------\n");
3987 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
3988 (unsigned long)totalBack, (unsigned long)totalFail);
3989 if (arrayEntries.nbulkentries_val)
3990 free(arrayEntries.nbulkentries_val);
3996 CompareVldbEntryByName(p1, p2)
3999 struct nvldbentry *arg1, *arg2;
4001 arg1 = (struct nvldbentry *)p1;
4002 arg2 = (struct nvldbentry *)p2;
4003 return (strcmp(arg1->name, arg2->name));
4007 static int CompareVldbEntry(p1,p2)
4010 struct nvldbentry *arg1,*arg2;
4013 char comp1[100],comp2[100];
4014 char temp1[20],temp2[20];
4016 arg1 = (struct nvldbentry *)p1;
4017 arg2 = (struct nvldbentry *)p2;
4021 for(i = 0; i < arg1->nServers; i++)
4022 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4023 for(i = 0; i < arg2->nServers; i++)
4024 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4025 if(pos1 == -1 || pos2 == -1){
4029 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4030 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4031 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4032 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4033 strcat(comp1,temp1);
4034 strcat(comp2,temp2);
4035 strcat(comp1,arg1->name);
4036 strcat(comp1,arg2->name);
4037 return(strcmp(comp1,comp2));
4044 struct cmd_syndesc *as;
4047 afs_int32 aserver, code;
4049 struct VldbListByAttributes attributes;
4050 nbulkentries arrayEntries;
4051 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4052 afs_int32 centries, nentries = 0, tarraysize, parraysize;
4055 int quiet, sort, lock;
4056 afs_int32 thisindex, nextindex;
4061 attributes.Mask = 0;
4062 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4063 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4064 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4066 /* If the volume name is given, Use VolumeInfoCmd to look it up
4067 * and not ListAttributes.
4069 if (as->parms[0].items) {
4072 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4075 code = VolumeInfoCmd(as->parms[0].items->data);
4077 PrintError("", code);
4083 /* Server specified */
4084 if (as->parms[1].items) {
4085 aserver = GetServer(as->parms[1].items->data);
4087 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4088 as->parms[1].items->data);
4091 attributes.server = ntohl(aserver);
4092 attributes.Mask |= VLLIST_SERVER;
4095 /* Partition specified */
4096 if (as->parms[2].items) {
4097 apart = volutil_GetPartitionID(as->parms[2].items->data);
4099 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4100 as->parms[2].items->data);
4103 attributes.partition = apart;
4104 attributes.Mask |= VLLIST_PARTITION;
4108 attributes.Mask |= VLLIST_FLAG;
4109 attributes.flag = VLOP_ALLOPERS;
4112 /* Print header information */
4114 MapPartIdIntoName(apart, pname);
4115 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4116 (as->parms[1].items ? "server" : "all"),
4117 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4118 (as->parms[2].items ? " partition " : ""),
4119 (as->parms[2].items ? pname : ""),
4120 (lock ? "which are locked:" : ""));
4123 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4124 memset(&arrayEntries, 0, sizeof(arrayEntries));
4129 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4130 &arrayEntries, &nextindex);
4131 if (vcode == RXGEN_OPCODE) {
4132 /* Vlserver not running with ListAttributesN2. Fall back */
4134 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4138 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4139 PrintError("", vcode);
4142 nentries += centries;
4144 /* We don't sort, so just print the entries now */
4146 for (j = 0; j < centries; j++) { /* process each entry */
4147 vllist = &arrayEntries.nbulkentries_val[j];
4148 MapHostToNetwork(vllist);
4149 EnumerateEntry(vllist);
4151 if (vllist->flags & VLOP_ALLOPERS)
4152 fprintf(STDOUT, " Volume is currently LOCKED \n");
4156 /* So we sort. First we must collect all the entries and keep
4159 else if (centries > 0) {
4161 /* steal away the first bulk entries array */
4162 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4163 tarraysize = centries * sizeof(struct nvldbentry);
4164 arrayEntries.nbulkentries_val = 0;
4166 /* Grow the tarray to keep the extra entries */
4167 parraysize = (centries * sizeof(struct nvldbentry));
4169 (struct nvldbentry *)realloc(tarray,
4170 tarraysize + parraysize);
4173 "Could not allocate enough space for the VLDB entries\n");
4179 memcpy(((char *)tarray) + tarraysize,
4180 (char *)arrayEntries.nbulkentries_val, parraysize);
4181 tarraysize += parraysize;
4185 /* Free the bulk array */
4186 if (arrayEntries.nbulkentries_val) {
4187 free(arrayEntries.nbulkentries_val);
4188 arrayEntries.nbulkentries_val = 0;
4192 /* Here is where we now sort all the entries and print them */
4193 if (sort && (nentries > 0)) {
4194 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4195 CompareVldbEntryByName);
4196 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4197 MapHostToNetwork(vllist);
4198 EnumerateEntry(vllist);
4200 if (vllist->flags & VLOP_ALLOPERS)
4201 fprintf(STDOUT, " Volume is currently LOCKED \n");
4207 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4215 register struct cmd_syndesc *as;
4217 afs_int32 apart = 0, avolid;
4218 afs_int32 aserver = 0, code, aserver1, apart1;
4220 struct VldbListByAttributes attributes;
4221 nbulkentries arrayEntries;
4222 register struct nvldbentry *vllist;
4226 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4227 afs_int32 totalBack = 0;
4228 afs_int32 totalFail = 0;
4229 int previdx = -1, error, same;
4231 struct cmd_item *ti;
4235 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4236 attributes.Mask = 0;
4238 seenprefix = (as->parms[0].items ? 1 : 0);
4239 exclude = (as->parms[3].items ? 1 : 0);
4240 seenxprefix = (as->parms[4].items ? 1 : 0);
4241 noaction = (as->parms[5].items ? 1 : 0);
4243 if (as->parms[1].items) { /* -server */
4244 aserver = GetServer(as->parms[1].items->data);
4246 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4247 as->parms[1].items->data);
4250 attributes.server = ntohl(aserver);
4251 attributes.Mask |= VLLIST_SERVER;
4254 if (as->parms[2].items) { /* -partition */
4255 apart = volutil_GetPartitionID(as->parms[2].items->data);
4257 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4258 as->parms[2].items->data);
4261 attributes.partition = apart;
4262 attributes.Mask |= VLLIST_PARTITION;
4265 /* Check to make sure the prefix and xprefix expressions compile ok */
4267 for (ti = as->parms[0].items; ti; ti = ti->next) {
4268 if (strncmp(ti->data, "^", 1) == 0) {
4269 #ifdef HAVE_POSIX_REGEX
4273 code = regcomp(&re, ti->data, REG_NOSUB);
4275 regerror(code, &re, errbuf, sizeof errbuf);
4277 "Unrecognizable -prefix regular expression: '%s': %s\n",
4283 ccode = (char *)re_comp(ti->data);
4286 "Unrecognizable -prefix regular expression: '%s': %s\n",
4295 for (ti = as->parms[4].items; ti; ti = ti->next) {
4296 if (strncmp(ti->data, "^", 1) == 0) {
4297 #ifdef HAVE_POSIX_REGEX
4301 code = regcomp(&re, ti->data, REG_NOSUB);
4303 regerror(code, &re, errbuf, sizeof errbuf);
4305 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4311 ccode = (char *)re_comp(ti->data);
4314 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4323 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4324 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4326 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4327 PrintError("", vcode);
4331 if (as->parms[1].items || as->parms[2].items || verbose) {
4332 fprintf(STDOUT, "%s up volumes",
4333 (noaction ? "Would have backed" : "Backing"));
4335 if (as->parms[1].items) {
4336 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4337 } else if (as->parms[2].items) {
4338 fprintf(STDOUT, " for all servers");
4341 if (as->parms[2].items) {
4342 MapPartIdIntoName(apart, pname);
4343 fprintf(STDOUT, " partition %s", pname);
4346 if (seenprefix || (!seenprefix && seenxprefix)) {
4347 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4348 ex = (seenprefix ? exclude : !exclude);
4349 exp = (strncmp(ti->data, "^", 1) == 0);