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");
449 vos_ctime(afs_int32 *timep)
455 #define vos_ctime ctime
459 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
462 afs_int32 server, part;
463 int *totalOK, *totalNotOK, *totalBusy;
464 int fast, longlist, disp;
469 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
470 } else if (longlist) {
471 if (pntr->status == VOK) {
472 fprintf(STDOUT, "%-32s ", pntr->name);
473 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
475 fprintf(STDOUT, "RW ");
477 fprintf(STDOUT, "RO ");
479 fprintf(STDOUT, "BK ");
480 fprintf(STDOUT, "%10d K ", pntr->size);
481 if (pntr->inUse == 1) {
482 fprintf(STDOUT, "On-line");
485 fprintf(STDOUT, "Off-line");
488 if (pntr->needsSalvaged == 1)
489 fprintf(STDOUT, "**needs salvage**");
490 fprintf(STDOUT, "\n");
491 MapPartIdIntoName(part, pname);
492 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
494 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
495 (unsigned long)pntr->parentID,
496 (unsigned long)pntr->cloneID,
497 (unsigned long)pntr->backupID);
498 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
499 fprintf(STDOUT, " Creation %s",
500 vos_ctime(& pntr->creationDate));
501 #ifdef FULL_LISTVOL_SWITCH
502 fprintf(STDOUT, " Copy %s",
503 vos_ctime( & pntr->copyDate));
504 if (!pntr->backupDate)
505 fprintf(STDOUT, " Backup Never\n");
507 fprintf(STDOUT, " Backup %s",
508 vos_ctime( & pntr->backupDate));
509 if (pntr->accessDate)
510 fprintf(STDOUT, " Last Access %s",
511 vos_ctime( & pntr->accessDate));
513 if (!pntr->updateDate)
514 fprintf(STDOUT, " Last Update Never\n");
516 fprintf(STDOUT, " Last Update %s",
517 vos_ctime( & pntr->updateDate));
519 " %d accesses in the past day (i.e., vnode references)\n",
522 } else if (pntr->status == VBUSY) {
524 qPut(&busyHead, pntr->volid);
526 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
527 (unsigned long)pntr->volid);
530 qPut(¬okHead, pntr->volid);
532 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
533 (unsigned long)pntr->volid);
535 fprintf(STDOUT, "\n");
536 } else { /* default listing */
537 if (pntr->status == VOK) {
538 fprintf(STDOUT, "%-32s ", pntr->name);
539 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
541 fprintf(STDOUT, "RW ");
543 fprintf(STDOUT, "RO ");
545 fprintf(STDOUT, "BK ");
546 fprintf(STDOUT, "%10d K ", pntr->size);
547 if (pntr->inUse == 1) {
548 fprintf(STDOUT, "On-line");
551 fprintf(STDOUT, "Off-line");
554 if (pntr->needsSalvaged == 1)
555 fprintf(STDOUT, "**needs salvage**");
556 fprintf(STDOUT, "\n");
557 } else if (pntr->status == VBUSY) {
559 qPut(&busyHead, pntr->volid);
561 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
562 (unsigned long)pntr->volid);
565 qPut(¬okHead, pntr->volid);
567 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
568 (unsigned long)pntr->volid);
573 /*------------------------------------------------------------------------
574 * PRIVATE XDisplayFormat
577 * Display the contents of one extended volume info structure.
580 * a_xInfoP : Ptr to extended volume info struct to print.
581 * a_servID : Server ID to print.
582 * a_partID : Partition ID to print.
583 * a_totalOKP : Ptr to total-OK counter.
584 * a_totalNotOKP : Ptr to total-screwed counter.
585 * a_totalBusyP : Ptr to total-busy counter.
586 * a_fast : Fast listing?
587 * a_int32 : Int32 listing?
588 * a_showProblems : Show volume problems?
594 * Nothing interesting.
598 *------------------------------------------------------------------------*/
601 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
602 a_totalBusyP, a_fast, a_int32, a_showProblems)
603 volintXInfo *a_xInfoP;
613 { /*XDisplayFormat */
621 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
622 } else if (a_int32) {
624 * Fully-detailed listing.
626 if (a_xInfoP->status == VOK) {
628 * Volume's status is OK - all the fields are valid.
630 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
631 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
632 if (a_xInfoP->type == 0)
633 fprintf(STDOUT, "RW ");
634 if (a_xInfoP->type == 1)
635 fprintf(STDOUT, "RO ");
636 if (a_xInfoP->type == 2)
637 fprintf(STDOUT, "BK ");
638 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
639 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
640 if (a_xInfoP->inUse == 1) {
641 fprintf(STDOUT, "On-line");
644 fprintf(STDOUT, "Off-line");
647 fprintf(STDOUT, "\n");
648 MapPartIdIntoName(a_partID, pname);
649 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
651 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
652 (unsigned long)a_xInfoP->parentID,
653 (unsigned long)a_xInfoP->cloneID,
654 (unsigned long)a_xInfoP->backupID);
655 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
656 fprintf(STDOUT, " Creation %s",
657 vos_ctime( & a_xInfoP->creationDate));
658 #ifdef FULL_LISTVOL_SWITCH
659 fprintf(STDOUT, " Copy %s",
660 vos_ctime( & a_xInfoP->copyDate));
661 if (!a_xInfoP->backupDate)
662 fprintf(STDOUT, " Backup Never\n");
664 fprintf(STDOUT, " Backup %s",
665 vos_ctime( & a_xInfoP->backupDate));
666 if (a_xInfoP->accessDate)
667 fprintf(STDOUT, " Last Access %s",
668 vos_ctime( & a_xInfoP->accessDate));
670 if (!a_xInfoP->updateDate)
671 fprintf(STDOUT, " Last Update Never\n");
673 fprintf(STDOUT, " Last Update %s",
674 vos_ctime( & a_xInfoP->updateDate));
676 " %d accesses in the past day (i.e., vnode references)\n",
681 * Print all the read/write and authorship stats.
683 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
685 " |-------------------------------------------|\n");
687 " | Same Network | Diff Network |\n");
689 " |----------|----------|----------|----------|\n");
691 " | Total | Auth | Total | Auth |\n");
693 " |----------|----------|----------|----------|\n");
694 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
695 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
696 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
697 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
698 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
699 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
700 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
701 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
702 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
703 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
705 " |-------------------------------------------|\n\n");
708 " Writes Affecting Authorship\n");
710 " |-------------------------------------------|\n");
712 " | File Authorship | Directory Authorship|\n");
714 " |----------|----------|----------|----------|\n");
716 " | Same | Diff | Same | Diff |\n");
718 " |----------|----------|----------|----------|\n");
719 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
720 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
721 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
722 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
723 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
724 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
725 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
726 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
727 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
728 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
729 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
730 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
731 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
732 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
733 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
734 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
735 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
736 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
737 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
738 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
739 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
740 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
741 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
742 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
743 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
744 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
745 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
746 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
747 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
748 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
750 " |-------------------------------------------|\n");
751 } /*Volume status OK */
752 else if (a_xInfoP->status == VBUSY) {
754 qPut(&busyHead, a_xInfoP->volid);
756 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
757 (unsigned long)a_xInfoP->volid);
761 qPut(¬okHead, a_xInfoP->volid);
763 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
764 (unsigned long)a_xInfoP->volid);
765 } /*Screwed volume */
766 fprintf(STDOUT, "\n");
772 if (a_xInfoP->status == VOK) {
773 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
774 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
775 if (a_xInfoP->type == 0)
776 fprintf(STDOUT, "RW ");
777 if (a_xInfoP->type == 1)
778 fprintf(STDOUT, "RO ");
779 if (a_xInfoP->type == 2)
780 fprintf(STDOUT, "BK ");
781 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
782 if (a_xInfoP->inUse == 1) {
783 fprintf(STDOUT, "On-line");
786 fprintf(STDOUT, "Off-line");
789 fprintf(STDOUT, "\n");
791 else if (a_xInfoP->status == VBUSY) {
793 qPut(&busyHead, a_xInfoP->volid);
795 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
796 (unsigned long)a_xInfoP->volid);
800 qPut(¬okHead, a_xInfoP->volid);
802 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
803 (unsigned long)a_xInfoP->volid);
804 } /*Screwed volume */
805 } /*Default listing */
806 } /*XDisplayFormat */
808 #ifdef FULL_LISTVOL_SWITCH
809 /*------------------------------------------------------------------------
810 * PRIVATE XDisplayFormat2
813 * Display the formated contents of one extended volume info structure.
816 * a_xInfoP : Ptr to extended volume info struct to print.
817 * a_servID : Server ID to print.
818 * a_partID : Partition ID to print.
819 * a_totalOKP : Ptr to total-OK counter.
820 * a_totalNotOKP : Ptr to total-screwed counter.
821 * a_totalBusyP : Ptr to total-busy counter.
822 * a_fast : Fast listing?
823 * a_int32 : Int32 listing?
824 * a_showProblems : Show volume problems?
830 * Nothing interesting.
834 *------------------------------------------------------------------------*/
837 XDisplayFormat2(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
838 a_totalBusyP, a_fast, a_int32, a_showProblems)
839 volintXInfo *a_xInfoP;
849 { /*XDisplayFormat */
854 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
855 } else if (a_int32) {
857 * Fully-detailed listing.
859 if (a_xInfoP->status == VOK) {
861 * Volume's status is OK - all the fields are valid.
864 static long server_cache = -1, partition_cache = -1;
865 static char hostname[256], address[32], pname[16];
866 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
867 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
869 if (a_servID != server_cache) {
873 strcpy(hostname, hostutil_GetNameByINet(a_servID));
874 strcpy(address, inet_ntoa(s));
875 server_cache = a_servID;
877 if (a_partID != partition_cache) {
878 MapPartIdIntoName(a_partID, pname);
879 partition_cache = a_partID;
882 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
883 fprintf(STDOUT, "id\t\t%lu\n", a_xInfoP->volid);
884 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
885 fprintf(STDOUT, "part\t\t%s\n", pname);
886 switch (a_xInfoP->status) {
888 fprintf(STDOUT, "status\t\tOK\n");
891 fprintf(STDOUT, "status\t\tBUSY\n");
894 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
897 fprintf(STDOUT, "backupID\t%lu\n", a_xInfoP->backupID);
898 fprintf(STDOUT, "parentID\t%lu\n", a_xInfoP->parentID);
899 fprintf(STDOUT, "cloneID\t\t%lu\n", a_xInfoP->cloneID);
900 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
901 switch (a_xInfoP->type) {
903 fprintf(STDOUT, "type\t\tRW\n");
906 fprintf(STDOUT, "type\t\tRO\n");
909 fprintf(STDOUT, "type\t\tBK\n");
912 fprintf(STDOUT, "type\t\t?\n");
915 fprintf(STDOUT, "creationDate\t%-9lu\t%s", a_xInfoP->creationDate,
916 vos_ctime(&a_xInfoP->creationDate));
917 fprintf(STDOUT, "accessDate\t%-9lu\t%s", a_xInfoP->accessDate,
918 vos_ctime(&a_xInfoP->accessDate));
919 fprintf(STDOUT, "updateDate\t%-9lu\t%s", a_xInfoP->updateDate,
920 vos_ctime(&a_xInfoP->updateDate));
921 fprintf(STDOUT, "backupDate\t%-9lu\t%s", a_xInfoP->backupDate,
922 vos_ctime(&a_xInfoP->backupDate));
923 fprintf(STDOUT, "copyDate\t%-9lu\t%s", a_xInfoP->copyDate,
924 vos_ctime(&a_xInfoP->copyDate));
926 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
927 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
929 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
930 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
934 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
935 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
936 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
937 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
939 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
940 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
941 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
942 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
946 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
947 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
948 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
949 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
952 } /*Volume status OK */
953 else if (a_xInfoP->status == VBUSY) {
955 qPut(&busyHead, a_xInfoP->volid);
957 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
958 (unsigned long)a_xInfoP->volid);
962 qPut(¬okHead, a_xInfoP->volid);
964 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
965 (unsigned long)a_xInfoP->volid);
966 } /*Screwed volume */
972 if (a_xInfoP->status == VOK) {
973 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
974 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
975 if (a_xInfoP->type == 0)
976 fprintf(STDOUT, "type\tRW\n");
977 if (a_xInfoP->type == 1)
978 fprintf(STDOUT, "type\tRO\n");
979 if (a_xInfoP->type == 2)
980 fprintf(STDOUT, "type\tBK\n");
981 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
983 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
984 if (a_xInfoP->inUse == 1)
990 else if (a_xInfoP->status == VBUSY) {
992 qPut(&busyHead, a_xInfoP->volid);
994 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
995 (unsigned long)a_xInfoP->volid);
999 qPut(¬okHead, a_xInfoP->volid);
1001 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1002 (unsigned long)a_xInfoP->volid);
1003 } /*Screwed volume */
1004 } /*Default listing */
1005 } /*XDisplayFormat */
1006 #endif /*FULL_LISTVOL_SWITCH*/
1008 #ifdef FULL_LISTVOL_SWITCH
1010 DisplayFormat2(server, partition, pntr)
1011 long server, partition;
1014 static long server_cache = -1, partition_cache = -1;
1015 static char hostname[256], address[32], pname[16];
1017 if (server != server_cache) {
1021 strcpy(hostname, hostutil_GetNameByINet(server));
1022 strcpy(address, inet_ntoa(s));
1023 server_cache = server;
1025 if (partition != partition_cache) {
1026 MapPartIdIntoName(partition, pname);
1027 partition_cache = partition;
1029 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1030 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
1031 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1032 fprintf(STDOUT, "part\t\t%s\n", pname);
1033 switch (pntr->status) {
1035 fprintf(STDOUT, "status\t\tOK\n");
1038 fprintf(STDOUT, "status\t\tBUSY\n");
1041 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1044 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
1045 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
1046 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
1047 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1048 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1049 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1050 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1051 switch (pntr->type) {
1053 fprintf(STDOUT, "type\t\tRW\n");
1056 fprintf(STDOUT, "type\t\tRO\n");
1059 fprintf(STDOUT, "type\t\tBK\n");
1062 fprintf(STDOUT, "type\t\t?\n");
1065 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
1066 vos_ctime(&pntr->creationDate));
1067 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
1068 vos_ctime(&pntr->accessDate));
1069 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
1070 vos_ctime(&pntr->updateDate));
1071 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
1072 vos_ctime(&pntr->backupDate));
1073 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
1074 vos_ctime(&pntr->copyDate));
1075 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
1076 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1077 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1078 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
1079 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1080 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1081 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
1082 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
1083 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
1088 DisplayVolumes2(server, partition, pntr, count)
1090 long server, partition, count;
1094 for (i = 0; i < count; i++) {
1095 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1096 DisplayFormat2(server, partition, pntr);
1097 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1102 #endif /* FULL_LISTVOL_SWITCH */
1105 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
1106 afs_int32 server, part;
1108 afs_int32 count, longlist, fast;
1111 int totalOK, totalNotOK, totalBusy, i;
1119 for (i = 0; i < count; i++) {
1120 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1125 while (busyHead.count) {
1126 qGet(&busyHead, &volid);
1127 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1128 (unsigned long)volid);
1132 while (notokHead.count) {
1133 qGet(¬okHead, &volid);
1134 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1135 (unsigned long)volid);
1139 fprintf(STDOUT, "\n");
1142 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1143 totalOK, totalNotOK, totalBusy);
1147 /*------------------------------------------------------------------------
1148 * PRIVATE XDisplayVolumes
1151 * Display extended volume information.
1154 * a_servID : Pointer to the Rx call we're performing.
1155 * a_partID : Partition for which we want the extended list.
1156 * a_xInfoP : Ptr to extended volume info.
1157 * a_count : Number of volume records contained above.
1158 * a_int32 : Int32 listing generated?
1159 * a_fast : Fast listing generated?
1160 * a_quiet : Quiet listing generated?
1166 * Nothing interesting.
1170 *------------------------------------------------------------------------*/
1173 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1177 volintXInfo *a_xInfoP;
1183 { /*XDisplayVolumes */
1185 int totalOK; /*Total OK volumes */
1186 int totalNotOK; /*Total screwed volumes */
1187 int totalBusy; /*Total busy volumes */
1188 int i; /*Loop variable */
1189 afs_int32 volid; /*Current volume ID */
1192 * Initialize counters and (global!!) queues.
1201 * Display each volume in the list.
1203 for (i = 0; i < a_count; i++) {
1204 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1205 &totalBusy, a_fast, a_int32, 0);
1210 * If any volumes were found to be busy or screwed, display them.
1213 while (busyHead.count) {
1214 qGet(&busyHead, &volid);
1215 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1216 (unsigned long)volid);
1220 while (notokHead.count) {
1221 qGet(¬okHead, &volid);
1222 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1223 (unsigned long)volid);
1228 fprintf(STDOUT, "\n");
1231 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1232 totalOK, totalNotOK, totalBusy);
1236 } /*XDisplayVolumes */
1237 #ifdef FULL_LISTVOL_SWITCH
1238 /*------------------------------------------------------------------------
1239 * PRIVATE XDisplayVolumes2
1242 * Display extended formated volume information.
1245 * a_servID : Pointer to the Rx call we're performing.
1246 * a_partID : Partition for which we want the extended list.
1247 * a_xInfoP : Ptr to extended volume info.
1248 * a_count : Number of volume records contained above.
1249 * a_int32 : Int32 listing generated?
1250 * a_fast : Fast listing generated?
1251 * a_quiet : Quiet listing generated?
1257 * Nothing interesting.
1261 *------------------------------------------------------------------------*/
1264 XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1268 volintXInfo *a_xInfoP;
1274 { /*XDisplayVolumes */
1276 int totalOK; /*Total OK volumes */
1277 int totalNotOK; /*Total screwed volumes */
1278 int totalBusy; /*Total busy volumes */
1279 int i; /*Loop variable */
1280 afs_int32 volid; /*Current volume ID */
1283 * Initialize counters and (global!!) queues.
1292 * Display each volume in the list.
1294 for (i = 0; i < a_count; i++) {
1295 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1296 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1297 &totalBusy, a_fast, a_int32, 0);
1298 fprintf(STDOUT, "END_OF_ENTRY\n");
1303 * If any volumes were found to be busy or screwed, display them.
1306 while (busyHead.count) {
1307 qGet(&busyHead, &volid);
1308 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1309 (unsigned long)volid);
1313 while (notokHead.count) {
1314 qGet(¬okHead, &volid);
1315 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1316 (unsigned long)volid);
1321 fprintf(STDOUT, "\n");
1324 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1325 totalOK, totalNotOK, totalBusy);
1329 } /*XDisplayVolumes2 */
1330 #endif /* FULL_LISTVOL_SWITCH */
1333 /* set <server> and <part> to the correct values depending on
1334 * <voltype> and <entry> */
1336 GetServerAndPart(entry, voltype, server, part, previdx)
1337 struct nvldbentry *entry;
1338 afs_int32 *server, *part;
1342 int i, istart, vtype;
1347 /* Doesn't check for non-existance of backup volume */
1348 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1350 istart = 0; /* seach the entire entry */
1353 /* Seach from beginning of entry or pick up where we left off */
1354 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1357 for (i = istart; i < entry->nServers; i++) {
1358 if (entry->serverFlags[i] & vtype) {
1359 *server = entry->serverNumber[i];
1360 *part = entry->serverPartition[i];
1366 /* Didn't find any, return -1 */
1372 PostVolumeStats(entry)
1373 struct nvldbentry *entry;
1375 SubEnumerateEntry(entry);
1376 /* Check for VLOP_ALLOPERS */
1377 if (entry->flags & VLOP_ALLOPERS)
1378 fprintf(STDOUT, " Volume is currently LOCKED \n");
1382 /*------------------------------------------------------------------------
1383 * PRIVATE XVolumeStats
1386 * Display extended volume information.
1389 * a_xInfoP : Ptr to extended volume info.
1390 * a_entryP : Ptr to the volume's VLDB entry.
1391 * a_srvID : Server ID.
1392 * a_partID : Partition ID.
1393 * a_volType : Type of volume to print.
1399 * Nothing interesting.
1403 *------------------------------------------------------------------------*/
1406 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1407 volintXInfo *a_xInfoP;
1408 struct nvldbentry *a_entryP;
1415 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1417 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1418 a_srvID, /*Server ID to print */
1419 a_partID, /*Partition ID to print */
1420 &totalOK, /*Ptr to total-OK counter */
1421 &totalNotOK, /*Ptr to total-screwed counter */
1422 &totalBusy, /*Ptr to total-busy counter */
1423 0, /*Don't do a fast listing */
1424 1, /*Do a long listing */
1425 1); /*Show volume problems */
1431 VolumeStats(pntr, entry, server, part, voltype)
1433 struct nvldbentry *entry;
1435 afs_int32 server, part;
1437 int totalOK, totalNotOK, totalBusy;
1439 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1444 /* command to forcibly remove a volume */
1447 register struct cmd_syndesc *as;
1449 register afs_int32 code;
1450 afs_int32 volID, err;
1455 server = GetServer(tp = as->parms[0].items->data);
1457 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1461 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1463 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1467 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1470 PrintError("", err);
1473 "vos: could not parse '%s' as a numeric volume ID", tp);
1478 "vos: forcibly removing all traces of volume %d, please wait...",
1481 code = UV_NukeVolume(server, partID, volID);
1483 fprintf(STDOUT, "done.\n");
1485 fprintf(STDOUT, "failed with code %d.\n", code);
1490 /*------------------------------------------------------------------------
1491 * PRIVATE ExamineVolume
1494 * Routine used to examine a single volume, contacting the VLDB as
1495 * well as the Volume Server.
1498 * as : Ptr to parsed command line arguments.
1501 * 0 for a successful operation,
1502 * Otherwise, one of the ubik or VolServer error values.
1505 * Nothing interesting.
1509 *------------------------------------------------------------------------
1513 register struct cmd_syndesc *as;
1515 struct nvldbentry entry;
1516 afs_int32 vcode = 0;
1517 volintInfo *pntr = (volintInfo *) 0;
1518 volintXInfo *xInfoP = (volintXInfo *) 0;
1520 afs_int32 code, err, error = 0;
1521 int voltype, foundserv = 0, foundentry = 0;
1522 afs_int32 aserver, apart;
1524 int wantExtendedInfo; /*Do we want extended vol info? */
1526 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1528 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1531 PrintError("", err);
1533 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1534 as->parms[0].items->data);
1539 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1540 (unsigned long)volid);
1543 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1546 "Could not fetch the entry for volume number %lu from VLDB \n",
1547 (unsigned long)volid);
1551 fprintf(STDOUT, "done\n");
1552 MapHostToNetwork(&entry);
1554 if (entry.volumeId[RWVOL] == volid)
1556 else if (entry.volumeId[BACKVOL] == volid)
1558 else /* (entry.volumeId[ROVOL] == volid) */
1561 do { /* do {...} while (voltype == ROVOL) */
1562 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1563 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1564 * If its a RO vol, get the next RO entry.
1566 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1567 &aserver, &apart, &previdx);
1568 if (previdx == -1) { /* searched all entries */
1570 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1571 as->parms[0].items->data);
1578 /* Get information about the volume from the server */
1580 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1581 hostutil_GetNameByINet(aserver));
1584 if (wantExtendedInfo)
1585 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1587 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1589 fprintf(STDOUT, "done\n");
1593 if (code == ENODEV) {
1594 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1595 /* The VLDB says there is no backup volume and its not on disk */
1596 fprintf(STDERR, "Volume %s does not exist\n",
1597 as->parms[0].items->data);
1601 "Volume does not exist on server %s as indicated by the VLDB\n",
1602 hostutil_GetNameByINet(aserver));
1605 PrintDiagnostics("examine", code);
1607 fprintf(STDOUT, "\n");
1610 if (wantExtendedInfo)
1611 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1613 #ifdef FULL_LISTVOL_SWITCH
1614 if (as->parms[2].items) {
1615 DisplayFormat2(aserver, apart, pntr);
1616 EnumerateEntry(&entry);
1618 #endif /* FULL_LISTVOL_SWITCH */
1619 VolumeStats(pntr, &entry, aserver, apart, voltype);
1621 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1622 /* The VLDB says there is no backup volume yet we found one on disk */
1623 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1624 as->parms[0].items->data);
1633 } while (voltype == ROVOL);
1636 fprintf(STDERR, "Dump only information from VLDB\n\n");
1637 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1639 PostVolumeStats(&entry);
1644 /*------------------------------------------------------------------------
1648 * Routine used to change the status of a single volume.
1651 * as : Ptr to parsed command line arguments.
1654 * 0 for a successful operation,
1655 * Otherwise, one of the ubik or VolServer error values.
1658 * Nothing interesting.
1662 *------------------------------------------------------------------------
1666 register struct cmd_syndesc *as;
1668 struct nvldbentry entry;
1669 afs_int32 vcode = 0;
1672 afs_int32 code, err;
1673 afs_int32 aserver, apart;
1676 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1679 PrintError("", err);
1681 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1682 as->parms[0].items->data);
1686 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1689 "Could not fetch the entry for volume number %lu from VLDB \n",
1690 (unsigned long)volid);
1693 MapHostToNetwork(&entry);
1695 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1696 if (previdx == -1) {
1697 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1698 as->parms[0].items->data);
1702 init_volintInfo(&info);
1706 if (as->parms[1].items) {
1708 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1710 fprintf(STDERR, "invalid quota value\n");
1714 if (as->parms[2].items) {
1718 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1721 "Could not update volume info fields for volume number %lu\n",
1722 (unsigned long)volid);
1726 /*------------------------------------------------------------------------
1730 * Brings a volume online.
1733 * as : Ptr to parsed command line arguments.
1736 * 0 for a successful operation,
1739 * Nothing interesting.
1743 *------------------------------------------------------------------------
1747 register struct cmd_syndesc *as;
1749 afs_int32 server, partition, volid;
1750 afs_int32 code, err = 0;
1752 server = GetServer(as->parms[0].items->data);
1754 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1755 as->parms[0].items->data);
1759 partition = volutil_GetPartitionID(as->parms[1].items->data);
1760 if (partition < 0) {
1761 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1762 as->parms[1].items->data);
1766 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1769 PrintError("", err);
1771 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1772 as->parms[0].items->data);
1776 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1779 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1786 /*------------------------------------------------------------------------
1787 * PRIVATE volOffline
1790 * Brings a volume offline.
1793 * as : Ptr to parsed command line arguments.
1796 * 0 for a successful operation,
1799 * Nothing interesting.
1803 *------------------------------------------------------------------------
1806 volOffline(register struct cmd_syndesc *as)
1808 afs_int32 server, partition, volid;
1809 afs_int32 code, err = 0;
1810 afs_int32 transflag, sleeptime, transdone;
1812 server = GetServer(as->parms[0].items->data);
1814 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1815 as->parms[0].items->data);
1819 partition = volutil_GetPartitionID(as->parms[1].items->data);
1820 if (partition < 0) {
1821 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1822 as->parms[1].items->data);
1826 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1829 PrintError("", err);
1831 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1832 as->parms[0].items->data);
1836 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1837 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1838 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1839 if (as->parms[4].items && !as->parms[3].items) {
1840 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1845 UV_SetVolume(server, partition, volid, transflag, transdone,
1848 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1856 CreateVolume(register struct cmd_syndesc *as)
1860 afs_int32 volid, code;
1861 struct nvldbentry entry;
1866 tserver = GetServer(as->parms[0].items->data);
1868 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1869 as->parms[0].items->data);
1872 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1874 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1875 as->parms[1].items->data);
1878 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1880 PrintError("", code);
1883 "vos : partition %s does not exist on the server\n",
1884 as->parms[1].items->data);
1887 if (!ISNAMEVALID(as->parms[2].items->data)) {
1889 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1890 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1893 if (!VolNameOK(as->parms[2].items->data)) {
1895 "Illegal volume name %s, should not end in .readonly or .backup\n",
1896 as->parms[2].items->data);
1899 if (IsNumeric(as->parms[2].items->data)) {
1900 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1901 as->parms[2].items->data);
1904 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1906 fprintf(STDERR, "Volume %s already exists\n",
1907 as->parms[2].items->data);
1908 PrintDiagnostics("create", code);
1912 if (as->parms[3].items) {
1913 if (!IsNumeric(as->parms[3].items->data)) {
1914 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1915 as->parms[3].items->data);
1919 code = util_GetInt32(as->parms[3].items->data, "a);
1921 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1927 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1930 PrintDiagnostics("create", code);
1933 MapPartIdIntoName(pnum, part);
1934 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1935 (unsigned long)volid, part, as->parms[0].items->data);
1942 struct nvldbentry *entry;
1945 afs_int32 error, code, curserver, curpart, volid;
1947 MapHostToNetwork(entry);
1949 for (i = 0; i < entry->nServers; i++) {
1950 curserver = entry->serverNumber[i];
1951 curpart = entry->serverPartition[i];
1952 if (entry->serverFlags[i] & ITSROVOL) {
1953 volid = entry->volumeId[ROVOL];
1955 volid = entry->volumeId[RWVOL];
1957 code = UV_DeleteVolume(curserver, curpart, volid);
1966 struct cmd_syndesc *as;
1968 afs_int32 err, code = 0;
1969 afs_int32 server = 0, partition = -1, volid;
1973 if (as->parms[0].items) {
1974 server = GetServer(as->parms[0].items->data);
1976 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1977 as->parms[0].items->data);
1982 if (as->parms[1].items) {
1983 partition = volutil_GetPartitionID(as->parms[1].items->data);
1984 if (partition < 0) {
1985 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1986 as->parms[1].items->data);
1990 /* Check for validity of the partition */
1991 if (!IsPartValid(partition, server, &code)) {
1993 PrintError("", code);
1996 "vos : partition %s does not exist on the server\n",
1997 as->parms[1].items->data);
2003 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2005 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2006 as->parms[2].items->data);
2008 PrintError("", err);
2012 /* If the server or partition option are not complete, try to fill
2013 * them in from the VLDB entry.
2015 if ((partition == -1) || !server) {
2016 struct nvldbentry entry;
2018 code = VLDB_GetEntryByID(volid, -1, &entry);
2021 "Could not fetch the entry for volume %lu from VLDB\n",
2022 (unsigned long)volid);
2023 PrintError("", code);
2027 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2028 || ((volid == entry.volumeId[BACKVOL])
2029 && (entry.flags & BACK_EXISTS))) {
2030 idx = Lp_GetRwIndex(&entry);
2031 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2032 || ((partition != -1)
2033 && (partition != entry.serverPartition[idx]))) {
2034 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2035 as->parms[2].items->data);
2038 } else if ((volid == entry.volumeId[ROVOL])
2039 && (entry.flags & RO_EXISTS)) {
2040 for (idx = -1, j = 0; j < entry.nServers; j++) {
2041 if (entry.serverFlags[j] != ITSROVOL)
2044 if (((server == 0) || (server == entry.serverNumber[j]))
2045 && ((partition == -1)
2046 || (partition == entry.serverPartition[j]))) {
2049 "VLDB: Volume '%s' matches more than one RO\n",
2050 as->parms[2].items->data);
2057 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2058 as->parms[2].items->data);
2062 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2063 as->parms[2].items->data);
2067 server = htonl(entry.serverNumber[idx]);
2068 partition = entry.serverPartition[idx];
2072 code = UV_DeleteVolume(server, partition, volid);
2074 PrintDiagnostics("remove", code);
2078 MapPartIdIntoName(partition, pname);
2079 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2080 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2084 #define TESTM 0 /* set for move space tests, clear for production */
2087 register struct cmd_syndesc *as;
2090 afs_int32 volid, fromserver, toserver, frompart, topart;
2091 afs_int32 flags, code, err;
2092 char fromPartName[10], toPartName[10];
2094 struct diskPartition partition; /* for space check */
2097 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2100 PrintError("", err);
2102 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2103 as->parms[0].items->data);
2106 fromserver = GetServer(as->parms[1].items->data);
2107 if (fromserver == 0) {
2108 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2109 as->parms[1].items->data);
2112 toserver = GetServer(as->parms[3].items->data);
2113 if (toserver == 0) {
2114 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2115 as->parms[3].items->data);
2118 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2120 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2121 as->parms[2].items->data);
2124 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2126 PrintError("", code);
2129 "vos : partition %s does not exist on the server\n",
2130 as->parms[2].items->data);
2133 topart = volutil_GetPartitionID(as->parms[4].items->data);
2135 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2136 as->parms[4].items->data);
2139 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2141 PrintError("", code);
2144 "vos : partition %s does not exist on the server\n",
2145 as->parms[4].items->data);
2150 if (as->parms[5].items) flags |= RV_NOCLONE;
2153 * check source partition for space to clone volume
2156 MapPartIdIntoName(topart, toPartName);
2157 MapPartIdIntoName(frompart, fromPartName);
2160 * check target partition for space to move volume
2163 code = UV_PartitionInfo(toserver, toPartName, &partition);
2165 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2169 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2172 p = (volintInfo *) 0;
2173 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2175 fprintf(STDERR, "vos:cannot access volume %lu\n",
2176 (unsigned long)volid);
2181 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2183 if (partition.free <= p->size) {
2185 "vos: no space on target partition %s to move volume %lu\n",
2186 toPartName, (unsigned long)volid);
2193 fprintf(STDOUT, "size test - don't do move\n");
2197 /* successful move still not guaranteed but shoot for it */
2200 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2202 PrintDiagnostics("move", code);
2205 MapPartIdIntoName(topart, toPartName);
2206 MapPartIdIntoName(frompart, fromPartName);
2207 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2208 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2209 as->parms[3].items->data, toPartName);
2216 register struct cmd_syndesc *as;
2218 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
2219 char fromPartName[10], toPartName[10], *tovolume;
2220 struct nvldbentry entry;
2221 struct diskPartition partition; /* for space check */
2224 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2227 PrintError("", err);
2229 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2230 as->parms[0].items->data);
2233 fromserver = GetServer(as->parms[1].items->data);
2234 if (fromserver == 0) {
2235 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2236 as->parms[1].items->data);
2240 toserver = GetServer(as->parms[4].items->data);
2241 if (toserver == 0) {
2242 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2243 as->parms[4].items->data);
2247 tovolume = as->parms[3].items->data;
2248 if (!ISNAMEVALID(tovolume)) {
2250 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2251 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2254 if (!VolNameOK(tovolume)) {
2256 "Illegal volume name %s, should not end in .readonly or .backup\n",
2260 if (IsNumeric(tovolume)) {
2261 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2265 code = VLDB_GetEntryByName(tovolume, &entry);
2267 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2268 PrintDiagnostics("copy", code);
2272 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2274 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2275 as->parms[2].items->data);
2278 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2280 PrintError("", code);
2283 "vos : partition %s does not exist on the server\n",
2284 as->parms[2].items->data);
2288 topart = volutil_GetPartitionID(as->parms[5].items->data);
2290 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2291 as->parms[5].items->data);
2294 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2296 PrintError("", code);
2299 "vos : partition %s does not exist on the server\n",
2300 as->parms[5].items->data);
2305 if (as->parms[6].items) flags |= RV_OFFLINE;
2306 if (as->parms[7].items) flags |= RV_RDONLY;
2307 if (as->parms[8].items) flags |= RV_NOCLONE;
2309 MapPartIdIntoName(topart, toPartName);
2310 MapPartIdIntoName(frompart, fromPartName);
2313 * check target partition for space to move volume
2316 code = UV_PartitionInfo(toserver, toPartName, &partition);
2318 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2322 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2325 p = (volintInfo *) 0;
2326 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2328 fprintf(STDERR, "vos:cannot access volume %lu\n",
2329 (unsigned long)volid);
2334 if (partition.free <= p->size) {
2336 "vos: no space on target partition %s to copy volume %lu\n",
2337 toPartName, (unsigned long)volid);
2343 /* successful copy still not guaranteed but shoot for it */
2346 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2349 PrintDiagnostics("copy", code);
2352 MapPartIdIntoName(topart, toPartName);
2353 MapPartIdIntoName(frompart, fromPartName);
2354 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2355 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2356 tovolume, as->parms[4].items->data, toPartName);
2364 register struct cmd_syndesc *as;
2366 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2367 afs_int32 code, err, flags;
2368 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2369 struct nvldbentry entry;
2370 struct diskPartition partition; /* for space check */
2373 p = (volintInfo *) 0;
2374 q = (volintInfo *) 0;
2376 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2379 PrintError("", err);
2381 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2382 as->parms[0].items->data);
2385 fromserver = GetServer(as->parms[1].items->data);
2386 if (fromserver == 0) {
2387 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2388 as->parms[1].items->data);
2392 toserver = GetServer(as->parms[3].items->data);
2393 if (toserver == 0) {
2394 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2395 as->parms[3].items->data);
2399 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2401 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2402 as->parms[2].items->data);
2405 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2407 PrintError("", code);
2410 "vos : partition %s does not exist on the server\n",
2411 as->parms[2].items->data);
2415 topart = volutil_GetPartitionID(as->parms[4].items->data);
2417 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2418 as->parms[4].items->data);
2421 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2423 PrintError("", code);
2426 "vos : partition %s does not exist on the server\n",
2427 as->parms[4].items->data);
2431 if (as->parms[5].items) {
2432 tovolume = as->parms[5].items->data;
2433 if (!ISNAMEVALID(tovolume)) {
2435 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2436 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2439 if (!VolNameOK(tovolume)) {
2441 "Illegal volume name %s, should not end in .readonly or .backup\n",
2445 if (IsNumeric(tovolume)) {
2447 "Illegal volume name %s, should not be a number\n",
2452 /* use actual name of source volume */
2453 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2455 fprintf(STDERR, "vos:cannot access volume %lu\n",
2456 (unsigned long)volid);
2459 strcpy(toVolName, p->name);
2460 tovolume = toVolName;
2461 /* save p for size checks later */
2464 if (as->parms[6].items) {
2465 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2468 PrintError("", err);
2470 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2471 as->parms[6].items->data);
2477 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2480 PrintError("", err);
2482 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2491 if (as->parms[7].items) flags |= RV_OFFLINE;
2492 if (as->parms[8].items) flags |= RV_RDONLY;
2493 if (as->parms[9].items) flags |= RV_NOCLONE;
2494 if (as->parms[10].items) flags |= RV_CPINCR;
2496 MapPartIdIntoName(topart, toPartName);
2497 MapPartIdIntoName(frompart, fromPartName);
2500 * check target partition for space to move volume
2503 code = UV_PartitionInfo(toserver, toPartName, &partition);
2505 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2509 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2512 /* Don't do this again if we did it above */
2514 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2516 fprintf(STDERR, "vos:cannot access volume %lu\n",
2517 (unsigned long)volid);
2522 /* OK if this fails */
2523 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2525 /* Treat existing volume size as "free" */
2527 p->size = (q->size < p->size) ? p->size - q->size : 0;
2529 if (partition.free <= p->size) {
2531 "vos: no space on target partition %s to copy volume %lu\n",
2532 toPartName, (unsigned long)volid);
2540 /* successful copy still not guaranteed but shoot for it */
2543 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2544 topart, tovolid, flags);
2546 PrintDiagnostics("shadow", code);
2549 MapPartIdIntoName(topart, toPartName);
2550 MapPartIdIntoName(frompart, fromPartName);
2551 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2552 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2553 as->parms[3].items->data, toPartName);
2561 register struct cmd_syndesc *as;
2563 afs_int32 server, part, volid, cloneid, voltype;
2564 char partName[10], *volname;
2565 afs_int32 code, err, flags;
2566 struct nvldbentry entry;
2568 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2571 PrintError("", err);
2573 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2574 as->parms[0].items->data);
2578 if (as->parms[1].items || as->parms[2].items) {
2579 if (!as->parms[1].items || !as->parms[2].items) {
2581 "Must specify both -server and -partition options\n");
2584 server = GetServer(as->parms[1].items->data);
2586 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2587 as->parms[1].items->data);
2590 part = volutil_GetPartitionID(as->parms[2].items->data);
2592 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2593 as->parms[2].items->data);
2596 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2598 PrintError("", code);
2601 "vos : partition %s does not exist on the server\n",
2602 as->parms[2].items->data);
2606 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2612 if (as->parms[3].items) {
2613 volname = as->parms[3].items->data;
2614 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2616 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2617 volname, VOLSER_OLDMAXVOLNAME - 1);
2620 if (!VolNameOK(volname)) {
2622 "Illegal volume name %s, should not end in .readonly or .backup\n",
2626 if (IsNumeric(volname)) {
2628 "Illegal volume name %s, should not be a number\n",
2635 if (as->parms[4].items) {
2636 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2639 PrintError("", err);
2641 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2642 as->parms[4].items->data);
2648 if (as->parms[5].items) flags |= RV_OFFLINE;
2649 if (as->parms[6].items) flags |= RV_RDONLY;
2653 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2656 PrintDiagnostics("clone", code);
2659 MapPartIdIntoName(part, partName);
2660 fprintf(STDOUT, "Created clone for volume %lu\n",
2661 as->parms[0].items->data);
2669 register struct cmd_syndesc *as;
2671 afs_int32 avolid, aserver, apart, vtype, code, err;
2672 struct nvldbentry entry;
2674 afs_int32 buvolid, buserver, bupart, butype;
2675 struct nvldbentry buentry;
2677 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2680 PrintError("", err);
2682 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2683 as->parms[0].items->data);
2686 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2690 /* verify this is a readwrite volume */
2692 if (vtype != RWVOL) {
2693 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2697 /* is there a backup volume already? */
2699 if (entry.flags & BACK_EXISTS) {
2700 /* yep, where is it? */
2702 buvolid = entry.volumeId[BACKVOL];
2703 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2708 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2711 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2717 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2718 (unsigned long)buvolid, (unsigned long)buserver);
2723 /* nope, carry on */
2725 code = UV_BackupVolume(aserver, apart, avolid);
2728 PrintDiagnostics("backup", code);
2731 fprintf(STDOUT, "Created backup volume for %s \n",
2732 as->parms[0].items->data);
2738 register struct cmd_syndesc *as;
2741 struct nvldbentry entry;
2742 afs_int32 avolid, aserver, apart, vtype, code, err;
2745 if (as->parms[1].items)
2747 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2750 PrintError("", err);
2752 fprintf(STDERR, "vos: can't find volume '%s'\n",
2753 as->parms[0].items->data);
2756 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2760 if (vtype != RWVOL) {
2761 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2765 if (!ISNAMEVALID(entry.name)) {
2767 "Volume name %s is too long, rename before releasing\n",
2772 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2774 PrintDiagnostics("release", code);
2777 fprintf(STDOUT, "Released volume %s successfully\n",
2778 as->parms[0].items->data);
2784 register struct cmd_syndesc *as;
2787 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
2788 char filename[NameLen];
2789 struct nvldbentry entry;
2791 rx_SetRxDeadTime(60 * 10);
2792 for (i = 0; i < MAXSERVERS; i++) {
2793 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2796 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2797 if (rxConn->service)
2798 rxConn->service->connDeadTime = rx_connDeadTime;
2801 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2804 PrintError("", err);
2806 fprintf(STDERR, "vos: can't find volume '%s'\n",
2807 as->parms[0].items->data);
2811 if (as->parms[3].items || as->parms[4].items) {
2812 if (!as->parms[3].items || !as->parms[4].items) {
2814 "Must specify both -server and -partition options\n");
2817 aserver = GetServer(as->parms[3].items->data);
2819 fprintf(STDERR, "Invalid server name\n");
2822 apart = volutil_GetPartitionID(as->parms[4].items->data);
2824 fprintf(STDERR, "Invalid partition name\n");
2828 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2833 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2834 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2836 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2837 as->parms[1].items->data, code);
2841 if (as->parms[2].items) {
2842 strcpy(filename, as->parms[2].items->data);
2844 strcpy(filename, "");
2847 if (as->parms[5].items) {
2849 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2850 DumpFunction, filename);
2853 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2857 PrintDiagnostics("dump", code);
2860 if (strcmp(filename, ""))
2861 fprintf(STDERR, "Dumped volume %s in file %s\n",
2862 as->parms[0].items->data, filename);
2864 fprintf(STDERR, "Dumped volume %s in stdout \n",
2865 as->parms[0].items->data);
2880 register struct cmd_syndesc *as;
2883 afs_int32 avolid, aserver, apart, code, vcode, err;
2884 afs_int32 aoverwrite = ASK;
2885 afs_int32 acreation = 0, alastupdate = 0;
2886 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2888 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2889 char volname[VOLSER_MAXVOLNAME + 1];
2890 struct nvldbentry entry;
2894 if (as->parms[4].items) {
2895 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2898 PrintError("", err);
2900 fprintf(STDERR, "vos: can't find volume '%s'\n",
2901 as->parms[4].items->data);
2907 if (as->parms[5].items) {
2908 if ((strcmp(as->parms[5].items->data, "a") == 0)
2909 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2911 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2912 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2914 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2915 || (strcmp(as->parms[5].items->data, "inc") == 0)
2916 || (strcmp(as->parms[5].items->data, "increment") == 0)
2917 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2920 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2921 as->parms[5].items->data);
2925 if (as->parms[6].items)
2927 if (as->parms[7].items) {
2932 if (as->parms[8].items) {
2933 if ((strcmp(as->parms[8].items->data, "d") == 0)
2934 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2935 acreation = TS_DUMP;
2936 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2937 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2938 acreation = TS_KEEP;
2939 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2940 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2943 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2944 as->parms[8].items->data);
2949 if (as->parms[9].items) {
2950 if ((strcmp(as->parms[9].items->data, "d") == 0)
2951 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2952 alastupdate = TS_DUMP;
2953 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2954 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2955 alastupdate = TS_KEEP;
2956 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2957 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2958 alastupdate = TS_NEW;
2960 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2961 as->parms[9].items->data);
2966 aserver = GetServer(as->parms[0].items->data);
2968 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2969 as->parms[0].items->data);
2972 apart = volutil_GetPartitionID(as->parms[1].items->data);
2974 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2975 as->parms[1].items->data);
2978 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2980 PrintError("", code);
2983 "vos : partition %s does not exist on the server\n",
2984 as->parms[1].items->data);
2987 strcpy(avolname, as->parms[2].items->data);
2988 if (!ISNAMEVALID(avolname)) {
2990 "vos: the name of the volume %s exceeds the size limit\n",
2994 if (!VolNameOK(avolname)) {
2996 "Illegal volume name %s, should not end in .readonly or .backup\n",
3000 if (as->parms[3].items) {
3001 strcpy(afilename, as->parms[3].items->data);
3002 if (!FileExists(afilename)) {
3003 fprintf(STDERR, "Can't access file %s\n", afilename);
3007 strcpy(afilename, "");
3010 /* Check if volume exists or not */
3012 vsu_ExtractName(volname, avolname);
3013 vcode = VLDB_GetEntryByName(volname, &entry);
3014 if (vcode) { /* no volume - do a full restore */
3015 restoreflags = RV_FULLRST;
3016 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3018 "Volume does not exist; Will perform a full restore\n");
3021 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3022 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3023 restoreflags = RV_FULLRST;
3024 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3026 "%s Volume does not exist; Will perform a full restore\n",
3027 readonly ? "RO" : "RW");
3030 avolid = entry.volumeId[voltype];
3031 } else if (entry.volumeId[voltype] != 0
3032 && entry.volumeId[voltype] != avolid) {
3033 avolid = entry.volumeId[voltype];
3037 else { /* volume exists - do we do a full incremental or abort */
3038 int Oserver, Opart, Otype, vol_elsewhere = 0;
3039 struct nvldbentry Oentry;
3043 avolid = entry.volumeId[voltype];
3044 } else if (entry.volumeId[voltype] != 0
3045 && entry.volumeId[voltype] != avolid) {
3046 avolid = entry.volumeId[voltype];
3049 /* A file name was specified - check if volume is on another partition */
3050 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3054 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3057 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3061 if (!vcode || (Opart != apart))
3064 if (aoverwrite == ASK) {
3065 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3067 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3071 /* Ask what to do */
3072 if (vol_elsewhere) {
3074 "The volume %s %u already exists on a different server/part\n",
3075 volname, entry.volumeId[voltype]);
3077 "Do you want to do a full restore or abort? [fa](a): ");
3080 "The volume %s %u already exists in the VLDB\n",
3081 volname, entry.volumeId[voltype]);
3083 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3086 while (!(dc == EOF || dc == '\n'))
3087 dc = getchar(); /* goto end of line */
3088 if ((c == 'f') || (c == 'F'))
3090 else if ((c == 'i') || (c == 'I'))
3096 if (aoverwrite == ABORT) {
3097 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3099 } else if (aoverwrite == FULL) {
3100 restoreflags = RV_FULLRST;
3102 "Volume exists; Will delete and perform full restore\n");
3103 } else if (aoverwrite == INC) {
3105 if (vol_elsewhere) {
3107 "%s volume %lu already exists on a different server/part; not allowed\n",
3108 readonly ? "RO" : "RW", (unsigned long)avolid);
3114 restoreflags |= RV_OFFLINE;
3116 restoreflags |= RV_RDONLY;
3118 switch (acreation) {
3120 restoreflags |= RV_CRDUMP;
3123 restoreflags |= RV_CRKEEP;
3126 restoreflags |= RV_CRNEW;
3129 if (aoverwrite == FULL)
3130 restoreflags |= RV_CRNEW;
3132 restoreflags |= RV_CRKEEP;
3135 switch (alastupdate) {
3137 restoreflags |= RV_LUDUMP;
3140 restoreflags |= RV_LUKEEP;
3143 restoreflags |= RV_LUNEW;
3146 restoreflags |= RV_LUDUMP;
3150 UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags,
3151 WriteData, afilename);
3153 PrintDiagnostics("restore", code);
3156 MapPartIdIntoName(apart, apartName);
3159 * patch typo here - originally "parms[1]", should be "parms[0]"
3162 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3163 as->parms[0].items->data, apartName);
3169 register struct cmd_syndesc *as;
3172 afs_int32 avolid, code, err;
3174 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3177 PrintError("", err);
3179 fprintf(STDERR, "vos: can't find volume '%s'\n",
3180 as->parms[0].items->data);
3184 code = UV_LockRelease(avolid);
3186 PrintDiagnostics("unlock", code);
3189 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3190 as->parms[0].items->data);
3196 register struct cmd_syndesc *as;
3198 afs_int32 avolid, aserver, apart, code, err;
3199 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3201 vsu_ExtractName(avolname, as->parms[2].items->data);;
3202 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3205 PrintError("", err);
3207 fprintf(STDERR, "vos: can't find volume '%s'\n",
3208 as->parms[2].items->data);
3211 aserver = GetServer(as->parms[0].items->data);
3213 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3214 as->parms[0].items->data);
3217 apart = volutil_GetPartitionID(as->parms[1].items->data);
3219 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3220 as->parms[1].items->data);
3223 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3225 PrintError("", code);
3228 "vos : partition %s does not exist on the server\n",
3229 as->parms[1].items->data);
3232 code = UV_AddSite(aserver, apart, avolid);
3234 PrintDiagnostics("addsite", code);
3237 MapPartIdIntoName(apart, apartName);
3238 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3239 as->parms[0].items->data, apartName, as->parms[2].items->data);
3245 register struct cmd_syndesc *as;
3248 afs_int32 avolid, aserver, apart, code, err;
3249 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3251 vsu_ExtractName(avolname, as->parms[2].items->data);
3252 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3255 PrintError("", err);
3257 fprintf(STDERR, "vos: can't find volume '%s'\n",
3258 as->parms[2].items->data);
3261 aserver = GetServer(as->parms[0].items->data);
3263 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3264 as->parms[0].items->data);
3267 apart = volutil_GetPartitionID(as->parms[1].items->data);
3269 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3270 as->parms[1].items->data);
3274 *skip the partition validity check, since it is possible that the partition
3275 *has since been decomissioned.
3278 if (!IsPartValid(apart,aserver,&code)){
3279 if(code) PrintError("",code);
3280 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3284 code = UV_RemoveSite(aserver, apart, avolid);
3286 PrintDiagnostics("remsite", code);
3289 MapPartIdIntoName(apart, apartName);
3290 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3291 as->parms[0].items->data, apartName, as->parms[2].items->data);
3297 register struct cmd_syndesc *as;
3299 afs_int32 avolid, aserver, apart, code, err;
3302 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3305 PrintError("", err);
3307 fprintf(STDERR, "vos: can't find volume '%s'\n",
3308 as->parms[2].items->data);
3311 aserver = GetServer(as->parms[0].items->data);
3313 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3314 as->parms[0].items->data);
3317 apart = volutil_GetPartitionID(as->parms[1].items->data);
3319 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3320 as->parms[1].items->data);
3323 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3325 PrintError("", code);
3328 "vos : partition %s does not exist on the server\n",
3329 as->parms[1].items->data);
3332 code = UV_ChangeLocation(aserver, apart, avolid);
3334 PrintDiagnostics("addsite", code);
3337 MapPartIdIntoName(apart, apartName);
3338 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3339 as->parms[0].items->data, apartName, as->parms[2].items->data);
3345 register struct cmd_syndesc *as;
3347 afs_int32 aserver, code;
3348 struct partList dummyPartList;
3353 aserver = GetServer(as->parms[0].items->data);
3355 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3356 as->parms[0].items->data);
3361 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3363 PrintDiagnostics("listpart", code);
3367 fprintf(STDOUT, "The partitions on the server are:\n");
3368 for (i = 0; i < cnt; i++) {
3369 if (dummyPartList.partFlags[i] & PARTVALID) {
3370 memset(pname, 0, sizeof(pname));
3371 MapPartIdIntoName(dummyPartList.partId[i], pname);
3372 fprintf(STDOUT, " %10s ", pname);
3374 if ((i % 5) == 0 && (i != 0))
3375 fprintf(STDOUT, "\n");
3378 fprintf(STDOUT, "\n");
3379 fprintf(STDOUT, "Total: %d\n", total);
3385 CompareVolName(p1, p2)
3388 volintInfo *arg1, *arg2;
3390 arg1 = (volintInfo *) p1;
3391 arg2 = (volintInfo *) p2;
3392 return (strcmp(arg1->name, arg2->name));
3396 /*------------------------------------------------------------------------
3397 * PRIVATE XCompareVolName
3400 * Comparison routine for volume names coming from an extended
3404 * a_obj1P : Char ptr to first extended vol info object
3405 * a_obj1P : Char ptr to second extended vol info object
3408 * The value of strcmp() on the volume names within the passed
3409 * objects (i,e., -1, 0, or 1).
3412 * Passed to qsort() as the designated comparison routine.
3416 *------------------------------------------------------------------------*/
3419 XCompareVolName(a_obj1P, a_obj2P)
3420 char *a_obj1P, *a_obj2P;
3422 { /*XCompareVolName */
3425 (((struct volintXInfo *)(a_obj1P))->name,
3426 ((struct volintXInfo *)(a_obj2P))->name));
3428 } /*XCompareVolName */
3431 CompareVolID(p1, p2)
3434 volintInfo *arg1, *arg2;
3436 arg1 = (volintInfo *) p1;
3437 arg2 = (volintInfo *) p2;
3438 if (arg1->volid == arg2->volid)
3440 if (arg1->volid > arg2->volid)
3447 /*------------------------------------------------------------------------
3448 * PRIVATE XCompareVolID
3451 * Comparison routine for volume IDs coming from an extended
3455 * a_obj1P : Char ptr to first extended vol info object
3456 * a_obj1P : Char ptr to second extended vol info object
3459 * The value of strcmp() on the volume names within the passed
3460 * objects (i,e., -1, 0, or 1).
3463 * Passed to qsort() as the designated comparison routine.
3467 *------------------------------------------------------------------------*/
3470 XCompareVolID(a_obj1P, a_obj2P)
3471 char *a_obj1P, *a_obj2P;
3473 { /*XCompareVolID */
3475 afs_int32 id1, id2; /*Volume IDs we're comparing */
3477 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3478 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3486 } /*XCompareVolID */
3488 /*------------------------------------------------------------------------
3489 * PRIVATE ListVolumes
3492 * Routine used to list volumes, contacting the Volume Server
3493 * directly, bypassing the VLDB.
3496 * as : Ptr to parsed command line arguments.
3499 * 0 Successful operation
3502 * Nothing interesting.
3506 *------------------------------------------------------------------------*/
3510 register struct cmd_syndesc *as;
3512 afs_int32 apart, int32list, fast;
3513 afs_int32 aserver, code;
3514 volintInfo *pntr, *oldpntr;
3518 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3519 int wantExtendedInfo; /*Do we want extended vol info? */
3522 struct partList dummyPartList;
3530 if (as->parms[3].items)
3532 if (as->parms[4].items)
3536 if (as->parms[2].items)
3542 if (as->parms[5].items) {
3544 * We can't coexist with the fast flag.
3548 "vos: Can't use the -fast and -extended flags together\n");
3553 * We need to turn on ``long'' listings to get the full effect.
3555 wantExtendedInfo = 1;
3558 wantExtendedInfo = 0;
3559 if (as->parms[1].items) {
3560 apart = volutil_GetPartitionID(as->parms[1].items->data);
3562 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3563 as->parms[1].items->data);
3566 dummyPartList.partId[0] = apart;
3567 dummyPartList.partFlags[0] = PARTVALID;
3570 aserver = GetServer(as->parms[0].items->data);
3572 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3573 as->parms[0].items->data);
3578 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3580 PrintError("", code);
3583 "vos : partition %s does not exist on the server\n",
3584 as->parms[1].items->data);
3588 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3590 PrintDiagnostics("listvol", code);
3594 for (i = 0; i < cnt; i++) {
3595 if (dummyPartList.partFlags[i] & PARTVALID) {
3596 if (wantExtendedInfo)
3598 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3602 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3605 PrintDiagnostics("listvol", code);
3610 if (wantExtendedInfo) {
3611 origxInfoP = xInfoP;
3612 base = (char *)xInfoP;
3615 base = (char *)pntr;
3619 if (wantExtendedInfo)
3620 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3622 qsort(base, count, sizeof(volintInfo), CompareVolName);
3624 if (wantExtendedInfo)
3625 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3627 qsort(base, count, sizeof(volintInfo), CompareVolID);
3629 MapPartIdIntoName(dummyPartList.partId[i], pname);
3632 "Total number of volumes on server %s partition %s: %lu \n",
3633 as->parms[0].items->data, pname,
3634 (unsigned long)count);
3635 if (wantExtendedInfo) {
3636 #ifdef FULL_LISTVOL_SWITCH
3637 if (as->parms[6].items)
3638 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3639 count, int32list, fast, quiet);
3641 #endif /* FULL_LISTVOL_SWITCH */
3642 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3643 count, int32list, fast, quiet);
3646 xInfoP = (volintXInfo *) 0;
3648 #ifdef FULL_LISTVOL_SWITCH
3649 if (as->parms[6].items)
3650 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3653 #endif /* FULL_LISTVOL_SWITCH */
3654 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3655 count, int32list, fast, quiet);
3658 pntr = (volintInfo *) 0;
3667 register struct cmd_syndesc *as;
3669 afs_int32 pnum = 0, code; /* part name */
3675 if (as->parms[0].items) {
3676 tserver = GetServer(as->parms[0].items->data);
3678 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3679 as->parms[0].items->data);
3684 if (as->parms[1].items) {
3685 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3687 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3688 as->parms[1].items->data);
3691 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3693 PrintError("", code);
3696 "vos: partition %s does not exist on the server\n",
3697 as->parms[1].items->data);
3704 "The -partition option requires a -server option\n");
3709 if (as->parms[2].items) {
3710 /* Synchronize an individual volume */
3711 volname = as->parms[2].items->data;
3712 code = UV_SyncVolume(tserver, pnum, volname, flags);
3716 "Without a -volume option, the -server option is required\n");
3719 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3723 PrintDiagnostics("syncvldb", code);
3727 /* Print a summary of what we did */
3729 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3731 fprintf(STDOUT, "VLDB synchronized");
3733 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3736 MapPartIdIntoName(pnum, part);
3737 fprintf(STDOUT, " partition %s\n", part);
3739 fprintf(STDOUT, "\n");
3746 register struct cmd_syndesc *as;
3749 afs_int32 pnum, code; /* part name */
3754 tserver = GetServer(as->parms[0].items->data);
3756 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3757 as->parms[0].items->data);
3760 if (as->parms[1].items) {
3761 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3763 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3764 as->parms[1].items->data);
3767 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3769 PrintError("", code);
3772 "vos : partition %s does not exist on the server\n",
3773 as->parms[1].items->data);
3781 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3783 PrintDiagnostics("syncserv", code);
3787 MapPartIdIntoName(pnum, part);
3788 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3789 as->parms[0].items->data, part);
3791 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3792 as->parms[0].items->data);
3801 struct nvldbentry entry;
3804 /* The vlserver will handle names with the .readonly
3805 * and .backup extension as well as volume ids.
3807 vcode = VLDB_GetEntryByName(name, &entry);
3809 PrintError("", vcode);
3812 MapHostToNetwork(&entry);
3813 EnumerateEntry(&entry);
3815 /* Defect #3027: grubby check to handle locked volume.
3816 * If VLOP_ALLOPERS is set, the entry is locked.
3817 * Leave this routine as is, but put in correct check.
3819 if (entry.flags & VLOP_ALLOPERS)
3820 fprintf(STDOUT, " Volume is currently LOCKED \n");
3827 register struct cmd_syndesc *as;
3830 struct nvldbentry entry;
3831 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3833 if (as->parms[3].items) {
3834 /* force flag is on, use the other version */
3835 return NukeVolume(as);
3838 if (as->parms[4].items) {
3842 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3845 PrintError("", err);
3847 fprintf(STDERR, "vos: can't find volume '%s'\n",
3848 as->parms[2].items->data);
3851 part = volutil_GetPartitionID(as->parms[1].items->data);
3853 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3854 as->parms[1].items->data);
3857 server = GetServer(as->parms[0].items->data);
3859 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3860 as->parms[0].items->data);
3863 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3865 PrintError("", code);
3868 "vos : partition %s does not exist on the server\n",
3869 as->parms[1].items->data);
3872 code = VLDB_GetEntryByID(volid, -1, &entry);
3874 if (volid == entry.volumeId[RWVOL])
3875 backupid = entry.volumeId[BACKVOL];
3877 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3878 (unsigned long)volid);
3881 volintInfo *pntr = (volintInfo *) 0;
3884 code = UV_ListOneVolume(server, part, volid, &pntr);
3886 if (volid == pntr->parentID)
3887 backupid = pntr->backupID;
3893 code = UV_VolumeZap(server, part, backupid);
3895 PrintDiagnostics("zap", code);
3898 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3899 (unsigned long)backupid);
3902 code = UV_VolumeZap(server, part, volid);
3904 PrintDiagnostics("zap", code);
3907 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3914 register struct cmd_syndesc *as;
3917 afs_int32 server, code;
3918 transDebugInfo *pntr, *oldpntr;
3923 server = GetServer(as->parms[0].items->data);
3925 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3926 as->parms[0].items->data);
3929 code = UV_VolserStatus(server, &pntr, &count);
3931 PrintDiagnostics("status", code);
3936 fprintf(STDOUT, "No active transactions on %s\n",
3937 as->parms[0].items->data);
3939 fprintf(STDOUT, "Total transactions: %d\n", count);
3941 for (i = 0; i < count; i++) {
3942 /*print out the relevant info */
3943 fprintf(STDOUT, "--------------------------------------\n");
3944 fprintf(STDOUT, "transaction: %lu created: %s",
3945 (unsigned long)pntr->tid, vos_ctime( & pntr->time));
3946 if (pntr->returnCode) {
3947 fprintf(STDOUT, "returnCode: %lu\n",
3948 (unsigned long)pntr->returnCode);
3951 fprintf(STDOUT, "attachFlags: ");
3952 switch (pntr->iflags) {
3954 fprintf(STDOUT, "offline ");
3957 fprintf(STDOUT, "busy ");
3960 fprintf(STDOUT, "readonly ");
3963 fprintf(STDOUT, "create ");
3966 fprintf(STDOUT, "create volid ");
3969 fprintf(STDOUT, "\n");
3972 fprintf(STDOUT, "volumeStatus: ");
3973 switch (pntr->vflags) {
3974 case VTDeleteOnSalvage:
3975 fprintf(STDOUT, "deleteOnSalvage ");
3976 case VTOutOfService:
3977 fprintf(STDOUT, "outOfService ");
3979 fprintf(STDOUT, "deleted ");
3981 fprintf(STDOUT, "\n");
3984 fprintf(STDOUT, "transactionFlags: ");
3985 fprintf(STDOUT, "delete\n");
3987 MapPartIdIntoName(pntr->partition, pname);
3988 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
3989 (unsigned long)pntr->volid, pname, pntr->lastProcName);
3990 if (pntr->callValid) {
3992 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3993 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
3994 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
3997 fprintf(STDOUT, "--------------------------------------\n");
3998 fprintf(STDOUT, "\n");
4007 register struct cmd_syndesc *as;
4009 afs_int32 code1, code2, code;
4010 struct nvldbentry entry;
4012 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4014 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4015 as->parms[0].items->data);
4018 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4019 if ((!code1) && (!code2)) { /*the newname already exists */
4020 fprintf(STDERR, "vos: volume %s already exists\n",
4021 as->parms[1].items->data);
4025 if (code1 && code2) {
4026 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4027 as->parms[0].items->data, as->parms[1].items->data);
4030 if (!VolNameOK(as->parms[0].items->data)) {
4032 "Illegal volume name %s, should not end in .readonly or .backup\n",
4033 as->parms[0].items->data);
4036 if (!ISNAMEVALID(as->parms[1].items->data)) {
4038 "vos: the new volume name %s exceeds the size limit of %d\n",
4039 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4042 if (!VolNameOK(as->parms[1].items->data)) {
4044 "Illegal volume name %s, should not end in .readonly or .backup\n",
4045 as->parms[1].items->data);
4048 if (IsNumeric(as->parms[1].items->data)) {
4049 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4050 as->parms[1].items->data);
4053 MapHostToNetwork(&entry);
4055 UV_RenameVolume(&entry, as->parms[0].items->data,
4056 as->parms[1].items->data);
4058 PrintDiagnostics("rename", code);
4061 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4062 as->parms[1].items->data);
4066 GetVolumeInfo(volid, server, part, voltype, rentry)
4067 afs_int32 *server, volid, *part, *voltype;
4068 register struct nvldbentry *rentry;
4073 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4076 "Could not fetch the entry for volume %lu from VLDB \n",
4077 (unsigned long)volid);
4078 PrintError("", vcode);
4081 MapHostToNetwork(rentry);
4082 if (volid == rentry->volumeId[ROVOL]) {
4084 for (i = 0; i < rentry->nServers; i++) {
4085 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4086 && !(rentry->serverFlags[i] & RO_DONTUSE))
4091 "RO volume is not found in VLDB entry for volume %lu\n",
4092 (unsigned long)volid);
4096 *server = rentry->serverNumber[index];
4097 *part = rentry->serverPartition[index];
4101 index = Lp_GetRwIndex(rentry);
4104 "RW Volume is not found in VLDB entry for volume %lu\n",
4105 (unsigned long)volid);
4108 if (volid == rentry->volumeId[RWVOL]) {
4110 *server = rentry->serverNumber[index];
4111 *part = rentry->serverPartition[index];
4114 if (volid == rentry->volumeId[BACKVOL]) {
4116 *server = rentry->serverNumber[index];
4117 *part = rentry->serverPartition[index];
4121 "unexpected volume type for volume %lu\n",
4122 (unsigned long)volid);
4128 register struct cmd_syndesc *as;
4134 struct VldbListByAttributes attributes;
4135 nbulkentries arrayEntries;
4136 register struct nvldbentry *vllist;
4137 struct cmd_item *itp;
4140 char prefix[VOLSER_MAXVOLNAME + 1];
4142 afs_int32 totalBack = 0, totalFail = 0, err;
4144 if (as->parms[0].items) { /* -id */
4145 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4147 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4150 for (itp = as->parms[0].items; itp; itp = itp->next) {
4151 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4154 PrintError("", err);
4156 fprintf(STDERR, "vos: can't find volume '%s'\n",
4160 if (as->parms[4].items) { /* -noexecute */
4161 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4166 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
4168 fprintf(STDERR, "Could not delete entry for volume %s\n",
4171 "You must specify a RW volume name or ID "
4172 "(the entire VLDB entry will be deleted)\n");
4173 PrintError("", vcode);
4179 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4183 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4184 fprintf(STDERR, "You must specify an option\n");
4188 /* Zero out search attributes */
4189 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4191 if (as->parms[1].items) { /* -prefix */
4192 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4194 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4196 "You must provide -server with the -prefix argument\n");
4201 if (as->parms[2].items) { /* -server */
4203 aserver = GetServer(as->parms[2].items->data);
4205 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4206 as->parms[2].items->data);
4209 attributes.server = ntohl(aserver);
4210 attributes.Mask |= VLLIST_SERVER;
4213 if (as->parms[3].items) { /* -partition */
4214 if (!as->parms[2].items) {
4216 "You must provide -server with the -partition argument\n");
4219 apart = volutil_GetPartitionID(as->parms[3].items->data);
4221 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4222 as->parms[3].items->data);
4225 attributes.partition = apart;
4226 attributes.Mask |= VLLIST_PARTITION;
4229 /* Print status line of what we are doing */
4230 fprintf(STDOUT, "Deleting VLDB entries for ");
4231 if (as->parms[2].items) {
4232 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4234 if (as->parms[3].items) {
4236 MapPartIdIntoName(apart, pname);
4237 fprintf(STDOUT, "partition %s ", pname);
4240 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4242 fprintf(STDOUT, "\n");
4245 /* Get all the VLDB entries on a server and/or partition */
4246 memset(&arrayEntries, 0, sizeof(arrayEntries));
4247 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4249 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4250 PrintError("", vcode);
4254 /* Process each entry */
4255 for (j = 0; j < nentries; j++) {
4256 vllist = &arrayEntries.nbulkentries_val[j];
4258 /* It only deletes the RW volumes */
4259 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4262 "Omitting to delete %s due to prefix %s mismatch\n",
4263 vllist->name, prefix);
4270 if (as->parms[4].items) { /* -noexecute */
4271 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4277 /* Only matches the RW volume name */
4278 avolid = vllist->volumeId[RWVOL];
4279 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
4281 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4284 PrintError("", vcode);
4289 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4294 fprintf(STDOUT, "----------------------\n");
4296 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4297 (unsigned long)totalBack, (unsigned long)totalFail);
4298 if (arrayEntries.nbulkentries_val)
4299 free(arrayEntries.nbulkentries_val);
4305 CompareVldbEntryByName(p1, p2)
4308 struct nvldbentry *arg1, *arg2;
4310 arg1 = (struct nvldbentry *)p1;
4311 arg2 = (struct nvldbentry *)p2;
4312 return (strcmp(arg1->name, arg2->name));
4316 static int CompareVldbEntry(p1,p2)
4319 struct nvldbentry *arg1,*arg2;
4322 char comp1[100],comp2[100];
4323 char temp1[20],temp2[20];
4325 arg1 = (struct nvldbentry *)p1;
4326 arg2 = (struct nvldbentry *)p2;
4330 for(i = 0; i < arg1->nServers; i++)
4331 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4332 for(i = 0; i < arg2->nServers; i++)
4333 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4334 if(pos1 == -1 || pos2 == -1){
4338 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4339 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4340 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4341 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4342 strcat(comp1,temp1);
4343 strcat(comp2,temp2);
4344 strcat(comp1,arg1->name);
4345 strcat(comp1,arg2->name);
4346 return(strcmp(comp1,comp2));
4353 struct cmd_syndesc *as;
4356 afs_int32 aserver, code;
4358 struct VldbListByAttributes attributes;
4359 nbulkentries arrayEntries;
4360 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4361 afs_int32 centries, nentries = 0, tarraysize, parraysize;
4364 int quiet, sort, lock;
4365 afs_int32 thisindex, nextindex;
4370 attributes.Mask = 0;
4371 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4372 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4373 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4375 /* If the volume name is given, Use VolumeInfoCmd to look it up
4376 * and not ListAttributes.
4378 if (as->parms[0].items) {
4381 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4384 code = VolumeInfoCmd(as->parms[0].items->data);
4386 PrintError("", code);
4392 /* Server specified */
4393 if (as->parms[1].items) {
4394 aserver = GetServer(as->parms[1].items->data);
4396 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4397 as->parms[1].items->data);
4400 attributes.server = ntohl(aserver);
4401 attributes.Mask |= VLLIST_SERVER;
4404 /* Partition specified */
4405 if (as->parms[2].items) {
4406 apart = volutil_GetPartitionID(as->parms[2].items->data);
4408 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4409 as->parms[2].items->data);
4412 attributes.partition = apart;
4413 attributes.Mask |= VLLIST_PARTITION;
4417 attributes.Mask |= VLLIST_FLAG;
4418 attributes.flag = VLOP_ALLOPERS;
4421 /* Print header information */
4423 MapPartIdIntoName(apart, pname);
4424 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4425 (as->parms[1].items ? "server" : "all"),
4426 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4427 (as->parms[2].items ? " partition " : ""),
4428 (as->parms[2].items ? pname : ""),
4429 (lock ? "which are locked:" : ""));
4432 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4433 memset(&arrayEntries, 0, sizeof(arrayEntries));
4438 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4439 &arrayEntries, &nextindex);
4440 if (vcode == RXGEN_OPCODE) {
4441 /* Vlserver not running with ListAttributesN2. Fall back */
4443 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4447 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4448 PrintError("", vcode);
4451 nentries += centries;
4453 /* We don't sort, so just print the entries now */
4455 for (j = 0; j < centries; j++) { /* process each entry */
4456 vllist = &arrayEntries.nbulkentries_val[j];
4457 MapHostToNetwork(vllist);
4458 EnumerateEntry(vllist);
4460 if (vllist->flags & VLOP_ALLOPERS)
4461 fprintf(STDOUT, " Volume is currently LOCKED \n");
4465 /* So we sort. First we must collect all the entries and keep
4468 else if (centries > 0) {
4470 /* steal away the first bulk entries array */
4471 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4472 tarraysize = centries * sizeof(struct nvldbentry);
4473 arrayEntries.nbulkentries_val = 0;
4475 /* Grow the tarray to keep the extra entries */
4476 parraysize = (centries * sizeof(struct nvldbentry));
4478 (struct nvldbentry *)realloc(tarray,
4479 tarraysize + parraysize);
4482 "Could not allocate enough space for the VLDB entries\n");
4488 memcpy(((char *)tarray) + tarraysize,
4489 (char *)arrayEntries.nbulkentries_val, parraysize);
4490 tarraysize += parraysize;
4494 /* Free the bulk array */
4495 if (arrayEntries.nbulkentries_val) {
4496 free(arrayEntries.nbulkentries_val);
4497 arrayEntries.nbulkentries_val = 0;
4501 /* Here is where we now sort all the entries and print them */
4502 if (sort && (nentries > 0)) {
4503 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4504 CompareVldbEntryByName);
4505 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4506 MapHostToNetwork(vllist);
4507 EnumerateEntry(vllist);
4509 if (vllist->flags & VLOP_ALLOPERS)
4510 fprintf(STDOUT, " Volume is currently LOCKED \n");
4516 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4524 register struct cmd_syndesc *as;
4526 afs_int32 apart = 0, avolid;
4527 afs_int32 aserver = 0, code, aserver1, apart1;
4529 struct VldbListByAttributes attributes;
4530 nbulkentries arrayEntries;
4531 register struct nvldbentry *vllist;
4535 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4536 afs_int32 totalBack = 0;
4537 afs_int32 totalFail = 0;
4538 int previdx = -1, error, same;
4540 struct cmd_item *ti;
4544 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4545 attributes.Mask = 0;
4547 seenprefix = (as->parms[0].items ? 1 : 0);
4548 exclude = (as->parms[3].items ? 1 : 0);
4549 seenxprefix = (as->parms[4].items ? 1 : 0);
4550 noaction = (as->parms[5].items ? 1 : 0);
4552 if (as->parms[1].items) { /* -server */
4553 aserver = GetServer(as->parms[1].items->data);
4555 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4556 as->parms[1].items->data);
4559 attributes.server = ntohl(aserver);
4560 attributes.Mask |= VLLIST_SERVER;
4563 if (as->parms[2].items) { /* -partition */
4564 apart = volutil_GetPartitionID(as->parms[2].items->data);
4566 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4567 as->parms[2].items->data);
4570 attributes.partition = apart;
4571 attributes.Mask |= VLLIST_PARTITION;
4574 /* Check to make sure the prefix and xprefix expressions compile ok */
4576 for (ti = as->parms[0].items; ti; ti = ti->next) {
4577 if (strncmp(ti->data, "^", 1) == 0) {
4578 #ifdef HAVE_POSIX_REGEX
4582 code = regcomp(&re, ti->data, REG_NOSUB);
4584 regerror(code, &re, errbuf, sizeof errbuf);
4586 "Unrecognizable -prefix regular expression: '%s': %s\n",
4592 ccode = (char *)re_comp(ti->data);
4595 "Unrecognizable -prefix regular expression: '%s': %s\n",
4604 for (ti = as->parms[4].items; ti; ti = ti->next) {
4605 if (strncmp(ti->data, "^", 1) == 0) {
4606 #ifdef HAVE_POSIX_REGEX
4610 code = regcomp(&re, ti->data, REG_NOSUB);
4612 regerror(code, &re, errbuf, sizeof errbuf);
4614 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4620 ccode = (char *)re_comp(ti->data);
4623 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4632 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4633 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4635 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4636 PrintError("", vcode);
4640 if (as->parms[1].items || as->parms[2].items || verbose) {
4641 fprintf(STDOUT, "%s up volumes",
4642 (noaction ? "Would have backed" : "Backing"));
4644 if (as->parms[1].items) {
4645 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4646 } else if (as->parms[2].items) {
4647 fprintf(STDOUT, " for all servers");
4650 if (as->parms[2].items) {
4651 MapPartIdIntoName(apart, pname);
4652 fprintf(STDOUT, " partition %s", pname);
4655 if (seenprefix || (!seenprefix && seenxprefix)) {
4656 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4657 ex = (seenprefix ? exclude : !exclude);
4658 exp = (strncmp(ti->data, "^", 1) == 0);
4659 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4660 (exp ? "expression" : "prefix"), ti->data);
4661 for (ti = ti->next; ti; ti = ti->next) {
4662 exp = (strncmp(ti->data, "^", 1) == 0);
4663 printf(" %sor %s '%s'", (ex ? "n" : ""),
4664 (exp ? "expression" : "prefix"), ti->data);
4668 if (seenprefix && seenxprefix) {
4669 ti = as->parms[4].items;
4670 exp = (strncmp(ti->data, "^", 1) == 0);
4671 fprintf(STDOUT, " %swhich match %s '%s'",
4672 (exclude ? "adding those " : "removing those "),
4673 (exp ? "expression" : "prefix"), ti->data);
4674 for (ti = ti->next; ti; ti = ti->next) {
4675 exp = (strncmp(ti->data, "^", 1) == 0);
4676 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4680 fprintf(STDOUT, " .. ");
4682 fprintf(STDOUT, "\n");
4686 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4687 vllist = &arrayEntries.nbulkentries_val[j];
4690 for (ti = as->parms[0].items; ti; ti = ti->next) {
4691 if (strncmp(ti->data, "^", 1) == 0) {
4692 #ifdef HAVE_POSIX_REGEX
4696 /* XXX -- should just do the compile once! */
4697 code = regcomp(&re, ti->data, REG_NOSUB);
4699 regerror(code, &re, errbuf, sizeof errbuf);
4701 "Error in -prefix regular expression: '%s': %s\n",
4705 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4708 ccode = (char *)re_comp(ti->data);
4711 "Error in -prefix regular expression: '%s': %s\n",
4715 match = (re_exec(vllist->name) == 1);
4719 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4729 /* Without the -exclude flag: If it matches the prefix, then
4730 * check if we want to exclude any from xprefix.
4731 * With the -exclude flag: If it matches the prefix, then
4732 * check if we want to add any from xprefix.
4734 if (match && seenxprefix) {
4735 for (ti = as->parms[4].items; ti; ti = ti->next) {
4736 if (strncmp(ti->data, "^", 1) == 0) {
4737 #ifdef HAVE_POSIX_REGEX
4741 /* XXX -- should just do the compile once! */
4742 code = regcomp(&re, ti->data, REG_NOSUB);
4744 regerror(code, &re, errbuf, sizeof errbuf);
4746 "Error in -xprefix regular expression: '%s': %s\n",
4750 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4754 ccode = (char *)re_comp(ti->data);
4757 "Error in -xprefix regular expression: '%s': %s\n",
4761 if (re_exec(vllist->name) == 1) {
4767 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4777 match = !match; /* -exclude will reverse the match */
4779 continue; /* Skip if no match */
4781 /* Print list of volumes to backup */
4783 fprintf(STDOUT, " %s\n", vllist->name);
4787 if (!(vllist->flags & RW_EXISTS)) {
4790 "Omitting to backup %s since RW volume does not exist \n",
4792 fprintf(STDOUT, "\n");
4798 avolid = vllist->volumeId[RWVOL];
4799 MapHostToNetwork(vllist);
4800 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4801 if (aserver1 == -1 || apart1 == -1) {
4802 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4808 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4811 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4817 if ((aserver && !same) || (apart && (apart != apart1))) {
4820 "Omitting to backup %s since the RW is in a different location\n",
4826 time_t now = time(0);
4827 fprintf(STDOUT, "Creating backup volume for %s on %s",
4828 vllist->name, ctime(&now));
4832 code = UV_BackupVolume(aserver1, apart1, avolid);
4834 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4840 fprintf(STDOUT, "\n");
4842 } /* process each vldb entry */
4843 fprintf(STDOUT, "done\n");
4844 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4845 (unsigned long)totalBack, (unsigned long)totalFail);
4847 if (arrayEntries.nbulkentries_val)
4848 free(arrayEntries.nbulkentries_val);
4854 register struct cmd_syndesc *as;
4857 afs_int32 aserver, code;
4859 struct VldbListByAttributes attributes;
4860 nbulkentries arrayEntries;
4861 register struct nvldbentry *vllist;
4870 attributes.Mask = 0;
4872 if (as->parms[0].items) { /* server specified */
4873 aserver = GetServer(as->parms[0].items->data);
4875 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4876 as->parms[0].items->data);
4879 attributes.server = ntohl(aserver);
4880 attributes.Mask |= VLLIST_SERVER;
4882 if (as->parms[1].items) { /* partition specified */
4883 apart = volutil_GetPartitionID(as->parms[1].items->data);
4885 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4886 as->parms[1].items->data);
4889 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4891 PrintError("", code);
4894 "vos : partition %s does not exist on the server\n",
4895 as->parms[1].items->data);
4898 attributes.partition = apart;
4899 attributes.Mask |= VLLIST_PARTITION;
4901 attributes.flag = VLOP_ALLOPERS;
4902 attributes.Mask |= VLLIST_FLAG;
4903 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4904 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4906 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4907 PrintError("", vcode);
4910 for (j = 0; j < nentries; j++) { /* process each entry */
4911 vllist = &arrayEntries.nbulkentries_val[j];
4912 volid = vllist->volumeId[RWVOL];
4914 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4915 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4917 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4919 PrintError("", vcode);
4924 MapPartIdIntoName(apart, pname);
4927 "Could not lock %lu VLDB entries of %lu locked entries\n",
4928 (unsigned long)totalE, (unsigned long)nentries);
4930 if (as->parms[0].items) {
4932 "Unlocked all the VLDB entries for volumes on server %s ",
4933 as->parms[0].items->data);
4934 if (as->parms[1].items) {
4935 MapPartIdIntoName(apart, pname);
4936 fprintf(STDOUT, "partition %s\n", pname);
4938 fprintf(STDOUT, "\n");
4940 } else if (as->parms[1].items) {
4941 MapPartIdIntoName(apart, pname);
4943 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4948 if (arrayEntries.nbulkentries_val)
4949 free(arrayEntries.nbulkentries_val);
4954 PrintInt64Size(afs_uint64 in)
4956 register afs_uint32 hi, lo;
4957 register char * units;
4958 static char output[16];
4960 SplitInt64(in,hi,lo);
4964 } else if (!(hi & 0xFFFFFC00)) {
4966 lo = (hi << 22) | (lo >> 10);
4967 } else if (!(hi & 0xFFF00000)) {
4969 lo = (hi << 12) | (lo >> 20);
4970 } else if (!(hi & 0xC0000000)) {
4972 lo = (hi << 2) | (lo >> 30);
4977 sprintf(output,"%u %s", lo, units);
4983 register struct cmd_syndesc *as;
4986 afs_int32 aserver, code;
4988 struct diskPartition partition;
4989 struct partList dummyPartList;
4991 int printSummary=0, sumPartitions=0;
4992 afs_uint64 sumFree, sumStorage, tmp;
4995 ZeroInt64(sumStorage);
4997 aserver = GetServer(as->parms[0].items->data);
4999 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5000 as->parms[0].items->data);
5003 if (as->parms[1].items) {
5004 apart = volutil_GetPartitionID(as->parms[1].items->data);
5006 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5007 as->parms[1].items->data);
5010 dummyPartList.partId[0] = apart;
5011 dummyPartList.partFlags[0] = PARTVALID;
5014 if (as->parms[2].items) {
5018 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5020 PrintError("", code);
5023 "vos : partition %s does not exist on the server\n",
5024 as->parms[1].items->data);
5028 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5030 PrintDiagnostics("listpart", code);
5034 for (i = 0; i < cnt; i++) {
5035 if (dummyPartList.partFlags[i] & PARTVALID) {
5036 MapPartIdIntoName(dummyPartList.partId[i], pname);
5037 code = UV_PartitionInfo(aserver, pname, &partition);
5039 fprintf(STDERR, "Could not get information on partition %s\n",
5041 PrintError("", code);
5045 "Free space on partition %s: %d K blocks out of total %d\n",
5046 pname, partition.free, partition.minFree);
5048 FillInt64(tmp,0,partition.free);
5049 AddUInt64(sumFree,tmp,&sumFree);
5050 FillInt64(tmp,0,partition.minFree);
5051 AddUInt64(sumStorage,tmp,&sumStorage);
5056 "Summary: %s free out of ",
5057 PrintInt64Size(sumFree));
5059 "%s on %d partitions\n",
5060 PrintInt64Size(sumStorage),
5068 register struct cmd_syndesc *as;
5071 afs_int32 ip1, ip2, vcode;
5074 ip1 = GetServer(as->parms[0].items->data);
5076 fprintf(STDERR, "vos: invalid host address\n");
5080 if ((as->parms[1].items && as->parms[2].items)
5081 || (!as->parms[1].items && !as->parms[2].items)) {
5083 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5087 if (as->parms[1].items) {
5088 ip2 = GetServer(as->parms[1].items->data);
5090 fprintf(STDERR, "vos: invalid host address\n");
5094 /* Play a trick here. If we are removing an address, ip1 will be -1
5095 * and ip2 will be the original address. This switch prevents an
5096 * older revision vlserver from removing the IP address.
5103 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
5106 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5107 as->parms[0].items->data);
5108 if (vcode == VL_NOENT) {
5110 "vlserver does not support the remove flag or ");
5113 fprintf(STDERR, "Could not change server %s to server %s\n",
5114 as->parms[0].items->data, as->parms[1].items->data);
5116 PrintError("", vcode);
5121 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5122 as->parms[0].items->data);
5124 fprintf(STDOUT, "Changed server %s to server %s\n",
5125 as->parms[0].items->data, as->parms[1].items->data);
5131 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
5132 int print, int noresolve)
5136 struct VLCallBack vlcb;
5139 ListAddrByAttributes m_attrs;
5140 afs_int32 m_nentries, *m_addrp;
5141 afs_int32 base, index;
5145 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5146 printf("UUID: %s\n", buf);
5149 /* print out the list of all the server */
5150 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5151 for (i = 0; i < nentries; i++, addrp++) {
5152 /* If it is a multihomed address, then we will need to
5153 * get the addresses for this multihomed server from
5154 * the vlserver and print them.
5156 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5157 /* Get the list of multihomed fileservers */
5158 base = (*addrp >> 16) & 0xff;
5159 index = (*addrp) & 0xffff;
5161 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5162 && (index <= VL_MHSRV_PERBLK)) {
5163 m_attrs.Mask = VLADDR_INDEX;
5164 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5166 m_addrs.bulkaddrs_val = 0;
5167 m_addrs.bulkaddrs_len = 0;
5169 ubik_Call(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5170 &vlcb, &m_nentries, &m_addrs);
5173 "vos: could not list the multi-homed server addresses\n");
5174 PrintError("", vcode);
5177 /* Print the list */
5178 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5179 for (j = 0; j < m_nentries; j++, m_addrp++) {
5180 *m_addrp = htonl(*m_addrp);
5183 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5185 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5189 printf("<unknown>\n");
5198 /* Otherwise, it is a non-multihomed entry and contains
5199 * the IP address of the server - print it.
5201 *addrp = htonl(*addrp);
5204 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5206 printf("%s\n", hostutil_GetNameByINet(*addrp));
5218 register struct cmd_syndesc *as;
5221 afs_int32 i, noresolve = 0, printuuid = 0;
5222 struct VLCallBack vlcb;
5225 ListAddrByAttributes m_attrs;
5226 afsUUID m_uuid, askuuid;
5227 afs_int32 m_nentries;
5229 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5230 m_attrs.Mask = VLADDR_INDEX;
5232 memset(&m_addrs, 0, sizeof(bulkaddrs));
5233 memset(&askuuid, 0, sizeof(afsUUID));
5234 if (as->parms[0].items) {
5236 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5237 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5238 as->parms[0].items->data);
5241 m_attrs.Mask = VLADDR_UUID;
5242 m_attrs.uuid = askuuid;
5244 if (as->parms[1].items) {
5248 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5250 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5251 as->parms[1].items->data);
5254 memcpy(&saddr, he->h_addr, 4);
5255 m_attrs.Mask = VLADDR_IPADDR;
5256 m_attrs.ipaddr = ntohl(saddr);
5258 if (as->parms[2].items) {
5261 if (as->parms[3].items) {
5265 m_addrs.bulkaddrs_val = 0;
5266 m_addrs.bulkaddrs_len = 0;
5269 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries,
5272 fprintf(STDERR, "vos: could not list the server addresses\n");
5273 PrintError("", vcode);
5278 m_addrs.bulkaddrs_val = 0;
5279 m_addrs.bulkaddrs_len = 0;
5285 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5286 &vlcb, &m_nentries, &m_addrs);
5288 if (vcode == VL_NOENT) {
5289 if (m_attrs.Mask == VLADDR_UUID) {
5290 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5291 as->parms[0].items->data);
5293 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5294 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5295 as->parms[1].items->data, m_attrs.ipaddr);
5304 if (vcode == VL_INDEXERANGE) {
5309 fprintf(STDERR, "vos: could not list the server addresses\n");
5310 PrintError("", vcode);
5314 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
5317 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5326 register struct cmd_syndesc *as;
5329 afs_int32 avolid, vcode, err;
5331 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5334 PrintError("", err);
5336 fprintf(STDERR, "vos: can't find volume '%s'\n",
5337 as->parms[0].items->data);
5340 vcode = ubik_Call(VL_SetLock, cstruct, 0, avolid, -1, VLOP_DELETE);
5342 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5343 as->parms[0].items->data);
5344 PrintError("", vcode);
5347 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5348 as->parms[0].items->data);
5354 register struct cmd_syndesc *as;
5357 afs_int32 partition = -1;
5358 afs_int32 server, volid, code, i, same;
5359 struct nvldbentry entry, storeEntry;
5362 afs_int32 rwserver = 0;
5363 afs_int32 rwpartition;
5365 afs_int32 roserver = 0;
5366 afs_int32 ropartition;
5368 struct rx_connection *aconn;
5371 server = GetServer(as->parms[0].items->data);
5373 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5374 as->parms[0].items->data);
5377 partition = volutil_GetPartitionID(as->parms[1].items->data);
5378 if (partition < 0) {
5379 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5380 as->parms[1].items->data);
5383 if (!IsPartValid(partition, server, &code)) {
5385 PrintError("", code);
5388 "vos : partition %s does not exist on the server\n",
5389 as->parms[1].items->data);
5392 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5395 PrintError("", code);
5397 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5398 as->parms[0].items->data);
5401 if (as->parms[3].items)
5404 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5407 "Could not fetch the entry for volume %lu from VLDB\n",
5408 (unsigned long)volid);
5409 PrintError("convertROtoRW", code);
5413 /* use RO volid even if user specified RW or BK volid */
5415 if (volid != entry.volumeId[ROVOL])
5416 volid = entry.volumeId[ROVOL];
5418 MapHostToNetwork(&entry);
5419 for (i = 0; i < entry.nServers; i++) {
5420 if (entry.serverFlags[i] & ITSRWVOL) {
5422 rwserver = entry.serverNumber[i];
5423 rwpartition = entry.serverPartition[i];
5425 if (entry.serverFlags[i] & ITSROVOL) {
5426 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5429 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5435 roserver = entry.serverNumber[i];
5436 ropartition = entry.serverPartition[i];
5442 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5444 if (ropartition != partition) {
5446 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5447 ropartition, partition);
5452 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5453 hostutil_GetNameByINet(rwserver),
5454 volutil_PartitionName(rwpartition));
5456 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5458 while (!(dc == EOF || dc == '\n'))
5459 dc = getchar(); /* goto end of line */
5460 if ((c != 'y') && (c != 'Y')) {
5461 fprintf(STDERR, "aborted.\n");
5468 ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5470 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5471 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5474 "Converting RO volume %lu to RW volume failed with code %d\n",
5475 (unsigned long)volid, code);
5476 PrintError("convertROtoRW ", code);
5479 entry.serverFlags[roindex] = ITSRWVOL;
5480 entry.flags |= RW_EXISTS;
5481 entry.flags &= ~BACK_EXISTS;
5484 if (rwindex != entry.nServers) {
5485 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5486 entry.serverPartition[rwindex] =
5487 entry.serverPartition[entry.nServers];
5488 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5489 entry.serverNumber[entry.nServers] = 0;
5490 entry.serverPartition[entry.nServers] = 0;
5491 entry.serverFlags[entry.nServers] = 0;
5494 entry.flags &= ~RO_EXISTS;
5495 for (i = 0; i < entry.nServers; i++) {
5496 if (entry.serverFlags[i] & ITSROVOL) {
5497 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5498 entry.flags |= RO_EXISTS;
5501 MapNetworkToHost(&entry, &storeEntry);
5503 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5504 (LOCKREL_OPCODE | LOCKREL_AFSID |
5505 LOCKREL_TIMESTAMP));
5508 "Warning: volume converted, but vldb update failed with code %d!\n",
5511 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5513 PrintDiagnostics("unlock", vcode);
5520 register struct cmd_syndesc *as;
5522 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
5523 struct nvldbentry entry;
5524 volintSize vol_size;
5526 rx_SetRxDeadTime(60 * 10);
5527 for (i = 0; i < MAXSERVERS; i++) {
5528 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5531 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5532 if (rxConn->service)
5533 rxConn->service->connDeadTime = rx_connDeadTime;
5536 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5539 PrintError("", err);
5541 fprintf(STDERR, "vos: can't find volume '%s'\n",
5542 as->parms[0].items->data);
5546 if (as->parms[1].items || as->parms[2].items) {
5547 if (!as->parms[1].items || !as->parms[2].items) {
5549 "Must specify both -server and -partition options\n");
5552 aserver = GetServer(as->parms[2].items->data);
5554 fprintf(STDERR, "Invalid server name\n");
5557 apart = volutil_GetPartitionID(as->parms[1].items->data);
5559 fprintf(STDERR, "Invalid partition name\n");
5563 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5570 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5571 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5573 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5574 as->parms[1].items->data, code);
5579 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5581 if (as->parms[3].items) { /* do the dump estimate */
5582 #ifdef AFS_64BIT_ENV
5583 vol_size.dump_size = 0;
5585 FillInt64(vol_size.dump_size,0, 1);
5587 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5589 PrintDiagnostics("size", code);
5592 /* presumably the size info is now gathered in pntr */
5593 /* now we display it */
5595 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5603 PrintDiagnostics(astring, acode)
5607 if (acode == EACCES) {
5609 "You are not authorized to perform the 'vos %s' command (%d)\n",
5612 fprintf(STDERR, "Error in vos %s command.\n", astring);
5613 PrintError("", acode);
5620 MyBeforeProc(as, arock)
5621 struct cmd_syndesc *as;
5624 register char *tcell;
5625 register afs_int32 code;
5626 register afs_int32 sauth;
5628 /* Initialize the ubik_client connection */
5629 rx_SetRxDeadTime(90);
5630 cstruct = (struct ubik_client *)0;
5634 if (as->parms[12].items) /* if -cell specified */
5635 tcell = as->parms[12].items->data;
5636 if (as->parms[14].items) /* -serverauth specified */
5638 if (as->parms[16].items) /* -crypt specified */
5641 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5642 &cstruct, UV_SetSecurity))) {
5643 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5644 (unsigned long)code);
5648 if (as->parms[15].items) /* -verbose flag set */
5658 /* this sucks but it works for now.
5663 #include "AFS_component_version_number.c"
5669 register afs_int32 code;
5671 register struct cmd_syndesc *ts;
5673 #ifdef AFS_AIX32_ENV
5675 * The following signal action for AIX is necessary so that in case of a
5676 * crash (i.e. core is generated) we can include the user's data section
5677 * in the core dump. Unfortunately, by default, only a partial core is
5678 * generated which, in many cases, isn't too useful.
5680 struct sigaction nsa;
5682 sigemptyset(&nsa.sa_mask);
5683 nsa.sa_handler = SIG_DFL;
5684 nsa.sa_flags = SA_FULLDUMP;
5685 sigaction(SIGSEGV, &nsa, NULL);
5688 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5690 cmd_SetBeforeProc(MyBeforeProc, NULL);
5692 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
5693 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5694 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5695 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5696 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5697 "initial quota (KB)");
5699 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5703 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
5704 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5705 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5706 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5710 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
5711 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5712 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5713 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5714 "partition name on source");
5715 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5716 "machine name on destination");
5717 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5718 "partition name on destination");
5719 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5720 "copy live volume without cloning");
5723 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
5724 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5725 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5726 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5727 "partition name on source");
5728 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5729 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5730 "machine name on destination");
5731 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5732 "partition name on destination");
5733 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5734 "leave new volume offline");
5735 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5736 "make new volume read-only");
5737 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5738 "copy live volume without cloning");
5741 ts = cmd_CreateSyntax("shadow", ShadowVolume, 0,
5742 "make or update a shadow volume");
5743 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5744 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5745 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5746 "partition name on source");
5747 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5748 "machine name on destination");
5749 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5750 "partition name on destination");
5751 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5752 "volume name on destination");
5753 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5754 "volume ID on destination");
5755 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5756 "leave shadow volume offline");
5757 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5758 "make shadow volume read-only");
5759 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5760 "copy live volume without cloning");
5761 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5762 "do incremental update if target exists");
5765 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
5766 "make backup of a volume");
5767 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5770 ts = cmd_CreateSyntax("clone", CloneVolume, 0,
5771 "make clone of a volume");
5772 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5773 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5774 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5775 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5776 "volume name on destination");
5777 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5778 "volume ID on destination");
5779 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5780 "leave clone volume offline");
5781 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5782 "make clone volume read-only, not readwrite");
5785 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
5786 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5787 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5788 "force a complete release");
5791 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
5792 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5793 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5794 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5795 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5796 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5797 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5798 "dump a clone of the volume");
5801 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
5802 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5803 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5804 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5805 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5806 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5807 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5808 "abort | full | incremental");
5809 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5810 "leave restored volume offline");
5811 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5812 "make restored volume read-only");
5813 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
5814 "dump | keep | new");
5815 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
5816 "dump | keep | new");
5819 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
5820 "release lock on VLDB entry for a volume");
5821 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5824 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
5825 "change an RW volume's location in the VLDB");
5826 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5827 "machine name for new location");
5828 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5829 "partition name for new location");
5830 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5833 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5834 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5835 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5836 "partition name for new site");
5837 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5840 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5841 "remove a replication site");
5842 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5843 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5844 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5847 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5848 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5851 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5852 "list volumes on server (bypass VLDB)");
5853 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5854 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5855 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5856 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5857 "list all normal volume fields");
5858 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5859 "generate minimal information");
5860 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5861 "list extended volume fields");
5862 #ifdef FULL_LISTVOL_SWITCH
5863 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5864 "machine readable format");
5865 #endif /* FULL_LISTVOL_SWITCH */
5868 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5869 "synchronize VLDB with server");
5870 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5871 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5872 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5875 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5876 "synchronize server with VLDB");
5877 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5878 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5881 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5882 "everything about the volume");
5883 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5884 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5885 "list extended volume fields");
5886 #ifdef FULL_LISTVOL_SWITCH
5887 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5888 "machine readable format");
5889 #endif /* FULL_LISTVOL_SWITCH */
5891 cmd_CreateAlias(ts, "volinfo");
5893 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5894 "change volume info fields");
5895 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5896 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5897 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5900 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5901 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5902 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5903 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5904 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5905 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5908 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5909 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5910 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5911 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5914 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5915 "delete the volume, don't bother with VLDB");
5916 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5917 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5918 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5919 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5920 "force deletion of bad volumes");
5921 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5922 "also delete backup volume if one is found");
5925 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5926 "report on volser status");
5927 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5930 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5931 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5932 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5935 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5936 "list volumes in the VLDB");
5937 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5938 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5939 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5940 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5941 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5942 "generate minimal information");
5943 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5944 "do not alphabetically sort the volume names");
5947 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5948 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5949 "common prefix on volume(s)");
5950 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5951 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5952 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5953 "exclude common prefix volumes");
5954 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5955 "negative prefix on volume(s)");
5956 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5959 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5960 "delete VLDB entry for a volume");
5961 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5962 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5963 "prefix of the volume whose VLDB entry is to be deleted");
5964 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5965 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5966 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
5970 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
5971 "list partition information");
5972 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5973 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5974 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
5975 "print storage summary");
5978 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
5979 "unlock all the locked entries in the VLDB");
5980 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5981 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5984 ts = cmd_CreateSyntax("lock", LockEntry, 0,
5985 "lock VLDB entry for a volume");
5986 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5989 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
5990 "change the IP address of a file server");
5991 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
5992 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
5993 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
5994 "remove the IP address from the VLDB");
5997 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
5998 "list the IP address of all file servers registered in the VLDB");
5999 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6000 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6001 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
6002 "don't resolve addresses");
6003 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6004 "print uuid of hosts");
6007 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
6008 "convert a RO volume into a RW volume (after loss of old RW volume)");
6009 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6010 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6011 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6012 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6015 ts = cmd_CreateSyntax("size", Sizes, 0,
6016 "obtain various sizes of the volume.");
6017 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6018 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6019 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6020 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6021 "Obtain the size of the dump");
6022 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6025 code = cmd_Dispatch(argc, argv);
6027 /* Shut down the ubik_client and rx connections */
6029 (void)ubik_ClientDestroy(cstruct);
6035 exit((code ? -1 : 0));