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 */
857 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
858 } else if (a_int32) {
860 * Fully-detailed listing.
862 if (a_xInfoP->status == VOK) {
864 * Volume's status is OK - all the fields are valid.
867 static long server_cache = -1, partition_cache = -1;
868 static char hostname[256], address[32], pname[16];
869 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
870 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
872 if (a_servID != server_cache) {
876 strcpy(hostname, hostutil_GetNameByINet(a_servID));
877 strcpy(address, inet_ntoa(s));
878 server_cache = a_servID;
880 if (a_partID != partition_cache) {
881 MapPartIdIntoName(a_partID, pname);
882 partition_cache = a_partID;
886 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
887 fprintf(STDOUT, "id\t\t%lu\n", a_xInfoP->volid);
888 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
889 fprintf(STDOUT, "part\t\t%s\n", pname);
890 switch (a_xInfoP->status) {
892 fprintf(STDOUT, "status\t\tOK\n");
895 fprintf(STDOUT, "status\t\tBUSY\n");
898 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
901 fprintf(STDOUT, "backupID\t%lu\n", a_xInfoP->backupID);
902 fprintf(STDOUT, "parentID\t%lu\n", a_xInfoP->parentID);
903 fprintf(STDOUT, "cloneID\t\t%lu\n", a_xInfoP->cloneID);
904 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
905 switch (a_xInfoP->type) {
907 fprintf(STDOUT, "type\t\tRW\n");
910 fprintf(STDOUT, "type\t\tRO\n");
913 fprintf(STDOUT, "type\t\tBK\n");
916 fprintf(STDOUT, "type\t\t?\n");
919 fprintf(STDOUT, "creationDate\t%-9lu\t%s", a_xInfoP->creationDate,
920 vos_ctime(&a_xInfoP->creationDate));
921 fprintf(STDOUT, "accessDate\t%-9lu\t%s", a_xInfoP->accessDate,
922 vos_ctime(&a_xInfoP->accessDate));
923 fprintf(STDOUT, "updateDate\t%-9lu\t%s", a_xInfoP->updateDate,
924 vos_ctime(&a_xInfoP->updateDate));
925 fprintf(STDOUT, "backupDate\t%-9lu\t%s", a_xInfoP->backupDate,
926 vos_ctime(&a_xInfoP->backupDate));
927 fprintf(STDOUT, "copyDate\t%-9lu\t%s", a_xInfoP->copyDate,
928 vos_ctime(&a_xInfoP->copyDate));
930 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
931 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
933 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
934 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
938 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
939 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
940 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
941 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
943 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
944 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
945 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
946 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
950 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
951 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
952 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
953 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
956 } /*Volume status OK */
957 else if (a_xInfoP->status == VBUSY) {
959 qPut(&busyHead, a_xInfoP->volid);
961 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
962 (unsigned long)a_xInfoP->volid);
966 qPut(¬okHead, a_xInfoP->volid);
968 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
969 (unsigned long)a_xInfoP->volid);
970 } /*Screwed volume */
976 if (a_xInfoP->status == VOK) {
977 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
978 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
979 if (a_xInfoP->type == 0)
980 fprintf(STDOUT, "type\tRW\n");
981 if (a_xInfoP->type == 1)
982 fprintf(STDOUT, "type\tRO\n");
983 if (a_xInfoP->type == 2)
984 fprintf(STDOUT, "type\tBK\n");
985 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
987 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
988 if (a_xInfoP->inUse == 1)
994 else if (a_xInfoP->status == VBUSY) {
996 qPut(&busyHead, a_xInfoP->volid);
998 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
999 (unsigned long)a_xInfoP->volid);
1003 qPut(¬okHead, a_xInfoP->volid);
1005 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1006 (unsigned long)a_xInfoP->volid);
1007 } /*Screwed volume */
1008 } /*Default listing */
1009 } /*XDisplayFormat */
1010 #endif /*FULL_LISTVOL_SWITCH*/
1012 #ifdef FULL_LISTVOL_SWITCH
1014 DisplayFormat2(server, partition, pntr)
1015 long server, partition;
1018 static long server_cache = -1, partition_cache = -1;
1019 static char hostname[256], address[32], pname[16];
1021 if (server != server_cache) {
1025 strcpy(hostname, hostutil_GetNameByINet(server));
1026 strcpy(address, inet_ntoa(s));
1027 server_cache = server;
1029 if (partition != partition_cache) {
1030 MapPartIdIntoName(partition, pname);
1031 partition_cache = partition;
1035 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1036 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
1037 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1038 fprintf(STDOUT, "part\t\t%s\n", pname);
1039 switch (pntr->status) {
1041 fprintf(STDOUT, "status\t\tOK\n");
1044 fprintf(STDOUT, "status\t\tBUSY\n");
1047 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1050 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
1051 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
1052 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
1053 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1054 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1055 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1056 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1057 switch (pntr->type) {
1059 fprintf(STDOUT, "type\t\tRW\n");
1062 fprintf(STDOUT, "type\t\tRO\n");
1065 fprintf(STDOUT, "type\t\tBK\n");
1068 fprintf(STDOUT, "type\t\t?\n");
1071 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
1072 vos_ctime(&pntr->creationDate));
1073 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
1074 vos_ctime(&pntr->accessDate));
1075 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
1076 vos_ctime(&pntr->updateDate));
1077 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
1078 vos_ctime(&pntr->backupDate));
1079 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
1080 vos_ctime(&pntr->copyDate));
1081 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
1082 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1083 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1084 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
1085 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1086 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1087 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
1088 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
1089 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
1094 DisplayVolumes2(server, partition, pntr, count)
1096 long server, partition, count;
1100 for (i = 0; i < count; i++) {
1101 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1102 DisplayFormat2(server, partition, pntr);
1103 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1108 #endif /* FULL_LISTVOL_SWITCH */
1111 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
1112 afs_int32 server, part;
1114 afs_int32 count, longlist, fast;
1117 int totalOK, totalNotOK, totalBusy, i;
1125 for (i = 0; i < count; i++) {
1126 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1131 while (busyHead.count) {
1132 qGet(&busyHead, &volid);
1133 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1134 (unsigned long)volid);
1138 while (notokHead.count) {
1139 qGet(¬okHead, &volid);
1140 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1141 (unsigned long)volid);
1145 fprintf(STDOUT, "\n");
1148 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1149 totalOK, totalNotOK, totalBusy);
1153 /*------------------------------------------------------------------------
1154 * PRIVATE XDisplayVolumes
1157 * Display extended volume information.
1160 * a_servID : Pointer to the Rx call we're performing.
1161 * a_partID : Partition for which we want the extended list.
1162 * a_xInfoP : Ptr to extended volume info.
1163 * a_count : Number of volume records contained above.
1164 * a_int32 : Int32 listing generated?
1165 * a_fast : Fast listing generated?
1166 * a_quiet : Quiet listing generated?
1172 * Nothing interesting.
1176 *------------------------------------------------------------------------*/
1179 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1183 volintXInfo *a_xInfoP;
1189 { /*XDisplayVolumes */
1191 int totalOK; /*Total OK volumes */
1192 int totalNotOK; /*Total screwed volumes */
1193 int totalBusy; /*Total busy volumes */
1194 int i; /*Loop variable */
1195 afs_int32 volid; /*Current volume ID */
1198 * Initialize counters and (global!!) queues.
1207 * Display each volume in the list.
1209 for (i = 0; i < a_count; i++) {
1210 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1211 &totalBusy, a_fast, a_int32, 0);
1216 * If any volumes were found to be busy or screwed, display them.
1219 while (busyHead.count) {
1220 qGet(&busyHead, &volid);
1221 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1222 (unsigned long)volid);
1226 while (notokHead.count) {
1227 qGet(¬okHead, &volid);
1228 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1229 (unsigned long)volid);
1234 fprintf(STDOUT, "\n");
1237 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1238 totalOK, totalNotOK, totalBusy);
1242 } /*XDisplayVolumes */
1243 #ifdef FULL_LISTVOL_SWITCH
1244 /*------------------------------------------------------------------------
1245 * PRIVATE XDisplayVolumes2
1248 * Display extended formated volume information.
1251 * a_servID : Pointer to the Rx call we're performing.
1252 * a_partID : Partition for which we want the extended list.
1253 * a_xInfoP : Ptr to extended volume info.
1254 * a_count : Number of volume records contained above.
1255 * a_int32 : Int32 listing generated?
1256 * a_fast : Fast listing generated?
1257 * a_quiet : Quiet listing generated?
1263 * Nothing interesting.
1267 *------------------------------------------------------------------------*/
1270 XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1274 volintXInfo *a_xInfoP;
1280 { /*XDisplayVolumes */
1282 int totalOK; /*Total OK volumes */
1283 int totalNotOK; /*Total screwed volumes */
1284 int totalBusy; /*Total busy volumes */
1285 int i; /*Loop variable */
1286 afs_int32 volid; /*Current volume ID */
1289 * Initialize counters and (global!!) queues.
1298 * Display each volume in the list.
1300 for (i = 0; i < a_count; i++) {
1301 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1302 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1303 &totalBusy, a_fast, a_int32, 0);
1304 fprintf(STDOUT, "END_OF_ENTRY\n");
1309 * If any volumes were found to be busy or screwed, display them.
1312 while (busyHead.count) {
1313 qGet(&busyHead, &volid);
1314 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1315 (unsigned long)volid);
1319 while (notokHead.count) {
1320 qGet(¬okHead, &volid);
1321 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1322 (unsigned long)volid);
1327 fprintf(STDOUT, "\n");
1330 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1331 totalOK, totalNotOK, totalBusy);
1335 } /*XDisplayVolumes2 */
1336 #endif /* FULL_LISTVOL_SWITCH */
1339 /* set <server> and <part> to the correct values depending on
1340 * <voltype> and <entry> */
1342 GetServerAndPart(entry, voltype, server, part, previdx)
1343 struct nvldbentry *entry;
1344 afs_int32 *server, *part;
1348 int i, istart, vtype;
1353 /* Doesn't check for non-existance of backup volume */
1354 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1356 istart = 0; /* seach the entire entry */
1359 /* Seach from beginning of entry or pick up where we left off */
1360 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1363 for (i = istart; i < entry->nServers; i++) {
1364 if (entry->serverFlags[i] & vtype) {
1365 *server = entry->serverNumber[i];
1366 *part = entry->serverPartition[i];
1372 /* Didn't find any, return -1 */
1378 PostVolumeStats(entry)
1379 struct nvldbentry *entry;
1381 SubEnumerateEntry(entry);
1382 /* Check for VLOP_ALLOPERS */
1383 if (entry->flags & VLOP_ALLOPERS)
1384 fprintf(STDOUT, " Volume is currently LOCKED \n");
1388 /*------------------------------------------------------------------------
1389 * PRIVATE XVolumeStats
1392 * Display extended volume information.
1395 * a_xInfoP : Ptr to extended volume info.
1396 * a_entryP : Ptr to the volume's VLDB entry.
1397 * a_srvID : Server ID.
1398 * a_partID : Partition ID.
1399 * a_volType : Type of volume to print.
1405 * Nothing interesting.
1409 *------------------------------------------------------------------------*/
1412 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1413 volintXInfo *a_xInfoP;
1414 struct nvldbentry *a_entryP;
1421 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1423 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1424 a_srvID, /*Server ID to print */
1425 a_partID, /*Partition ID to print */
1426 &totalOK, /*Ptr to total-OK counter */
1427 &totalNotOK, /*Ptr to total-screwed counter */
1428 &totalBusy, /*Ptr to total-busy counter */
1429 0, /*Don't do a fast listing */
1430 1, /*Do a long listing */
1431 1); /*Show volume problems */
1437 VolumeStats(pntr, entry, server, part, voltype)
1439 struct nvldbentry *entry;
1441 afs_int32 server, part;
1443 int totalOK, totalNotOK, totalBusy;
1445 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1450 /* command to forcibly remove a volume */
1453 register struct cmd_syndesc *as;
1455 register afs_int32 code;
1456 afs_int32 volID, err;
1461 server = GetServer(tp = as->parms[0].items->data);
1463 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1467 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1469 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1473 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1476 PrintError("", err);
1479 "vos: could not parse '%s' as a numeric volume ID", tp);
1484 "vos: forcibly removing all traces of volume %d, please wait...",
1487 code = UV_NukeVolume(server, partID, volID);
1489 fprintf(STDOUT, "done.\n");
1491 fprintf(STDOUT, "failed with code %d.\n", code);
1496 /*------------------------------------------------------------------------
1497 * PRIVATE ExamineVolume
1500 * Routine used to examine a single volume, contacting the VLDB as
1501 * well as the Volume Server.
1504 * as : Ptr to parsed command line arguments.
1507 * 0 for a successful operation,
1508 * Otherwise, one of the ubik or VolServer error values.
1511 * Nothing interesting.
1515 *------------------------------------------------------------------------
1519 register struct cmd_syndesc *as;
1521 struct nvldbentry entry;
1522 afs_int32 vcode = 0;
1523 volintInfo *pntr = (volintInfo *) 0;
1524 volintXInfo *xInfoP = (volintXInfo *) 0;
1526 afs_int32 code, err, error = 0;
1527 int voltype, foundserv = 0, foundentry = 0;
1528 afs_int32 aserver, apart;
1530 int wantExtendedInfo; /*Do we want extended vol info? */
1532 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1534 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1537 PrintError("", err);
1539 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1540 as->parms[0].items->data);
1545 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1546 (unsigned long)volid);
1549 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1552 "Could not fetch the entry for volume number %lu from VLDB \n",
1553 (unsigned long)volid);
1557 fprintf(STDOUT, "done\n");
1558 MapHostToNetwork(&entry);
1560 if (entry.volumeId[RWVOL] == volid)
1562 else if (entry.volumeId[BACKVOL] == volid)
1564 else /* (entry.volumeId[ROVOL] == volid) */
1567 do { /* do {...} while (voltype == ROVOL) */
1568 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1569 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1570 * If its a RO vol, get the next RO entry.
1572 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1573 &aserver, &apart, &previdx);
1574 if (previdx == -1) { /* searched all entries */
1576 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1577 as->parms[0].items->data);
1584 /* Get information about the volume from the server */
1586 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1587 hostutil_GetNameByINet(aserver));
1590 if (wantExtendedInfo)
1591 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1593 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1595 fprintf(STDOUT, "done\n");
1599 if (code == ENODEV) {
1600 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1601 /* The VLDB says there is no backup volume and its not on disk */
1602 fprintf(STDERR, "Volume %s does not exist\n",
1603 as->parms[0].items->data);
1607 "Volume does not exist on server %s as indicated by the VLDB\n",
1608 hostutil_GetNameByINet(aserver));
1611 PrintDiagnostics("examine", code);
1613 fprintf(STDOUT, "\n");
1616 if (wantExtendedInfo)
1617 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1619 #ifdef FULL_LISTVOL_SWITCH
1620 if (as->parms[2].items) {
1621 DisplayFormat2(aserver, apart, pntr);
1622 EnumerateEntry(&entry);
1624 #endif /* FULL_LISTVOL_SWITCH */
1625 VolumeStats(pntr, &entry, aserver, apart, voltype);
1627 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1628 /* The VLDB says there is no backup volume yet we found one on disk */
1629 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1630 as->parms[0].items->data);
1639 } while (voltype == ROVOL);
1642 fprintf(STDERR, "Dump only information from VLDB\n\n");
1643 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1645 PostVolumeStats(&entry);
1650 /*------------------------------------------------------------------------
1654 * Routine used to change the status of a single volume.
1657 * as : Ptr to parsed command line arguments.
1660 * 0 for a successful operation,
1661 * Otherwise, one of the ubik or VolServer error values.
1664 * Nothing interesting.
1668 *------------------------------------------------------------------------
1672 register struct cmd_syndesc *as;
1674 struct nvldbentry entry;
1675 afs_int32 vcode = 0;
1678 afs_int32 code, err;
1679 afs_int32 aserver, apart;
1682 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1685 PrintError("", err);
1687 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1688 as->parms[0].items->data);
1692 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1695 "Could not fetch the entry for volume number %lu from VLDB \n",
1696 (unsigned long)volid);
1699 MapHostToNetwork(&entry);
1701 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1702 if (previdx == -1) {
1703 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1704 as->parms[0].items->data);
1708 init_volintInfo(&info);
1712 if (as->parms[1].items) {
1714 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1716 fprintf(STDERR, "invalid quota value\n");
1720 if (as->parms[2].items) {
1724 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1727 "Could not update volume info fields for volume number %lu\n",
1728 (unsigned long)volid);
1732 /*------------------------------------------------------------------------
1736 * Brings a volume online.
1739 * as : Ptr to parsed command line arguments.
1742 * 0 for a successful operation,
1745 * Nothing interesting.
1749 *------------------------------------------------------------------------
1753 register struct cmd_syndesc *as;
1755 afs_int32 server, partition, volid;
1756 afs_int32 code, err = 0;
1758 server = GetServer(as->parms[0].items->data);
1760 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1761 as->parms[0].items->data);
1765 partition = volutil_GetPartitionID(as->parms[1].items->data);
1766 if (partition < 0) {
1767 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1768 as->parms[1].items->data);
1772 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1775 PrintError("", err);
1777 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1778 as->parms[0].items->data);
1782 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1785 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1792 /*------------------------------------------------------------------------
1793 * PRIVATE volOffline
1796 * Brings a volume offline.
1799 * as : Ptr to parsed command line arguments.
1802 * 0 for a successful operation,
1805 * Nothing interesting.
1809 *------------------------------------------------------------------------
1812 volOffline(register struct cmd_syndesc *as)
1814 afs_int32 server, partition, volid;
1815 afs_int32 code, err = 0;
1816 afs_int32 transflag, sleeptime, transdone;
1818 server = GetServer(as->parms[0].items->data);
1820 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1821 as->parms[0].items->data);
1825 partition = volutil_GetPartitionID(as->parms[1].items->data);
1826 if (partition < 0) {
1827 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1828 as->parms[1].items->data);
1832 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1835 PrintError("", err);
1837 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1838 as->parms[0].items->data);
1842 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1843 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1844 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1845 if (as->parms[4].items && !as->parms[3].items) {
1846 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1851 UV_SetVolume(server, partition, volid, transflag, transdone,
1854 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1862 CreateVolume(register struct cmd_syndesc *as)
1866 afs_int32 volid, code;
1867 struct nvldbentry entry;
1872 tserver = GetServer(as->parms[0].items->data);
1874 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1875 as->parms[0].items->data);
1878 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1880 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1881 as->parms[1].items->data);
1884 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1886 PrintError("", code);
1889 "vos : partition %s does not exist on the server\n",
1890 as->parms[1].items->data);
1893 if (!ISNAMEVALID(as->parms[2].items->data)) {
1895 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1896 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1899 if (!VolNameOK(as->parms[2].items->data)) {
1901 "Illegal volume name %s, should not end in .readonly or .backup\n",
1902 as->parms[2].items->data);
1905 if (IsNumeric(as->parms[2].items->data)) {
1906 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1907 as->parms[2].items->data);
1910 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1912 fprintf(STDERR, "Volume %s already exists\n",
1913 as->parms[2].items->data);
1914 PrintDiagnostics("create", code);
1918 if (as->parms[3].items) {
1919 if (!IsNumeric(as->parms[3].items->data)) {
1920 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1921 as->parms[3].items->data);
1925 code = util_GetInt32(as->parms[3].items->data, "a);
1927 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1933 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1936 PrintDiagnostics("create", code);
1939 MapPartIdIntoName(pnum, part);
1940 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1941 (unsigned long)volid, part, as->parms[0].items->data);
1948 struct nvldbentry *entry;
1951 afs_int32 error, code, curserver, curpart, volid;
1953 MapHostToNetwork(entry);
1955 for (i = 0; i < entry->nServers; i++) {
1956 curserver = entry->serverNumber[i];
1957 curpart = entry->serverPartition[i];
1958 if (entry->serverFlags[i] & ITSROVOL) {
1959 volid = entry->volumeId[ROVOL];
1961 volid = entry->volumeId[RWVOL];
1963 code = UV_DeleteVolume(curserver, curpart, volid);
1972 struct cmd_syndesc *as;
1974 afs_int32 err, code = 0;
1975 afs_int32 server = 0, partition = -1, volid;
1979 if (as->parms[0].items) {
1980 server = GetServer(as->parms[0].items->data);
1982 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1983 as->parms[0].items->data);
1988 if (as->parms[1].items) {
1989 partition = volutil_GetPartitionID(as->parms[1].items->data);
1990 if (partition < 0) {
1991 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1992 as->parms[1].items->data);
1996 /* Check for validity of the partition */
1997 if (!IsPartValid(partition, server, &code)) {
1999 PrintError("", code);
2002 "vos : partition %s does not exist on the server\n",
2003 as->parms[1].items->data);
2009 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2011 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2012 as->parms[2].items->data);
2014 PrintError("", err);
2018 /* If the server or partition option are not complete, try to fill
2019 * them in from the VLDB entry.
2021 if ((partition == -1) || !server) {
2022 struct nvldbentry entry;
2024 code = VLDB_GetEntryByID(volid, -1, &entry);
2027 "Could not fetch the entry for volume %lu from VLDB\n",
2028 (unsigned long)volid);
2029 PrintError("", code);
2033 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2034 || ((volid == entry.volumeId[BACKVOL])
2035 && (entry.flags & BACK_EXISTS))) {
2036 idx = Lp_GetRwIndex(&entry);
2037 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2038 || ((partition != -1)
2039 && (partition != entry.serverPartition[idx]))) {
2040 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2041 as->parms[2].items->data);
2044 } else if ((volid == entry.volumeId[ROVOL])
2045 && (entry.flags & RO_EXISTS)) {
2046 for (idx = -1, j = 0; j < entry.nServers; j++) {
2047 if (entry.serverFlags[j] != ITSROVOL)
2050 if (((server == 0) || (server == entry.serverNumber[j]))
2051 && ((partition == -1)
2052 || (partition == entry.serverPartition[j]))) {
2055 "VLDB: Volume '%s' matches more than one RO\n",
2056 as->parms[2].items->data);
2063 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2064 as->parms[2].items->data);
2068 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2069 as->parms[2].items->data);
2073 server = htonl(entry.serverNumber[idx]);
2074 partition = entry.serverPartition[idx];
2078 code = UV_DeleteVolume(server, partition, volid);
2080 PrintDiagnostics("remove", code);
2084 MapPartIdIntoName(partition, pname);
2085 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2086 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2090 #define TESTM 0 /* set for move space tests, clear for production */
2093 register struct cmd_syndesc *as;
2096 afs_int32 volid, fromserver, toserver, frompart, topart;
2097 afs_int32 flags, code, err;
2098 char fromPartName[10], toPartName[10];
2100 struct diskPartition partition; /* for space check */
2103 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2106 PrintError("", err);
2108 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2109 as->parms[0].items->data);
2112 fromserver = GetServer(as->parms[1].items->data);
2113 if (fromserver == 0) {
2114 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2115 as->parms[1].items->data);
2118 toserver = GetServer(as->parms[3].items->data);
2119 if (toserver == 0) {
2120 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2121 as->parms[3].items->data);
2124 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2126 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2127 as->parms[2].items->data);
2130 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2132 PrintError("", code);
2135 "vos : partition %s does not exist on the server\n",
2136 as->parms[2].items->data);
2139 topart = volutil_GetPartitionID(as->parms[4].items->data);
2141 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2142 as->parms[4].items->data);
2145 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2147 PrintError("", code);
2150 "vos : partition %s does not exist on the server\n",
2151 as->parms[4].items->data);
2156 if (as->parms[5].items) flags |= RV_NOCLONE;
2159 * check source partition for space to clone volume
2162 MapPartIdIntoName(topart, toPartName);
2163 MapPartIdIntoName(frompart, fromPartName);
2166 * check target partition for space to move volume
2169 code = UV_PartitionInfo(toserver, toPartName, &partition);
2171 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2175 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2178 p = (volintInfo *) 0;
2179 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2181 fprintf(STDERR, "vos:cannot access volume %lu\n",
2182 (unsigned long)volid);
2187 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2189 if (partition.free <= p->size) {
2191 "vos: no space on target partition %s to move volume %lu\n",
2192 toPartName, (unsigned long)volid);
2199 fprintf(STDOUT, "size test - don't do move\n");
2203 /* successful move still not guaranteed but shoot for it */
2206 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2208 PrintDiagnostics("move", code);
2211 MapPartIdIntoName(topart, toPartName);
2212 MapPartIdIntoName(frompart, fromPartName);
2213 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2214 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2215 as->parms[3].items->data, toPartName);
2222 register struct cmd_syndesc *as;
2224 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
2225 char fromPartName[10], toPartName[10], *tovolume;
2226 struct nvldbentry entry;
2227 struct diskPartition partition; /* for space check */
2230 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2233 PrintError("", err);
2235 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2236 as->parms[0].items->data);
2239 fromserver = GetServer(as->parms[1].items->data);
2240 if (fromserver == 0) {
2241 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2242 as->parms[1].items->data);
2246 toserver = GetServer(as->parms[4].items->data);
2247 if (toserver == 0) {
2248 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2249 as->parms[4].items->data);
2253 tovolume = as->parms[3].items->data;
2254 if (!ISNAMEVALID(tovolume)) {
2256 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2257 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2260 if (!VolNameOK(tovolume)) {
2262 "Illegal volume name %s, should not end in .readonly or .backup\n",
2266 if (IsNumeric(tovolume)) {
2267 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2271 code = VLDB_GetEntryByName(tovolume, &entry);
2273 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2274 PrintDiagnostics("copy", code);
2278 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2280 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2281 as->parms[2].items->data);
2284 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2286 PrintError("", code);
2289 "vos : partition %s does not exist on the server\n",
2290 as->parms[2].items->data);
2294 topart = volutil_GetPartitionID(as->parms[5].items->data);
2296 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2297 as->parms[5].items->data);
2300 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2302 PrintError("", code);
2305 "vos : partition %s does not exist on the server\n",
2306 as->parms[5].items->data);
2311 if (as->parms[6].items) flags |= RV_OFFLINE;
2312 if (as->parms[7].items) flags |= RV_RDONLY;
2313 if (as->parms[8].items) flags |= RV_NOCLONE;
2315 MapPartIdIntoName(topart, toPartName);
2316 MapPartIdIntoName(frompart, fromPartName);
2319 * check target partition for space to move volume
2322 code = UV_PartitionInfo(toserver, toPartName, &partition);
2324 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2328 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2331 p = (volintInfo *) 0;
2332 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2334 fprintf(STDERR, "vos:cannot access volume %lu\n",
2335 (unsigned long)volid);
2340 if (partition.free <= p->size) {
2342 "vos: no space on target partition %s to copy volume %lu\n",
2343 toPartName, (unsigned long)volid);
2349 /* successful copy still not guaranteed but shoot for it */
2352 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2355 PrintDiagnostics("copy", code);
2358 MapPartIdIntoName(topart, toPartName);
2359 MapPartIdIntoName(frompart, fromPartName);
2360 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2361 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2362 tovolume, as->parms[4].items->data, toPartName);
2370 register struct cmd_syndesc *as;
2372 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2373 afs_int32 code, err, flags;
2374 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2375 struct nvldbentry entry;
2376 struct diskPartition partition; /* for space check */
2379 p = (volintInfo *) 0;
2380 q = (volintInfo *) 0;
2382 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2385 PrintError("", err);
2387 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2388 as->parms[0].items->data);
2391 fromserver = GetServer(as->parms[1].items->data);
2392 if (fromserver == 0) {
2393 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2394 as->parms[1].items->data);
2398 toserver = GetServer(as->parms[3].items->data);
2399 if (toserver == 0) {
2400 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2401 as->parms[3].items->data);
2405 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2407 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2408 as->parms[2].items->data);
2411 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2413 PrintError("", code);
2416 "vos : partition %s does not exist on the server\n",
2417 as->parms[2].items->data);
2421 topart = volutil_GetPartitionID(as->parms[4].items->data);
2423 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2424 as->parms[4].items->data);
2427 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2429 PrintError("", code);
2432 "vos : partition %s does not exist on the server\n",
2433 as->parms[4].items->data);
2437 if (as->parms[5].items) {
2438 tovolume = as->parms[5].items->data;
2439 if (!ISNAMEVALID(tovolume)) {
2441 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2442 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2445 if (!VolNameOK(tovolume)) {
2447 "Illegal volume name %s, should not end in .readonly or .backup\n",
2451 if (IsNumeric(tovolume)) {
2453 "Illegal volume name %s, should not be a number\n",
2458 /* use actual name of source volume */
2459 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2461 fprintf(STDERR, "vos:cannot access volume %lu\n",
2462 (unsigned long)volid);
2465 strcpy(toVolName, p->name);
2466 tovolume = toVolName;
2467 /* save p for size checks later */
2470 if (as->parms[6].items) {
2471 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2474 PrintError("", err);
2476 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2477 as->parms[6].items->data);
2483 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2486 PrintError("", err);
2488 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2497 if (as->parms[7].items) flags |= RV_OFFLINE;
2498 if (as->parms[8].items) flags |= RV_RDONLY;
2499 if (as->parms[9].items) flags |= RV_NOCLONE;
2500 if (as->parms[10].items) flags |= RV_CPINCR;
2502 MapPartIdIntoName(topart, toPartName);
2503 MapPartIdIntoName(frompart, fromPartName);
2506 * check target partition for space to move volume
2509 code = UV_PartitionInfo(toserver, toPartName, &partition);
2511 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2515 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2518 /* Don't do this again if we did it above */
2520 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2522 fprintf(STDERR, "vos:cannot access volume %lu\n",
2523 (unsigned long)volid);
2528 /* OK if this fails */
2529 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2531 /* Treat existing volume size as "free" */
2533 p->size = (q->size < p->size) ? p->size - q->size : 0;
2535 if (partition.free <= p->size) {
2537 "vos: no space on target partition %s to copy volume %lu\n",
2538 toPartName, (unsigned long)volid);
2546 /* successful copy still not guaranteed but shoot for it */
2549 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2550 topart, tovolid, flags);
2552 PrintDiagnostics("shadow", code);
2555 MapPartIdIntoName(topart, toPartName);
2556 MapPartIdIntoName(frompart, fromPartName);
2557 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2558 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2559 as->parms[3].items->data, toPartName);
2567 register struct cmd_syndesc *as;
2569 afs_int32 server, part, volid, cloneid, voltype;
2570 char partName[10], *volname;
2571 afs_int32 code, err, flags;
2572 struct nvldbentry entry;
2574 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2577 PrintError("", err);
2579 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2580 as->parms[0].items->data);
2584 if (as->parms[1].items || as->parms[2].items) {
2585 if (!as->parms[1].items || !as->parms[2].items) {
2587 "Must specify both -server and -partition options\n");
2590 server = GetServer(as->parms[1].items->data);
2592 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2593 as->parms[1].items->data);
2596 part = volutil_GetPartitionID(as->parms[2].items->data);
2598 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2599 as->parms[2].items->data);
2602 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2604 PrintError("", code);
2607 "vos : partition %s does not exist on the server\n",
2608 as->parms[2].items->data);
2612 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2618 if (as->parms[3].items) {
2619 volname = as->parms[3].items->data;
2620 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2622 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2623 volname, VOLSER_OLDMAXVOLNAME - 1);
2626 if (!VolNameOK(volname)) {
2628 "Illegal volume name %s, should not end in .readonly or .backup\n",
2632 if (IsNumeric(volname)) {
2634 "Illegal volume name %s, should not be a number\n",
2641 if (as->parms[4].items) {
2642 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2645 PrintError("", err);
2647 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2648 as->parms[4].items->data);
2654 if (as->parms[5].items) flags |= RV_OFFLINE;
2655 if (as->parms[6].items) flags |= RV_RDONLY;
2659 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2662 PrintDiagnostics("clone", code);
2665 MapPartIdIntoName(part, partName);
2666 fprintf(STDOUT, "Created clone for volume %lu\n",
2667 as->parms[0].items->data);
2675 register struct cmd_syndesc *as;
2677 afs_int32 avolid, aserver, apart, vtype, code, err;
2678 struct nvldbentry entry;
2680 afs_int32 buvolid, buserver, bupart, butype;
2681 struct nvldbentry buentry;
2683 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2686 PrintError("", err);
2688 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2689 as->parms[0].items->data);
2692 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2696 /* verify this is a readwrite volume */
2698 if (vtype != RWVOL) {
2699 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2703 /* is there a backup volume already? */
2705 if (entry.flags & BACK_EXISTS) {
2706 /* yep, where is it? */
2708 buvolid = entry.volumeId[BACKVOL];
2709 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2714 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2717 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2723 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2724 (unsigned long)buvolid, (unsigned long)buserver);
2729 /* nope, carry on */
2731 code = UV_BackupVolume(aserver, apart, avolid);
2734 PrintDiagnostics("backup", code);
2737 fprintf(STDOUT, "Created backup volume for %s \n",
2738 as->parms[0].items->data);
2744 register struct cmd_syndesc *as;
2747 struct nvldbentry entry;
2748 afs_int32 avolid, aserver, apart, vtype, code, err;
2751 if (as->parms[1].items)
2753 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2756 PrintError("", err);
2758 fprintf(STDERR, "vos: can't find volume '%s'\n",
2759 as->parms[0].items->data);
2762 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2766 if (vtype != RWVOL) {
2767 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2771 if (!ISNAMEVALID(entry.name)) {
2773 "Volume name %s is too long, rename before releasing\n",
2778 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2780 PrintDiagnostics("release", code);
2783 fprintf(STDOUT, "Released volume %s successfully\n",
2784 as->parms[0].items->data);
2790 register struct cmd_syndesc *as;
2793 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
2794 char filename[NameLen];
2795 struct nvldbentry entry;
2797 rx_SetRxDeadTime(60 * 10);
2798 for (i = 0; i < MAXSERVERS; i++) {
2799 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2802 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2803 if (rxConn->service)
2804 rxConn->service->connDeadTime = rx_connDeadTime;
2807 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2810 PrintError("", err);
2812 fprintf(STDERR, "vos: can't find volume '%s'\n",
2813 as->parms[0].items->data);
2817 if (as->parms[3].items || as->parms[4].items) {
2818 if (!as->parms[3].items || !as->parms[4].items) {
2820 "Must specify both -server and -partition options\n");
2823 aserver = GetServer(as->parms[3].items->data);
2825 fprintf(STDERR, "Invalid server name\n");
2828 apart = volutil_GetPartitionID(as->parms[4].items->data);
2830 fprintf(STDERR, "Invalid partition name\n");
2834 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2839 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2840 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2842 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2843 as->parms[1].items->data, code);
2847 if (as->parms[2].items) {
2848 strcpy(filename, as->parms[2].items->data);
2850 strcpy(filename, "");
2853 if (as->parms[5].items) {
2855 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2856 DumpFunction, filename);
2859 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2863 PrintDiagnostics("dump", code);
2866 if (strcmp(filename, ""))
2867 fprintf(STDERR, "Dumped volume %s in file %s\n",
2868 as->parms[0].items->data, filename);
2870 fprintf(STDERR, "Dumped volume %s in stdout \n",
2871 as->parms[0].items->data);
2886 register struct cmd_syndesc *as;
2889 afs_int32 avolid, aserver, apart, code, vcode, err;
2890 afs_int32 aoverwrite = ASK;
2891 afs_int32 acreation = 0, alastupdate = 0;
2892 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2894 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2895 char volname[VOLSER_MAXVOLNAME + 1];
2896 struct nvldbentry entry;
2900 if (as->parms[4].items) {
2901 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2904 PrintError("", err);
2906 fprintf(STDERR, "vos: can't find volume '%s'\n",
2907 as->parms[4].items->data);
2913 if (as->parms[5].items) {
2914 if ((strcmp(as->parms[5].items->data, "a") == 0)
2915 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2917 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2918 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2920 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2921 || (strcmp(as->parms[5].items->data, "inc") == 0)
2922 || (strcmp(as->parms[5].items->data, "increment") == 0)
2923 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2926 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2927 as->parms[5].items->data);
2931 if (as->parms[6].items)
2933 if (as->parms[7].items) {
2938 if (as->parms[8].items) {
2939 if ((strcmp(as->parms[8].items->data, "d") == 0)
2940 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2941 acreation = TS_DUMP;
2942 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2943 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2944 acreation = TS_KEEP;
2945 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2946 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2949 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2950 as->parms[8].items->data);
2955 if (as->parms[9].items) {
2956 if ((strcmp(as->parms[9].items->data, "d") == 0)
2957 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2958 alastupdate = TS_DUMP;
2959 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2960 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2961 alastupdate = TS_KEEP;
2962 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2963 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2964 alastupdate = TS_NEW;
2966 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2967 as->parms[9].items->data);
2972 aserver = GetServer(as->parms[0].items->data);
2974 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2975 as->parms[0].items->data);
2978 apart = volutil_GetPartitionID(as->parms[1].items->data);
2980 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2981 as->parms[1].items->data);
2984 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2986 PrintError("", code);
2989 "vos : partition %s does not exist on the server\n",
2990 as->parms[1].items->data);
2993 strcpy(avolname, as->parms[2].items->data);
2994 if (!ISNAMEVALID(avolname)) {
2996 "vos: the name of the volume %s exceeds the size limit\n",
3000 if (!VolNameOK(avolname)) {
3002 "Illegal volume name %s, should not end in .readonly or .backup\n",
3006 if (as->parms[3].items) {
3007 strcpy(afilename, as->parms[3].items->data);
3008 if (!FileExists(afilename)) {
3009 fprintf(STDERR, "Can't access file %s\n", afilename);
3013 strcpy(afilename, "");
3016 /* Check if volume exists or not */
3018 vsu_ExtractName(volname, avolname);
3019 vcode = VLDB_GetEntryByName(volname, &entry);
3020 if (vcode) { /* no volume - do a full restore */
3021 restoreflags = RV_FULLRST;
3022 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3024 "Volume does not exist; Will perform a full restore\n");
3027 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3028 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3029 restoreflags = RV_FULLRST;
3030 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3032 "%s Volume does not exist; Will perform a full restore\n",
3033 readonly ? "RO" : "RW");
3036 avolid = entry.volumeId[voltype];
3037 } else if (entry.volumeId[voltype] != 0
3038 && entry.volumeId[voltype] != avolid) {
3039 avolid = entry.volumeId[voltype];
3043 else { /* volume exists - do we do a full incremental or abort */
3044 int Oserver, Opart, Otype, vol_elsewhere = 0;
3045 struct nvldbentry Oentry;
3049 avolid = entry.volumeId[voltype];
3050 } else if (entry.volumeId[voltype] != 0
3051 && entry.volumeId[voltype] != avolid) {
3052 avolid = entry.volumeId[voltype];
3055 /* A file name was specified - check if volume is on another partition */
3056 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3060 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3063 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3067 if (!vcode || (Opart != apart))
3070 if (aoverwrite == ASK) {
3071 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3073 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3077 /* Ask what to do */
3078 if (vol_elsewhere) {
3080 "The volume %s %u already exists on a different server/part\n",
3081 volname, entry.volumeId[voltype]);
3083 "Do you want to do a full restore or abort? [fa](a): ");
3086 "The volume %s %u already exists in the VLDB\n",
3087 volname, entry.volumeId[voltype]);
3089 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3092 while (!(dc == EOF || dc == '\n'))
3093 dc = getchar(); /* goto end of line */
3094 if ((c == 'f') || (c == 'F'))
3096 else if ((c == 'i') || (c == 'I'))
3102 if (aoverwrite == ABORT) {
3103 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3105 } else if (aoverwrite == FULL) {
3106 restoreflags = RV_FULLRST;
3108 "Volume exists; Will delete and perform full restore\n");
3109 } else if (aoverwrite == INC) {
3111 if (vol_elsewhere) {
3113 "%s volume %lu already exists on a different server/part; not allowed\n",
3114 readonly ? "RO" : "RW", (unsigned long)avolid);
3120 restoreflags |= RV_OFFLINE;
3122 restoreflags |= RV_RDONLY;
3124 switch (acreation) {
3126 restoreflags |= RV_CRDUMP;
3129 restoreflags |= RV_CRKEEP;
3132 restoreflags |= RV_CRNEW;
3135 if (aoverwrite == FULL)
3136 restoreflags |= RV_CRNEW;
3138 restoreflags |= RV_CRKEEP;
3141 switch (alastupdate) {
3143 restoreflags |= RV_LUDUMP;
3146 restoreflags |= RV_LUKEEP;
3149 restoreflags |= RV_LUNEW;
3152 restoreflags |= RV_LUDUMP;
3156 UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags,
3157 WriteData, afilename);
3159 PrintDiagnostics("restore", code);
3162 MapPartIdIntoName(apart, apartName);
3165 * patch typo here - originally "parms[1]", should be "parms[0]"
3168 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3169 as->parms[0].items->data, apartName);
3175 register struct cmd_syndesc *as;
3178 afs_int32 avolid, code, err;
3180 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3183 PrintError("", err);
3185 fprintf(STDERR, "vos: can't find volume '%s'\n",
3186 as->parms[0].items->data);
3190 code = UV_LockRelease(avolid);
3192 PrintDiagnostics("unlock", code);
3195 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3196 as->parms[0].items->data);
3202 register struct cmd_syndesc *as;
3204 afs_int32 avolid, aserver, apart, code, err;
3205 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3207 vsu_ExtractName(avolname, as->parms[2].items->data);;
3208 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3211 PrintError("", err);
3213 fprintf(STDERR, "vos: can't find volume '%s'\n",
3214 as->parms[2].items->data);
3217 aserver = GetServer(as->parms[0].items->data);
3219 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3220 as->parms[0].items->data);
3223 apart = volutil_GetPartitionID(as->parms[1].items->data);
3225 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3226 as->parms[1].items->data);
3229 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3231 PrintError("", code);
3234 "vos : partition %s does not exist on the server\n",
3235 as->parms[1].items->data);
3238 code = UV_AddSite(aserver, apart, avolid);
3240 PrintDiagnostics("addsite", code);
3243 MapPartIdIntoName(apart, apartName);
3244 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3245 as->parms[0].items->data, apartName, as->parms[2].items->data);
3251 register struct cmd_syndesc *as;
3254 afs_int32 avolid, aserver, apart, code, err;
3255 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3257 vsu_ExtractName(avolname, as->parms[2].items->data);
3258 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3261 PrintError("", err);
3263 fprintf(STDERR, "vos: can't find volume '%s'\n",
3264 as->parms[2].items->data);
3267 aserver = GetServer(as->parms[0].items->data);
3269 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3270 as->parms[0].items->data);
3273 apart = volutil_GetPartitionID(as->parms[1].items->data);
3275 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3276 as->parms[1].items->data);
3280 *skip the partition validity check, since it is possible that the partition
3281 *has since been decomissioned.
3284 if (!IsPartValid(apart,aserver,&code)){
3285 if(code) PrintError("",code);
3286 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3290 code = UV_RemoveSite(aserver, apart, avolid);
3292 PrintDiagnostics("remsite", code);
3295 MapPartIdIntoName(apart, apartName);
3296 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3297 as->parms[0].items->data, apartName, as->parms[2].items->data);
3303 register struct cmd_syndesc *as;
3305 afs_int32 avolid, aserver, apart, code, err;
3308 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3311 PrintError("", err);
3313 fprintf(STDERR, "vos: can't find volume '%s'\n",
3314 as->parms[2].items->data);
3317 aserver = GetServer(as->parms[0].items->data);
3319 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3320 as->parms[0].items->data);
3323 apart = volutil_GetPartitionID(as->parms[1].items->data);
3325 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3326 as->parms[1].items->data);
3329 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3331 PrintError("", code);
3334 "vos : partition %s does not exist on the server\n",
3335 as->parms[1].items->data);
3338 code = UV_ChangeLocation(aserver, apart, avolid);
3340 PrintDiagnostics("addsite", code);
3343 MapPartIdIntoName(apart, apartName);
3344 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3345 as->parms[0].items->data, apartName, as->parms[2].items->data);
3351 register struct cmd_syndesc *as;
3353 afs_int32 aserver, code;
3354 struct partList dummyPartList;
3359 aserver = GetServer(as->parms[0].items->data);
3361 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3362 as->parms[0].items->data);
3367 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3369 PrintDiagnostics("listpart", code);
3373 fprintf(STDOUT, "The partitions on the server are:\n");
3374 for (i = 0; i < cnt; i++) {
3375 if (dummyPartList.partFlags[i] & PARTVALID) {
3376 memset(pname, 0, sizeof(pname));
3377 MapPartIdIntoName(dummyPartList.partId[i], pname);
3378 fprintf(STDOUT, " %10s ", pname);
3380 if ((i % 5) == 0 && (i != 0))
3381 fprintf(STDOUT, "\n");
3384 fprintf(STDOUT, "\n");
3385 fprintf(STDOUT, "Total: %d\n", total);
3391 CompareVolName(p1, p2)
3394 volintInfo *arg1, *arg2;
3396 arg1 = (volintInfo *) p1;
3397 arg2 = (volintInfo *) p2;
3398 return (strcmp(arg1->name, arg2->name));
3402 /*------------------------------------------------------------------------
3403 * PRIVATE XCompareVolName
3406 * Comparison routine for volume names coming from an extended
3410 * a_obj1P : Char ptr to first extended vol info object
3411 * a_obj1P : Char ptr to second extended vol info object
3414 * The value of strcmp() on the volume names within the passed
3415 * objects (i,e., -1, 0, or 1).
3418 * Passed to qsort() as the designated comparison routine.
3422 *------------------------------------------------------------------------*/
3425 XCompareVolName(a_obj1P, a_obj2P)
3426 char *a_obj1P, *a_obj2P;
3428 { /*XCompareVolName */
3431 (((struct volintXInfo *)(a_obj1P))->name,
3432 ((struct volintXInfo *)(a_obj2P))->name));
3434 } /*XCompareVolName */
3437 CompareVolID(p1, p2)
3440 volintInfo *arg1, *arg2;
3442 arg1 = (volintInfo *) p1;
3443 arg2 = (volintInfo *) p2;
3444 if (arg1->volid == arg2->volid)
3446 if (arg1->volid > arg2->volid)
3453 /*------------------------------------------------------------------------
3454 * PRIVATE XCompareVolID
3457 * Comparison routine for volume IDs coming from an extended
3461 * a_obj1P : Char ptr to first extended vol info object
3462 * a_obj1P : Char ptr to second extended vol info object
3465 * The value of strcmp() on the volume names within the passed
3466 * objects (i,e., -1, 0, or 1).
3469 * Passed to qsort() as the designated comparison routine.
3473 *------------------------------------------------------------------------*/
3476 XCompareVolID(a_obj1P, a_obj2P)
3477 char *a_obj1P, *a_obj2P;
3479 { /*XCompareVolID */
3481 afs_int32 id1, id2; /*Volume IDs we're comparing */
3483 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3484 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3492 } /*XCompareVolID */
3494 /*------------------------------------------------------------------------
3495 * PRIVATE ListVolumes
3498 * Routine used to list volumes, contacting the Volume Server
3499 * directly, bypassing the VLDB.
3502 * as : Ptr to parsed command line arguments.
3505 * 0 Successful operation
3508 * Nothing interesting.
3512 *------------------------------------------------------------------------*/
3516 register struct cmd_syndesc *as;
3518 afs_int32 apart, int32list, fast;
3519 afs_int32 aserver, code;
3520 volintInfo *pntr, *oldpntr;
3524 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3525 int wantExtendedInfo; /*Do we want extended vol info? */
3528 struct partList dummyPartList;
3536 if (as->parms[3].items)
3538 if (as->parms[4].items)
3542 if (as->parms[2].items)
3548 if (as->parms[5].items) {
3550 * We can't coexist with the fast flag.
3554 "vos: Can't use the -fast and -extended flags together\n");
3559 * We need to turn on ``long'' listings to get the full effect.
3561 wantExtendedInfo = 1;
3564 wantExtendedInfo = 0;
3565 if (as->parms[1].items) {
3566 apart = volutil_GetPartitionID(as->parms[1].items->data);
3568 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3569 as->parms[1].items->data);
3572 dummyPartList.partId[0] = apart;
3573 dummyPartList.partFlags[0] = PARTVALID;
3576 aserver = GetServer(as->parms[0].items->data);
3578 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3579 as->parms[0].items->data);
3584 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3586 PrintError("", code);
3589 "vos : partition %s does not exist on the server\n",
3590 as->parms[1].items->data);
3594 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3596 PrintDiagnostics("listvol", code);
3600 for (i = 0; i < cnt; i++) {
3601 if (dummyPartList.partFlags[i] & PARTVALID) {
3602 if (wantExtendedInfo)
3604 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3608 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3611 PrintDiagnostics("listvol", code);
3616 if (wantExtendedInfo) {
3617 origxInfoP = xInfoP;
3618 base = (char *)xInfoP;
3621 base = (char *)pntr;
3625 if (wantExtendedInfo)
3626 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3628 qsort(base, count, sizeof(volintInfo), CompareVolName);
3630 if (wantExtendedInfo)
3631 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3633 qsort(base, count, sizeof(volintInfo), CompareVolID);
3635 MapPartIdIntoName(dummyPartList.partId[i], pname);
3638 "Total number of volumes on server %s partition %s: %lu \n",
3639 as->parms[0].items->data, pname,
3640 (unsigned long)count);
3641 if (wantExtendedInfo) {
3642 #ifdef FULL_LISTVOL_SWITCH
3643 if (as->parms[6].items)
3644 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3645 count, int32list, fast, quiet);
3647 #endif /* FULL_LISTVOL_SWITCH */
3648 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3649 count, int32list, fast, quiet);
3652 xInfoP = (volintXInfo *) 0;
3654 #ifdef FULL_LISTVOL_SWITCH
3655 if (as->parms[6].items)
3656 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3659 #endif /* FULL_LISTVOL_SWITCH */
3660 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3661 count, int32list, fast, quiet);
3664 pntr = (volintInfo *) 0;
3673 register struct cmd_syndesc *as;
3675 afs_int32 pnum = 0, code; /* part name */
3681 if (as->parms[0].items) {
3682 tserver = GetServer(as->parms[0].items->data);
3684 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3685 as->parms[0].items->data);
3690 if (as->parms[1].items) {
3691 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3693 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3694 as->parms[1].items->data);
3697 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3699 PrintError("", code);
3702 "vos: partition %s does not exist on the server\n",
3703 as->parms[1].items->data);
3710 "The -partition option requires a -server option\n");
3715 if (as->parms[2].items) {
3716 /* Synchronize an individual volume */
3717 volname = as->parms[2].items->data;
3718 code = UV_SyncVolume(tserver, pnum, volname, flags);
3722 "Without a -volume option, the -server option is required\n");
3725 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3729 PrintDiagnostics("syncvldb", code);
3733 /* Print a summary of what we did */
3735 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3737 fprintf(STDOUT, "VLDB synchronized");
3739 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3742 MapPartIdIntoName(pnum, part);
3743 fprintf(STDOUT, " partition %s\n", part);
3745 fprintf(STDOUT, "\n");
3752 register struct cmd_syndesc *as;
3755 afs_int32 pnum, code; /* part name */
3760 tserver = GetServer(as->parms[0].items->data);
3762 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3763 as->parms[0].items->data);
3766 if (as->parms[1].items) {
3767 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3769 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3770 as->parms[1].items->data);
3773 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3775 PrintError("", code);
3778 "vos : partition %s does not exist on the server\n",
3779 as->parms[1].items->data);
3787 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3789 PrintDiagnostics("syncserv", code);
3793 MapPartIdIntoName(pnum, part);
3794 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3795 as->parms[0].items->data, part);
3797 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3798 as->parms[0].items->data);
3807 struct nvldbentry entry;
3810 /* The vlserver will handle names with the .readonly
3811 * and .backup extension as well as volume ids.
3813 vcode = VLDB_GetEntryByName(name, &entry);
3815 PrintError("", vcode);
3818 MapHostToNetwork(&entry);
3819 EnumerateEntry(&entry);
3821 /* Defect #3027: grubby check to handle locked volume.
3822 * If VLOP_ALLOPERS is set, the entry is locked.
3823 * Leave this routine as is, but put in correct check.
3825 if (entry.flags & VLOP_ALLOPERS)
3826 fprintf(STDOUT, " Volume is currently LOCKED \n");
3833 register struct cmd_syndesc *as;
3836 struct nvldbentry entry;
3837 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3839 if (as->parms[3].items) {
3840 /* force flag is on, use the other version */
3841 return NukeVolume(as);
3844 if (as->parms[4].items) {
3848 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3851 PrintError("", err);
3853 fprintf(STDERR, "vos: can't find volume '%s'\n",
3854 as->parms[2].items->data);
3857 part = volutil_GetPartitionID(as->parms[1].items->data);
3859 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3860 as->parms[1].items->data);
3863 server = GetServer(as->parms[0].items->data);
3865 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3866 as->parms[0].items->data);
3869 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3871 PrintError("", code);
3874 "vos : partition %s does not exist on the server\n",
3875 as->parms[1].items->data);
3878 code = VLDB_GetEntryByID(volid, -1, &entry);
3880 if (volid == entry.volumeId[RWVOL])
3881 backupid = entry.volumeId[BACKVOL];
3883 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3884 (unsigned long)volid);
3887 volintInfo *pntr = (volintInfo *) 0;
3890 code = UV_ListOneVolume(server, part, volid, &pntr);
3892 if (volid == pntr->parentID)
3893 backupid = pntr->backupID;
3899 code = UV_VolumeZap(server, part, backupid);
3901 PrintDiagnostics("zap", code);
3904 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3905 (unsigned long)backupid);
3908 code = UV_VolumeZap(server, part, volid);
3910 PrintDiagnostics("zap", code);
3913 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3920 register struct cmd_syndesc *as;
3923 afs_int32 server, code;
3924 transDebugInfo *pntr, *oldpntr;
3929 server = GetServer(as->parms[0].items->data);
3931 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3932 as->parms[0].items->data);
3935 code = UV_VolserStatus(server, &pntr, &count);
3937 PrintDiagnostics("status", code);
3942 fprintf(STDOUT, "No active transactions on %s\n",
3943 as->parms[0].items->data);
3945 fprintf(STDOUT, "Total transactions: %d\n", count);
3947 for (i = 0; i < count; i++) {
3948 /*print out the relevant info */
3949 fprintf(STDOUT, "--------------------------------------\n");
3950 fprintf(STDOUT, "transaction: %lu created: %s",
3951 (unsigned long)pntr->tid, vos_ctime( & pntr->time));
3952 if (pntr->returnCode) {
3953 fprintf(STDOUT, "returnCode: %lu\n",
3954 (unsigned long)pntr->returnCode);
3957 fprintf(STDOUT, "attachFlags: ");
3958 switch (pntr->iflags) {
3960 fprintf(STDOUT, "offline ");
3963 fprintf(STDOUT, "busy ");
3966 fprintf(STDOUT, "readonly ");
3969 fprintf(STDOUT, "create ");
3972 fprintf(STDOUT, "create volid ");
3975 fprintf(STDOUT, "\n");
3978 fprintf(STDOUT, "volumeStatus: ");
3979 switch (pntr->vflags) {
3980 case VTDeleteOnSalvage:
3981 fprintf(STDOUT, "deleteOnSalvage ");
3982 case VTOutOfService:
3983 fprintf(STDOUT, "outOfService ");
3985 fprintf(STDOUT, "deleted ");
3987 fprintf(STDOUT, "\n");
3990 fprintf(STDOUT, "transactionFlags: ");
3991 fprintf(STDOUT, "delete\n");
3993 MapPartIdIntoName(pntr->partition, pname);
3994 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
3995 (unsigned long)pntr->volid, pname, pntr->lastProcName);
3996 if (pntr->callValid) {
3998 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3999 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4000 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4003 fprintf(STDOUT, "--------------------------------------\n");
4004 fprintf(STDOUT, "\n");
4013 register struct cmd_syndesc *as;
4015 afs_int32 code1, code2, code;
4016 struct nvldbentry entry;
4018 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4020 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4021 as->parms[0].items->data);
4024 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4025 if ((!code1) && (!code2)) { /*the newname already exists */
4026 fprintf(STDERR, "vos: volume %s already exists\n",
4027 as->parms[1].items->data);
4031 if (code1 && code2) {
4032 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4033 as->parms[0].items->data, as->parms[1].items->data);
4036 if (!VolNameOK(as->parms[0].items->data)) {
4038 "Illegal volume name %s, should not end in .readonly or .backup\n",
4039 as->parms[0].items->data);
4042 if (!ISNAMEVALID(as->parms[1].items->data)) {
4044 "vos: the new volume name %s exceeds the size limit of %d\n",
4045 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4048 if (!VolNameOK(as->parms[1].items->data)) {
4050 "Illegal volume name %s, should not end in .readonly or .backup\n",
4051 as->parms[1].items->data);
4054 if (IsNumeric(as->parms[1].items->data)) {
4055 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4056 as->parms[1].items->data);
4059 MapHostToNetwork(&entry);
4061 UV_RenameVolume(&entry, as->parms[0].items->data,
4062 as->parms[1].items->data);
4064 PrintDiagnostics("rename", code);
4067 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4068 as->parms[1].items->data);
4072 GetVolumeInfo(volid, server, part, voltype, rentry)
4073 afs_int32 *server, volid, *part, *voltype;
4074 register struct nvldbentry *rentry;
4079 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4082 "Could not fetch the entry for volume %lu from VLDB \n",
4083 (unsigned long)volid);
4084 PrintError("", vcode);
4087 MapHostToNetwork(rentry);
4088 if (volid == rentry->volumeId[ROVOL]) {
4090 for (i = 0; i < rentry->nServers; i++) {
4091 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4092 && !(rentry->serverFlags[i] & RO_DONTUSE))
4097 "RO volume is not found in VLDB entry for volume %lu\n",
4098 (unsigned long)volid);
4102 *server = rentry->serverNumber[index];
4103 *part = rentry->serverPartition[index];
4107 index = Lp_GetRwIndex(rentry);
4110 "RW Volume is not found in VLDB entry for volume %lu\n",
4111 (unsigned long)volid);
4114 if (volid == rentry->volumeId[RWVOL]) {
4116 *server = rentry->serverNumber[index];
4117 *part = rentry->serverPartition[index];
4120 if (volid == rentry->volumeId[BACKVOL]) {
4122 *server = rentry->serverNumber[index];
4123 *part = rentry->serverPartition[index];
4127 "unexpected volume type for volume %lu\n",
4128 (unsigned long)volid);
4134 register struct cmd_syndesc *as;
4140 struct VldbListByAttributes attributes;
4141 nbulkentries arrayEntries;
4142 register struct nvldbentry *vllist;
4143 struct cmd_item *itp;
4146 char prefix[VOLSER_MAXVOLNAME + 1];
4148 afs_int32 totalBack = 0, totalFail = 0, err;
4150 if (as->parms[0].items) { /* -id */
4151 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4153 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4156 for (itp = as->parms[0].items; itp; itp = itp->next) {
4157 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4160 PrintError("", err);
4162 fprintf(STDERR, "vos: can't find volume '%s'\n",
4166 if (as->parms[4].items) { /* -noexecute */
4167 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4172 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
4174 fprintf(STDERR, "Could not delete entry for volume %s\n",
4177 "You must specify a RW volume name or ID "
4178 "(the entire VLDB entry will be deleted)\n");
4179 PrintError("", vcode);
4185 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4189 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4190 fprintf(STDERR, "You must specify an option\n");
4194 /* Zero out search attributes */
4195 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4197 if (as->parms[1].items) { /* -prefix */
4198 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4200 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4202 "You must provide -server with the -prefix argument\n");
4207 if (as->parms[2].items) { /* -server */
4209 aserver = GetServer(as->parms[2].items->data);
4211 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4212 as->parms[2].items->data);
4215 attributes.server = ntohl(aserver);
4216 attributes.Mask |= VLLIST_SERVER;
4219 if (as->parms[3].items) { /* -partition */
4220 if (!as->parms[2].items) {
4222 "You must provide -server with the -partition argument\n");
4225 apart = volutil_GetPartitionID(as->parms[3].items->data);
4227 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4228 as->parms[3].items->data);
4231 attributes.partition = apart;
4232 attributes.Mask |= VLLIST_PARTITION;
4235 /* Print status line of what we are doing */
4236 fprintf(STDOUT, "Deleting VLDB entries for ");
4237 if (as->parms[2].items) {
4238 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4240 if (as->parms[3].items) {
4242 MapPartIdIntoName(apart, pname);
4243 fprintf(STDOUT, "partition %s ", pname);
4246 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4248 fprintf(STDOUT, "\n");
4251 /* Get all the VLDB entries on a server and/or partition */
4252 memset(&arrayEntries, 0, sizeof(arrayEntries));
4253 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4255 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4256 PrintError("", vcode);
4260 /* Process each entry */
4261 for (j = 0; j < nentries; j++) {
4262 vllist = &arrayEntries.nbulkentries_val[j];
4264 /* It only deletes the RW volumes */
4265 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4268 "Omitting to delete %s due to prefix %s mismatch\n",
4269 vllist->name, prefix);
4276 if (as->parms[4].items) { /* -noexecute */
4277 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4283 /* Only matches the RW volume name */
4284 avolid = vllist->volumeId[RWVOL];
4285 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
4287 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4290 PrintError("", vcode);
4295 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4300 fprintf(STDOUT, "----------------------\n");
4302 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4303 (unsigned long)totalBack, (unsigned long)totalFail);
4304 if (arrayEntries.nbulkentries_val)
4305 free(arrayEntries.nbulkentries_val);
4311 CompareVldbEntryByName(p1, p2)
4314 struct nvldbentry *arg1, *arg2;
4316 arg1 = (struct nvldbentry *)p1;
4317 arg2 = (struct nvldbentry *)p2;
4318 return (strcmp(arg1->name, arg2->name));
4322 static int CompareVldbEntry(p1,p2)
4325 struct nvldbentry *arg1,*arg2;
4328 char comp1[100],comp2[100];
4329 char temp1[20],temp2[20];
4331 arg1 = (struct nvldbentry *)p1;
4332 arg2 = (struct nvldbentry *)p2;
4336 for(i = 0; i < arg1->nServers; i++)
4337 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4338 for(i = 0; i < arg2->nServers; i++)
4339 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4340 if(pos1 == -1 || pos2 == -1){
4344 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4345 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4346 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4347 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4348 strcat(comp1,temp1);
4349 strcat(comp2,temp2);
4350 strcat(comp1,arg1->name);
4351 strcat(comp1,arg2->name);
4352 return(strcmp(comp1,comp2));
4359 struct cmd_syndesc *as;
4362 afs_int32 aserver, code;
4364 struct VldbListByAttributes attributes;
4365 nbulkentries arrayEntries;
4366 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4367 afs_int32 centries, nentries = 0, tarraysize, parraysize;
4370 int quiet, sort, lock;
4371 afs_int32 thisindex, nextindex;
4376 attributes.Mask = 0;
4377 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4378 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4379 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4381 /* If the volume name is given, Use VolumeInfoCmd to look it up
4382 * and not ListAttributes.
4384 if (as->parms[0].items) {
4387 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4390 code = VolumeInfoCmd(as->parms[0].items->data);
4392 PrintError("", code);
4398 /* Server specified */
4399 if (as->parms[1].items) {
4400 aserver = GetServer(as->parms[1].items->data);
4402 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4403 as->parms[1].items->data);
4406 attributes.server = ntohl(aserver);
4407 attributes.Mask |= VLLIST_SERVER;
4410 /* Partition specified */
4411 if (as->parms[2].items) {
4412 apart = volutil_GetPartitionID(as->parms[2].items->data);
4414 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4415 as->parms[2].items->data);
4418 attributes.partition = apart;
4419 attributes.Mask |= VLLIST_PARTITION;
4423 attributes.Mask |= VLLIST_FLAG;
4424 attributes.flag = VLOP_ALLOPERS;
4427 /* Print header information */
4429 MapPartIdIntoName(apart, pname);
4430 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4431 (as->parms[1].items ? "server" : "all"),
4432 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4433 (as->parms[2].items ? " partition " : ""),
4434 (as->parms[2].items ? pname : ""),
4435 (lock ? "which are locked:" : ""));
4438 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4439 memset(&arrayEntries, 0, sizeof(arrayEntries));
4444 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4445 &arrayEntries, &nextindex);
4446 if (vcode == RXGEN_OPCODE) {
4447 /* Vlserver not running with ListAttributesN2. Fall back */
4449 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4453 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4454 PrintError("", vcode);
4457 nentries += centries;
4459 /* We don't sort, so just print the entries now */
4461 for (j = 0; j < centries; j++) { /* process each entry */
4462 vllist = &arrayEntries.nbulkentries_val[j];
4463 MapHostToNetwork(vllist);
4464 EnumerateEntry(vllist);
4466 if (vllist->flags & VLOP_ALLOPERS)
4467 fprintf(STDOUT, " Volume is currently LOCKED \n");
4471 /* So we sort. First we must collect all the entries and keep
4474 else if (centries > 0) {
4476 /* steal away the first bulk entries array */
4477 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4478 tarraysize = centries * sizeof(struct nvldbentry);
4479 arrayEntries.nbulkentries_val = 0;
4481 /* Grow the tarray to keep the extra entries */
4482 parraysize = (centries * sizeof(struct nvldbentry));
4484 (struct nvldbentry *)realloc(tarray,
4485 tarraysize + parraysize);
4488 "Could not allocate enough space for the VLDB entries\n");
4494 memcpy(((char *)tarray) + tarraysize,
4495 (char *)arrayEntries.nbulkentries_val, parraysize);
4496 tarraysize += parraysize;
4500 /* Free the bulk array */
4501 if (arrayEntries.nbulkentries_val) {
4502 free(arrayEntries.nbulkentries_val);
4503 arrayEntries.nbulkentries_val = 0;
4507 /* Here is where we now sort all the entries and print them */
4508 if (sort && (nentries > 0)) {
4509 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4510 CompareVldbEntryByName);
4511 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4512 MapHostToNetwork(vllist);
4513 EnumerateEntry(vllist);
4515 if (vllist->flags & VLOP_ALLOPERS)
4516 fprintf(STDOUT, " Volume is currently LOCKED \n");
4522 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4530 register struct cmd_syndesc *as;
4532 afs_int32 apart = 0, avolid;
4533 afs_int32 aserver = 0, code, aserver1, apart1;
4535 struct VldbListByAttributes attributes;
4536 nbulkentries arrayEntries;
4537 register struct nvldbentry *vllist;
4541 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4542 afs_int32 totalBack = 0;
4543 afs_int32 totalFail = 0;
4544 int previdx = -1, error, same;
4546 struct cmd_item *ti;
4550 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4551 attributes.Mask = 0;
4553 seenprefix = (as->parms[0].items ? 1 : 0);
4554 exclude = (as->parms[3].items ? 1 : 0);
4555 seenxprefix = (as->parms[4].items ? 1 : 0);
4556 noaction = (as->parms[5].items ? 1 : 0);
4558 if (as->parms[1].items) { /* -server */
4559 aserver = GetServer(as->parms[1].items->data);
4561 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4562 as->parms[1].items->data);
4565 attributes.server = ntohl(aserver);
4566 attributes.Mask |= VLLIST_SERVER;
4569 if (as->parms[2].items) { /* -partition */
4570 apart = volutil_GetPartitionID(as->parms[2].items->data);
4572 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4573 as->parms[2].items->data);
4576 attributes.partition = apart;
4577 attributes.Mask |= VLLIST_PARTITION;
4580 /* Check to make sure the prefix and xprefix expressions compile ok */
4582 for (ti = as->parms[0].items; ti; ti = ti->next) {
4583 if (strncmp(ti->data, "^", 1) == 0) {
4584 #ifdef HAVE_POSIX_REGEX
4588 code = regcomp(&re, ti->data, REG_NOSUB);
4590 regerror(code, &re, errbuf, sizeof errbuf);
4592 "Unrecognizable -prefix regular expression: '%s': %s\n",
4598 ccode = (char *)re_comp(ti->data);
4601 "Unrecognizable -prefix regular expression: '%s': %s\n",
4610 for (ti = as->parms[4].items; ti; ti = ti->next) {
4611 if (strncmp(ti->data, "^", 1) == 0) {
4612 #ifdef HAVE_POSIX_REGEX
4616 code = regcomp(&re, ti->data, REG_NOSUB);
4618 regerror(code, &re, errbuf, sizeof errbuf);
4620 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4626 ccode = (char *)re_comp(ti->data);
4629 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4638 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4639 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4641 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4642 PrintError("", vcode);
4646 if (as->parms[1].items || as->parms[2].items || verbose) {
4647 fprintf(STDOUT, "%s up volumes",
4648 (noaction ? "Would have backed" : "Backing"));
4650 if (as->parms[1].items) {
4651 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4652 } else if (as->parms[2].items) {
4653 fprintf(STDOUT, " for all servers");
4656 if (as->parms[2].items) {
4657 MapPartIdIntoName(apart, pname);
4658 fprintf(STDOUT, " partition %s", pname);
4661 if (seenprefix || (!seenprefix && seenxprefix)) {
4662 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4663 ex = (seenprefix ? exclude : !exclude);
4664 exp = (strncmp(ti->data, "^", 1) == 0);
4665 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4666 (exp ? "expression" : "prefix"), ti->data);
4667 for (ti = ti->next; ti; ti = ti->next) {
4668 exp = (strncmp(ti->data, "^", 1) == 0);
4669 printf(" %sor %s '%s'", (ex ? "n" : ""),
4670 (exp ? "expression" : "prefix"), ti->data);
4674 if (seenprefix && seenxprefix) {
4675 ti = as->parms[4].items;
4676 exp = (strncmp(ti->data, "^", 1) == 0);
4677 fprintf(STDOUT, " %swhich match %s '%s'",
4678 (exclude ? "adding those " : "removing those "),
4679 (exp ? "expression" : "prefix"), ti->data);
4680 for (ti = ti->next; ti; ti = ti->next) {
4681 exp = (strncmp(ti->data, "^", 1) == 0);
4682 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4686 fprintf(STDOUT, " .. ");
4688 fprintf(STDOUT, "\n");
4692 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4693 vllist = &arrayEntries.nbulkentries_val[j];
4696 for (ti = as->parms[0].items; ti; ti = ti->next) {
4697 if (strncmp(ti->data, "^", 1) == 0) {
4698 #ifdef HAVE_POSIX_REGEX
4702 /* XXX -- should just do the compile once! */
4703 code = regcomp(&re, ti->data, REG_NOSUB);
4705 regerror(code, &re, errbuf, sizeof errbuf);
4707 "Error in -prefix regular expression: '%s': %s\n",
4711 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4714 ccode = (char *)re_comp(ti->data);
4717 "Error in -prefix regular expression: '%s': %s\n",
4721 match = (re_exec(vllist->name) == 1);
4725 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4735 /* Without the -exclude flag: If it matches the prefix, then
4736 * check if we want to exclude any from xprefix.
4737 * With the -exclude flag: If it matches the prefix, then
4738 * check if we want to add any from xprefix.
4740 if (match && seenxprefix) {
4741 for (ti = as->parms[4].items; ti; ti = ti->next) {
4742 if (strncmp(ti->data, "^", 1) == 0) {
4743 #ifdef HAVE_POSIX_REGEX
4747 /* XXX -- should just do the compile once! */
4748 code = regcomp(&re, ti->data, REG_NOSUB);
4750 regerror(code, &re, errbuf, sizeof errbuf);
4752 "Error in -xprefix regular expression: '%s': %s\n",
4756 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4760 ccode = (char *)re_comp(ti->data);
4763 "Error in -xprefix regular expression: '%s': %s\n",
4767 if (re_exec(vllist->name) == 1) {
4773 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4783 match = !match; /* -exclude will reverse the match */
4785 continue; /* Skip if no match */
4787 /* Print list of volumes to backup */
4789 fprintf(STDOUT, " %s\n", vllist->name);
4793 if (!(vllist->flags & RW_EXISTS)) {
4796 "Omitting to backup %s since RW volume does not exist \n",
4798 fprintf(STDOUT, "\n");
4804 avolid = vllist->volumeId[RWVOL];
4805 MapHostToNetwork(vllist);
4806 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4807 if (aserver1 == -1 || apart1 == -1) {
4808 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4814 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4817 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4823 if ((aserver && !same) || (apart && (apart != apart1))) {
4826 "Omitting to backup %s since the RW is in a different location\n",
4832 time_t now = time(0);
4833 fprintf(STDOUT, "Creating backup volume for %s on %s",
4834 vllist->name, ctime(&now));
4838 code = UV_BackupVolume(aserver1, apart1, avolid);
4840 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4846 fprintf(STDOUT, "\n");
4848 } /* process each vldb entry */
4849 fprintf(STDOUT, "done\n");
4850 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4851 (unsigned long)totalBack, (unsigned long)totalFail);
4853 if (arrayEntries.nbulkentries_val)
4854 free(arrayEntries.nbulkentries_val);
4860 register struct cmd_syndesc *as;
4863 afs_int32 aserver, code;
4865 struct VldbListByAttributes attributes;
4866 nbulkentries arrayEntries;
4867 register struct nvldbentry *vllist;
4876 attributes.Mask = 0;
4878 if (as->parms[0].items) { /* server specified */
4879 aserver = GetServer(as->parms[0].items->data);
4881 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4882 as->parms[0].items->data);
4885 attributes.server = ntohl(aserver);
4886 attributes.Mask |= VLLIST_SERVER;
4888 if (as->parms[1].items) { /* partition specified */
4889 apart = volutil_GetPartitionID(as->parms[1].items->data);
4891 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4892 as->parms[1].items->data);
4895 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4897 PrintError("", code);
4900 "vos : partition %s does not exist on the server\n",
4901 as->parms[1].items->data);
4904 attributes.partition = apart;
4905 attributes.Mask |= VLLIST_PARTITION;
4907 attributes.flag = VLOP_ALLOPERS;
4908 attributes.Mask |= VLLIST_FLAG;
4909 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4910 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4912 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4913 PrintError("", vcode);
4916 for (j = 0; j < nentries; j++) { /* process each entry */
4917 vllist = &arrayEntries.nbulkentries_val[j];
4918 volid = vllist->volumeId[RWVOL];
4920 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4921 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4923 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4925 PrintError("", vcode);
4930 MapPartIdIntoName(apart, pname);
4933 "Could not lock %lu VLDB entries of %lu locked entries\n",
4934 (unsigned long)totalE, (unsigned long)nentries);
4936 if (as->parms[0].items) {
4938 "Unlocked all the VLDB entries for volumes on server %s ",
4939 as->parms[0].items->data);
4940 if (as->parms[1].items) {
4941 MapPartIdIntoName(apart, pname);
4942 fprintf(STDOUT, "partition %s\n", pname);
4944 fprintf(STDOUT, "\n");
4946 } else if (as->parms[1].items) {
4947 MapPartIdIntoName(apart, pname);
4949 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4954 if (arrayEntries.nbulkentries_val)
4955 free(arrayEntries.nbulkentries_val);
4960 PrintInt64Size(afs_uint64 in)
4962 register afs_uint32 hi, lo;
4963 register char * units;
4964 static char output[16];
4966 SplitInt64(in,hi,lo);
4970 } else if (!(hi & 0xFFFFFC00)) {
4972 lo = (hi << 22) | (lo >> 10);
4973 } else if (!(hi & 0xFFF00000)) {
4975 lo = (hi << 12) | (lo >> 20);
4976 } else if (!(hi & 0xC0000000)) {
4978 lo = (hi << 2) | (lo >> 30);
4983 sprintf(output,"%u %s", lo, units);
4989 register struct cmd_syndesc *as;
4992 afs_int32 aserver, code;
4994 struct diskPartition partition;
4995 struct partList dummyPartList;
4997 int printSummary=0, sumPartitions=0;
4998 afs_uint64 sumFree, sumStorage, tmp;
5001 ZeroInt64(sumStorage);
5003 aserver = GetServer(as->parms[0].items->data);
5005 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5006 as->parms[0].items->data);
5009 if (as->parms[1].items) {
5010 apart = volutil_GetPartitionID(as->parms[1].items->data);
5012 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5013 as->parms[1].items->data);
5016 dummyPartList.partId[0] = apart;
5017 dummyPartList.partFlags[0] = PARTVALID;
5020 if (as->parms[2].items) {
5024 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5026 PrintError("", code);
5029 "vos : partition %s does not exist on the server\n",
5030 as->parms[1].items->data);
5034 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5036 PrintDiagnostics("listpart", code);
5040 for (i = 0; i < cnt; i++) {
5041 if (dummyPartList.partFlags[i] & PARTVALID) {
5042 MapPartIdIntoName(dummyPartList.partId[i], pname);
5043 code = UV_PartitionInfo(aserver, pname, &partition);
5045 fprintf(STDERR, "Could not get information on partition %s\n",
5047 PrintError("", code);
5051 "Free space on partition %s: %d K blocks out of total %d\n",
5052 pname, partition.free, partition.minFree);
5054 FillInt64(tmp,0,partition.free);
5055 AddUInt64(sumFree,tmp,&sumFree);
5056 FillInt64(tmp,0,partition.minFree);
5057 AddUInt64(sumStorage,tmp,&sumStorage);
5062 "Summary: %s free out of ",
5063 PrintInt64Size(sumFree));
5065 "%s on %d partitions\n",
5066 PrintInt64Size(sumStorage),
5074 register struct cmd_syndesc *as;
5077 afs_int32 ip1, ip2, vcode;
5080 ip1 = GetServer(as->parms[0].items->data);
5082 fprintf(STDERR, "vos: invalid host address\n");
5086 if ((as->parms[1].items && as->parms[2].items)
5087 || (!as->parms[1].items && !as->parms[2].items)) {
5089 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5093 if (as->parms[1].items) {
5094 ip2 = GetServer(as->parms[1].items->data);
5096 fprintf(STDERR, "vos: invalid host address\n");
5100 /* Play a trick here. If we are removing an address, ip1 will be -1
5101 * and ip2 will be the original address. This switch prevents an
5102 * older revision vlserver from removing the IP address.
5109 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
5112 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5113 as->parms[0].items->data);
5114 if (vcode == VL_NOENT) {
5116 "vlserver does not support the remove flag or ");
5119 fprintf(STDERR, "Could not change server %s to server %s\n",
5120 as->parms[0].items->data, as->parms[1].items->data);
5122 PrintError("", vcode);
5127 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5128 as->parms[0].items->data);
5130 fprintf(STDOUT, "Changed server %s to server %s\n",
5131 as->parms[0].items->data, as->parms[1].items->data);
5137 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
5138 int print, int noresolve)
5142 struct VLCallBack vlcb;
5145 ListAddrByAttributes m_attrs;
5146 afs_int32 m_nentries, *m_addrp;
5147 afs_int32 base, index;
5151 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5152 printf("UUID: %s\n", buf);
5155 /* print out the list of all the server */
5156 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5157 for (i = 0; i < nentries; i++, addrp++) {
5158 /* If it is a multihomed address, then we will need to
5159 * get the addresses for this multihomed server from
5160 * the vlserver and print them.
5162 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5163 /* Get the list of multihomed fileservers */
5164 base = (*addrp >> 16) & 0xff;
5165 index = (*addrp) & 0xffff;
5167 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5168 && (index <= VL_MHSRV_PERBLK)) {
5169 m_attrs.Mask = VLADDR_INDEX;
5170 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5172 m_addrs.bulkaddrs_val = 0;
5173 m_addrs.bulkaddrs_len = 0;
5175 ubik_Call(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5176 &vlcb, &m_nentries, &m_addrs);
5179 "vos: could not list the multi-homed server addresses\n");
5180 PrintError("", vcode);
5183 /* Print the list */
5184 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5185 for (j = 0; j < m_nentries; j++, m_addrp++) {
5186 *m_addrp = htonl(*m_addrp);
5189 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5191 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5195 printf("<unknown>\n");
5204 /* Otherwise, it is a non-multihomed entry and contains
5205 * the IP address of the server - print it.
5207 *addrp = htonl(*addrp);
5210 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5212 printf("%s\n", hostutil_GetNameByINet(*addrp));
5224 register struct cmd_syndesc *as;
5227 afs_int32 i, noresolve = 0, printuuid = 0;
5228 struct VLCallBack vlcb;
5231 ListAddrByAttributes m_attrs;
5232 afsUUID m_uuid, askuuid;
5233 afs_int32 m_nentries;
5235 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5236 m_attrs.Mask = VLADDR_INDEX;
5238 memset(&m_addrs, 0, sizeof(bulkaddrs));
5239 memset(&askuuid, 0, sizeof(afsUUID));
5240 if (as->parms[0].items) {
5242 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5243 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5244 as->parms[0].items->data);
5247 m_attrs.Mask = VLADDR_UUID;
5248 m_attrs.uuid = askuuid;
5250 if (as->parms[1].items) {
5254 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5256 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5257 as->parms[1].items->data);
5260 memcpy(&saddr, he->h_addr, 4);
5261 m_attrs.Mask = VLADDR_IPADDR;
5262 m_attrs.ipaddr = ntohl(saddr);
5264 if (as->parms[2].items) {
5267 if (as->parms[3].items) {
5271 m_addrs.bulkaddrs_val = 0;
5272 m_addrs.bulkaddrs_len = 0;
5275 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries,
5278 fprintf(STDERR, "vos: could not list the server addresses\n");
5279 PrintError("", vcode);
5284 m_addrs.bulkaddrs_val = 0;
5285 m_addrs.bulkaddrs_len = 0;
5291 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5292 &vlcb, &m_nentries, &m_addrs);
5294 if (vcode == VL_NOENT) {
5295 if (m_attrs.Mask == VLADDR_UUID) {
5296 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5297 as->parms[0].items->data);
5299 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5300 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5301 as->parms[1].items->data, m_attrs.ipaddr);
5310 if (vcode == VL_INDEXERANGE) {
5315 fprintf(STDERR, "vos: could not list the server addresses\n");
5316 PrintError("", vcode);
5320 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
5323 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5332 register struct cmd_syndesc *as;
5335 afs_int32 avolid, vcode, err;
5337 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5340 PrintError("", err);
5342 fprintf(STDERR, "vos: can't find volume '%s'\n",
5343 as->parms[0].items->data);
5346 vcode = ubik_Call(VL_SetLock, cstruct, 0, avolid, -1, VLOP_DELETE);
5348 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5349 as->parms[0].items->data);
5350 PrintError("", vcode);
5353 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5354 as->parms[0].items->data);
5360 register struct cmd_syndesc *as;
5363 afs_int32 partition = -1;
5364 afs_int32 server, volid, code, i, same;
5365 struct nvldbentry entry, storeEntry;
5368 afs_int32 rwserver = 0;
5369 afs_int32 rwpartition;
5371 afs_int32 roserver = 0;
5372 afs_int32 ropartition;
5374 struct rx_connection *aconn;
5377 server = GetServer(as->parms[0].items->data);
5379 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5380 as->parms[0].items->data);
5383 partition = volutil_GetPartitionID(as->parms[1].items->data);
5384 if (partition < 0) {
5385 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5386 as->parms[1].items->data);
5389 if (!IsPartValid(partition, server, &code)) {
5391 PrintError("", code);
5394 "vos : partition %s does not exist on the server\n",
5395 as->parms[1].items->data);
5398 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5401 PrintError("", code);
5403 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5404 as->parms[0].items->data);
5407 if (as->parms[3].items)
5410 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5413 "Could not fetch the entry for volume %lu from VLDB\n",
5414 (unsigned long)volid);
5415 PrintError("convertROtoRW", code);
5419 /* use RO volid even if user specified RW or BK volid */
5421 if (volid != entry.volumeId[ROVOL])
5422 volid = entry.volumeId[ROVOL];
5424 MapHostToNetwork(&entry);
5425 for (i = 0; i < entry.nServers; i++) {
5426 if (entry.serverFlags[i] & ITSRWVOL) {
5428 rwserver = entry.serverNumber[i];
5429 rwpartition = entry.serverPartition[i];
5431 if (entry.serverFlags[i] & ITSROVOL) {
5432 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5435 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5441 roserver = entry.serverNumber[i];
5442 ropartition = entry.serverPartition[i];
5448 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5450 if (ropartition != partition) {
5452 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5453 ropartition, partition);
5458 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5459 hostutil_GetNameByINet(rwserver),
5460 volutil_PartitionName(rwpartition));
5462 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5464 while (!(dc == EOF || dc == '\n'))
5465 dc = getchar(); /* goto end of line */
5466 if ((c != 'y') && (c != 'Y')) {
5467 fprintf(STDERR, "aborted.\n");
5474 ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5476 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5477 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5480 "Converting RO volume %lu to RW volume failed with code %d\n",
5481 (unsigned long)volid, code);
5482 PrintError("convertROtoRW ", code);
5485 entry.serverFlags[roindex] = ITSRWVOL;
5486 entry.flags |= RW_EXISTS;
5487 entry.flags &= ~BACK_EXISTS;
5490 if (rwindex != entry.nServers) {
5491 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5492 entry.serverPartition[rwindex] =
5493 entry.serverPartition[entry.nServers];
5494 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5495 entry.serverNumber[entry.nServers] = 0;
5496 entry.serverPartition[entry.nServers] = 0;
5497 entry.serverFlags[entry.nServers] = 0;
5500 entry.flags &= ~RO_EXISTS;
5501 for (i = 0; i < entry.nServers; i++) {
5502 if (entry.serverFlags[i] & ITSROVOL) {
5503 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5504 entry.flags |= RO_EXISTS;
5507 MapNetworkToHost(&entry, &storeEntry);
5509 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5510 (LOCKREL_OPCODE | LOCKREL_AFSID |
5511 LOCKREL_TIMESTAMP));
5514 "Warning: volume converted, but vldb update failed with code %d!\n",
5517 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5519 PrintDiagnostics("unlock", vcode);
5526 register struct cmd_syndesc *as;
5528 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
5529 struct nvldbentry entry;
5530 volintSize vol_size;
5532 rx_SetRxDeadTime(60 * 10);
5533 for (i = 0; i < MAXSERVERS; i++) {
5534 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5537 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5538 if (rxConn->service)
5539 rxConn->service->connDeadTime = rx_connDeadTime;
5542 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5545 PrintError("", err);
5547 fprintf(STDERR, "vos: can't find volume '%s'\n",
5548 as->parms[0].items->data);
5552 if (as->parms[1].items || as->parms[2].items) {
5553 if (!as->parms[1].items || !as->parms[2].items) {
5555 "Must specify both -server and -partition options\n");
5558 aserver = GetServer(as->parms[2].items->data);
5560 fprintf(STDERR, "Invalid server name\n");
5563 apart = volutil_GetPartitionID(as->parms[1].items->data);
5565 fprintf(STDERR, "Invalid partition name\n");
5569 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5576 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5577 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5579 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5580 as->parms[1].items->data, code);
5585 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5587 if (as->parms[3].items) { /* do the dump estimate */
5588 #ifdef AFS_64BIT_ENV
5589 vol_size.dump_size = 0;
5591 FillInt64(vol_size.dump_size,0, 1);
5593 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5595 PrintDiagnostics("size", code);
5598 /* presumably the size info is now gathered in pntr */
5599 /* now we display it */
5601 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5609 PrintDiagnostics(astring, acode)
5613 if (acode == EACCES) {
5615 "You are not authorized to perform the 'vos %s' command (%d)\n",
5618 fprintf(STDERR, "Error in vos %s command.\n", astring);
5619 PrintError("", acode);
5626 MyBeforeProc(as, arock)
5627 struct cmd_syndesc *as;
5630 register char *tcell;
5631 register afs_int32 code;
5632 register afs_int32 sauth;
5634 /* Initialize the ubik_client connection */
5635 rx_SetRxDeadTime(90);
5636 cstruct = (struct ubik_client *)0;
5640 if (as->parms[12].items) /* if -cell specified */
5641 tcell = as->parms[12].items->data;
5642 if (as->parms[14].items) /* -serverauth specified */
5644 if (as->parms[16].items) /* -crypt specified */
5647 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5648 &cstruct, UV_SetSecurity))) {
5649 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5650 (unsigned long)code);
5654 if (as->parms[15].items) /* -verbose flag set */
5664 /* this sucks but it works for now.
5669 #include "AFS_component_version_number.c"
5675 register afs_int32 code;
5677 register struct cmd_syndesc *ts;
5679 #ifdef AFS_AIX32_ENV
5681 * The following signal action for AIX is necessary so that in case of a
5682 * crash (i.e. core is generated) we can include the user's data section
5683 * in the core dump. Unfortunately, by default, only a partial core is
5684 * generated which, in many cases, isn't too useful.
5686 struct sigaction nsa;
5688 sigemptyset(&nsa.sa_mask);
5689 nsa.sa_handler = SIG_DFL;
5690 nsa.sa_flags = SA_FULLDUMP;
5691 sigaction(SIGSEGV, &nsa, NULL);
5694 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5696 cmd_SetBeforeProc(MyBeforeProc, NULL);
5698 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
5699 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5700 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5701 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5702 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5703 "initial quota (KB)");
5705 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5709 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
5710 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5711 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5712 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5716 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
5717 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5718 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5719 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5720 "partition name on source");
5721 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5722 "machine name on destination");
5723 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5724 "partition name on destination");
5725 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5726 "copy live volume without cloning");
5729 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
5730 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5731 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5732 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5733 "partition name on source");
5734 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5735 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5736 "machine name on destination");
5737 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5738 "partition name on destination");
5739 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5740 "leave new volume offline");
5741 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5742 "make new volume read-only");
5743 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5744 "copy live volume without cloning");
5747 ts = cmd_CreateSyntax("shadow", ShadowVolume, 0,
5748 "make or update a shadow volume");
5749 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5750 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5751 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5752 "partition name on source");
5753 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5754 "machine name on destination");
5755 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5756 "partition name on destination");
5757 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5758 "volume name on destination");
5759 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5760 "volume ID on destination");
5761 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5762 "leave shadow volume offline");
5763 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5764 "make shadow volume read-only");
5765 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5766 "copy live volume without cloning");
5767 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5768 "do incremental update if target exists");
5771 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
5772 "make backup of a volume");
5773 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5776 ts = cmd_CreateSyntax("clone", CloneVolume, 0,
5777 "make clone of a volume");
5778 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5779 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5780 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5781 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5782 "volume name on destination");
5783 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5784 "volume ID on destination");
5785 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5786 "leave clone volume offline");
5787 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5788 "make clone volume read-only, not readwrite");
5791 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
5792 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5793 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5794 "force a complete release");
5797 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
5798 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5799 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5800 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5801 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5802 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5803 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5804 "dump a clone of the volume");
5807 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
5808 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5809 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5810 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5811 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5812 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5813 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5814 "abort | full | incremental");
5815 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5816 "leave restored volume offline");
5817 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5818 "make restored volume read-only");
5819 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
5820 "dump | keep | new");
5821 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
5822 "dump | keep | new");
5825 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
5826 "release lock on VLDB entry for a volume");
5827 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5830 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
5831 "change an RW volume's location in the VLDB");
5832 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5833 "machine name for new location");
5834 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5835 "partition name for new location");
5836 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5839 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5840 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5841 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5842 "partition name for new site");
5843 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5846 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5847 "remove a replication site");
5848 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5849 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5850 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5853 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5854 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5857 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5858 "list volumes on server (bypass VLDB)");
5859 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5860 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5861 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5862 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5863 "list all normal volume fields");
5864 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5865 "generate minimal information");
5866 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5867 "list extended volume fields");
5868 #ifdef FULL_LISTVOL_SWITCH
5869 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5870 "machine readable format");
5871 #endif /* FULL_LISTVOL_SWITCH */
5874 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5875 "synchronize VLDB with server");
5876 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5877 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5878 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5881 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5882 "synchronize server with VLDB");
5883 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5884 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5887 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5888 "everything about the volume");
5889 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5890 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5891 "list extended volume fields");
5892 #ifdef FULL_LISTVOL_SWITCH
5893 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5894 "machine readable format");
5895 #endif /* FULL_LISTVOL_SWITCH */
5897 cmd_CreateAlias(ts, "volinfo");
5899 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5900 "change volume info fields");
5901 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5902 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5903 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5906 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5907 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5908 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5909 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5910 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5911 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5914 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5915 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5916 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5917 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5920 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5921 "delete the volume, don't bother with VLDB");
5922 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5923 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5924 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5925 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5926 "force deletion of bad volumes");
5927 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5928 "also delete backup volume if one is found");
5931 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5932 "report on volser status");
5933 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5936 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5937 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5938 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5941 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5942 "list volumes in the VLDB");
5943 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5944 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5945 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5946 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5947 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5948 "generate minimal information");
5949 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5950 "do not alphabetically sort the volume names");
5953 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5954 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5955 "common prefix on volume(s)");
5956 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5957 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5958 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5959 "exclude common prefix volumes");
5960 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5961 "negative prefix on volume(s)");
5962 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5965 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5966 "delete VLDB entry for a volume");
5967 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5968 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5969 "prefix of the volume whose VLDB entry is to be deleted");
5970 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5971 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5972 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
5976 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
5977 "list partition information");
5978 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5979 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5980 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
5981 "print storage summary");
5984 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
5985 "unlock all the locked entries in the VLDB");
5986 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5987 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5990 ts = cmd_CreateSyntax("lock", LockEntry, 0,
5991 "lock VLDB entry for a volume");
5992 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5995 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
5996 "change the IP address of a file server");
5997 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
5998 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
5999 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6000 "remove the IP address from the VLDB");
6003 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
6004 "list the IP address of all file servers registered in the VLDB");
6005 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6006 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6007 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
6008 "don't resolve addresses");
6009 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6010 "print uuid of hosts");
6013 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
6014 "convert a RO volume into a RW volume (after loss of old RW volume)");
6015 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6016 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6017 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6018 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6021 ts = cmd_CreateSyntax("size", Sizes, 0,
6022 "obtain various sizes of the volume.");
6023 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6024 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6025 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6026 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6027 "Obtain the size of the dump");
6028 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6031 code = cmd_Dispatch(argc, argv);
6033 /* Shut down the ubik_client and rx connections */
6035 (void)ubik_ClientDestroy(cstruct);
6041 exit((code ? -1 : 0));