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>
49 #include <afs/cellconfig.h>
51 #include <afs/afsutil.h>
53 #include <afs/afsint.h>
58 #include <afs/ihandle.h>
59 #include <afs/vnode.h>
60 #include <afs/volume.h>
67 #include "volser_prototypes.h"
69 #ifdef HAVE_POSIX_REGEX
83 #define COMMONPARMS cmd_Seek(ts, 12);\
84 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
85 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
86 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
87 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
88 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
90 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
94 struct rx_connection *tconn;
96 extern struct ubik_client *cstruct;
99 static struct tqHead busyHead, notokHead;
102 qInit(struct tqHead *ahead)
104 memset((char *)ahead, 0, sizeof(struct tqHead));
110 qPut(struct tqHead *ahead, afs_int32 volid)
114 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
115 elem->next = ahead->next;
123 qGet(struct tqHead *ahead, afs_int32 *volid)
127 if (ahead->count <= 0)
129 *volid = ahead->next->volid;
131 ahead->next = tmp->next;
137 /* returns 1 if <filename> exists else 0 */
139 FileExists(char *filename)
145 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
149 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
157 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
159 VolNameOK(char *name)
164 total = strlen(name);
165 if (!strcmp(&name[total - 9], ".readonly")) {
167 } else if (!strcmp(&name[total - 7], ".backup")) {
174 /* return 1 if name is a number else 0 */
176 IsNumeric(char *name)
184 for (i = 0; i < len; i++) {
185 if (*ptr < '0' || *ptr > '9') {
197 * Parse a server name/address and return the address in HOST BYTE order
200 GetServer(char *aname)
202 register struct hostent *th;
205 register afs_int32 code;
206 char hostname[MAXHOSTCHARS];
208 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
210 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
211 addr = ntohl(addr); /* convert to host order */
213 th = gethostbyname(aname);
216 memcpy(&addr, th->h_addr, sizeof(addr));
219 if (addr == htonl(0x7f000001)) { /* local host */
220 code = gethostname(hostname, MAXHOSTCHARS);
223 th = gethostbyname(hostname); /* returns host byte order */
226 memcpy(&addr, th->h_addr, sizeof(addr));
233 GetVolumeType(char *aname)
236 if (!strcmp(aname, "ro"))
238 else if (!strcmp(aname, "rw"))
240 else if (!strcmp(aname, "bk"))
247 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
249 struct partList dummyPartList;
255 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
258 for (i = 0; i < cnt; i++) {
259 if (dummyPartList.partFlags[i] & PARTVALID)
260 if (dummyPartList.partId[i] == partId)
268 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
269 * associated with <call> */
271 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
273 char *buffer = (char *)0;
278 buffer = (char *)malloc(blksize);
280 fprintf(STDERR, "malloc failed\n");
284 while (!error && !done) {
285 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
288 FD_SET((int)(ufd->handle), &in);
289 /* don't timeout if read blocks */
290 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
292 error = USD_READ(ufd, buffer, blksize, &nbytes);
294 fprintf(STDERR, "File system read failed\n");
301 if (rx_Write(call, buffer, nbytes) != nbytes) {
311 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
312 * writes it out to the volume. */
314 WriteData(struct rx_call *call, char *rock)
319 afs_int32 error, code;
321 afs_hyper_t filesize, currOffset;
328 if (!filename || !*filename) {
329 usd_StandardInput(&ufd);
333 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
336 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
339 fprintf(STDERR, "Could not access file '%s'\n", filename);
343 /* test if we have a valid dump */
344 hset64(filesize, 0, 0);
345 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
346 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
347 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
348 USD_READ(ufd, &buffer, sizeof(afs_uint32), &got);
349 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
350 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
354 /* rewind, we are done */
355 hset64(filesize, 0, 0);
356 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
358 code = SendFile(ufd, call, blksize);
365 code = USD_CLOSE(ufd);
367 fprintf(STDERR, "Could not close dump file %s\n",
368 (filename && *filename) ? filename : "STDOUT");
376 /* Receive data from <call> stream into file associated
377 * with <fd> <blksize>
380 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
384 afs_uint32 bytesleft, w;
387 buffer = (char *)malloc(blksize);
389 fprintf(STDERR, "memory allocation failed\n");
393 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
394 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
395 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
398 FD_SET((int)(ufd->handle), &out);
399 /* don't timeout if write blocks */
400 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
403 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
405 fprintf(STDERR, "File system write failed\n");
418 DumpFunction(struct rx_call *call, char *filename)
420 usd_handle_t ufd; /* default is to stdout */
421 afs_int32 error = 0, code;
426 /* Open the output file */
427 if (!filename || !*filename) {
428 usd_StandardOutput(&ufd);
433 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
437 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
440 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
443 fprintf(STDERR, "Could not create file '%s'\n", filename);
444 ERROR_EXIT(VOLSERBADOP);
448 code = ReceiveFile(ufd, call, blksize);
453 /* Close the output file */
455 code = USD_CLOSE(ufd);
457 fprintf(STDERR, "Could not close dump file %s\n",
458 (filename && *filename) ? filename : "STDIN");
469 vos_ctime(afs_int32 *timep)
475 #define vos_ctime ctime
479 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
482 afs_int32 server, part;
483 int *totalOK, *totalNotOK, *totalBusy;
484 int fast, longlist, disp;
489 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
490 } else if (longlist) {
491 if (pntr->status == VOK) {
492 fprintf(STDOUT, "%-32s ", pntr->name);
493 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
495 fprintf(STDOUT, "RW ");
497 fprintf(STDOUT, "RO ");
499 fprintf(STDOUT, "BK ");
500 fprintf(STDOUT, "%10d K ", pntr->size);
501 if (pntr->inUse == 1) {
502 fprintf(STDOUT, "On-line");
505 fprintf(STDOUT, "Off-line");
508 if (pntr->needsSalvaged == 1)
509 fprintf(STDOUT, "**needs salvage**");
510 fprintf(STDOUT, "\n");
511 MapPartIdIntoName(part, pname);
512 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
514 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
515 (unsigned long)pntr->parentID,
516 (unsigned long)pntr->cloneID,
517 (unsigned long)pntr->backupID);
518 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
519 fprintf(STDOUT, " Creation %s",
520 vos_ctime(& pntr->creationDate));
521 #ifdef FULL_LISTVOL_SWITCH
522 fprintf(STDOUT, " Copy %s",
523 vos_ctime( & pntr->copyDate));
524 if (!pntr->backupDate)
525 fprintf(STDOUT, " Backup Never\n");
527 fprintf(STDOUT, " Backup %s",
528 vos_ctime( & pntr->backupDate));
529 if (pntr->accessDate)
530 fprintf(STDOUT, " Last Access %s",
531 vos_ctime( & pntr->accessDate));
533 if (!pntr->updateDate)
534 fprintf(STDOUT, " Last Update Never\n");
536 fprintf(STDOUT, " Last Update %s",
537 vos_ctime( & pntr->updateDate));
539 " %d accesses in the past day (i.e., vnode references)\n",
542 } else if (pntr->status == VBUSY) {
544 qPut(&busyHead, pntr->volid);
546 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
547 (unsigned long)pntr->volid);
550 qPut(¬okHead, pntr->volid);
552 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
553 (unsigned long)pntr->volid);
555 fprintf(STDOUT, "\n");
556 } else { /* default listing */
557 if (pntr->status == VOK) {
558 fprintf(STDOUT, "%-32s ", pntr->name);
559 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
561 fprintf(STDOUT, "RW ");
563 fprintf(STDOUT, "RO ");
565 fprintf(STDOUT, "BK ");
566 fprintf(STDOUT, "%10d K ", pntr->size);
567 if (pntr->inUse == 1) {
568 fprintf(STDOUT, "On-line");
571 fprintf(STDOUT, "Off-line");
574 if (pntr->needsSalvaged == 1)
575 fprintf(STDOUT, "**needs salvage**");
576 fprintf(STDOUT, "\n");
577 } else if (pntr->status == VBUSY) {
579 qPut(&busyHead, pntr->volid);
581 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
582 (unsigned long)pntr->volid);
585 qPut(¬okHead, pntr->volid);
587 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
588 (unsigned long)pntr->volid);
593 /*------------------------------------------------------------------------
594 * PRIVATE XDisplayFormat
597 * Display the contents of one extended volume info structure.
600 * a_xInfoP : Ptr to extended volume info struct to print.
601 * a_servID : Server ID to print.
602 * a_partID : Partition ID to print.
603 * a_totalOKP : Ptr to total-OK counter.
604 * a_totalNotOKP : Ptr to total-screwed counter.
605 * a_totalBusyP : Ptr to total-busy counter.
606 * a_fast : Fast listing?
607 * a_int32 : Int32 listing?
608 * a_showProblems : Show volume problems?
614 * Nothing interesting.
618 *------------------------------------------------------------------------*/
621 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
622 a_totalBusyP, a_fast, a_int32, a_showProblems)
623 volintXInfo *a_xInfoP;
633 { /*XDisplayFormat */
641 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
642 } else if (a_int32) {
644 * Fully-detailed listing.
646 if (a_xInfoP->status == VOK) {
648 * Volume's status is OK - all the fields are valid.
650 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
651 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
652 if (a_xInfoP->type == 0)
653 fprintf(STDOUT, "RW ");
654 if (a_xInfoP->type == 1)
655 fprintf(STDOUT, "RO ");
656 if (a_xInfoP->type == 2)
657 fprintf(STDOUT, "BK ");
658 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
659 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
660 if (a_xInfoP->inUse == 1) {
661 fprintf(STDOUT, "On-line");
664 fprintf(STDOUT, "Off-line");
667 fprintf(STDOUT, "\n");
668 MapPartIdIntoName(a_partID, pname);
669 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
671 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
672 (unsigned long)a_xInfoP->parentID,
673 (unsigned long)a_xInfoP->cloneID,
674 (unsigned long)a_xInfoP->backupID);
675 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
676 fprintf(STDOUT, " Creation %s",
677 vos_ctime( & a_xInfoP->creationDate));
678 #ifdef FULL_LISTVOL_SWITCH
679 fprintf(STDOUT, " Copy %s",
680 vos_ctime( & a_xInfoP->copyDate));
681 if (!a_xInfoP->backupDate)
682 fprintf(STDOUT, " Backup Never\n");
684 fprintf(STDOUT, " Backup %s",
685 vos_ctime( & a_xInfoP->backupDate));
686 if (a_xInfoP->accessDate)
687 fprintf(STDOUT, " Last Access %s",
688 vos_ctime( & a_xInfoP->accessDate));
690 if (!a_xInfoP->updateDate)
691 fprintf(STDOUT, " Last Update Never\n");
693 fprintf(STDOUT, " Last Update %s",
694 vos_ctime( & a_xInfoP->updateDate));
696 " %d accesses in the past day (i.e., vnode references)\n",
701 * Print all the read/write and authorship stats.
703 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
705 " |-------------------------------------------|\n");
707 " | Same Network | Diff Network |\n");
709 " |----------|----------|----------|----------|\n");
711 " | Total | Auth | Total | Auth |\n");
713 " |----------|----------|----------|----------|\n");
714 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
715 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
716 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
717 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
718 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
719 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
720 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
721 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
722 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
723 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
725 " |-------------------------------------------|\n\n");
728 " Writes Affecting Authorship\n");
730 " |-------------------------------------------|\n");
732 " | File Authorship | Directory Authorship|\n");
734 " |----------|----------|----------|----------|\n");
736 " | Same | Diff | Same | Diff |\n");
738 " |----------|----------|----------|----------|\n");
739 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
740 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
741 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
742 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
743 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
744 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
745 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
746 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
747 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
748 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
749 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
750 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
751 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
752 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
753 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
754 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
755 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
756 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
757 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
758 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
759 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
760 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
761 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
762 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
763 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
764 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
765 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
766 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
767 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
768 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
770 " |-------------------------------------------|\n");
771 } /*Volume status OK */
772 else if (a_xInfoP->status == VBUSY) {
774 qPut(&busyHead, a_xInfoP->volid);
776 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
777 (unsigned long)a_xInfoP->volid);
781 qPut(¬okHead, a_xInfoP->volid);
783 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
784 (unsigned long)a_xInfoP->volid);
785 } /*Screwed volume */
786 fprintf(STDOUT, "\n");
792 if (a_xInfoP->status == VOK) {
793 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
794 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
795 if (a_xInfoP->type == 0)
796 fprintf(STDOUT, "RW ");
797 if (a_xInfoP->type == 1)
798 fprintf(STDOUT, "RO ");
799 if (a_xInfoP->type == 2)
800 fprintf(STDOUT, "BK ");
801 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
802 if (a_xInfoP->inUse == 1) {
803 fprintf(STDOUT, "On-line");
806 fprintf(STDOUT, "Off-line");
809 fprintf(STDOUT, "\n");
811 else if (a_xInfoP->status == VBUSY) {
813 qPut(&busyHead, a_xInfoP->volid);
815 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
816 (unsigned long)a_xInfoP->volid);
820 qPut(¬okHead, a_xInfoP->volid);
822 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
823 (unsigned long)a_xInfoP->volid);
824 } /*Screwed volume */
825 } /*Default listing */
826 } /*XDisplayFormat */
828 #ifdef FULL_LISTVOL_SWITCH
829 /*------------------------------------------------------------------------
830 * PRIVATE XDisplayFormat2
833 * Display the formated contents of one extended volume info structure.
836 * a_xInfoP : Ptr to extended volume info struct to print.
837 * a_servID : Server ID to print.
838 * a_partID : Partition ID to print.
839 * a_totalOKP : Ptr to total-OK counter.
840 * a_totalNotOKP : Ptr to total-screwed counter.
841 * a_totalBusyP : Ptr to total-busy counter.
842 * a_fast : Fast listing?
843 * a_int32 : Int32 listing?
844 * a_showProblems : Show volume problems?
850 * Nothing interesting.
854 *------------------------------------------------------------------------*/
857 XDisplayFormat2(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
858 a_totalBusyP, a_fast, a_int32, a_showProblems)
859 volintXInfo *a_xInfoP;
869 { /*XDisplayFormat */
874 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
875 } else if (a_int32) {
877 * Fully-detailed listing.
879 if (a_xInfoP->status == VOK) {
881 * Volume's status is OK - all the fields are valid.
884 static long server_cache = -1, partition_cache = -1;
885 static char hostname[256], address[32], pname[16];
886 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
887 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
889 if (a_servID != server_cache) {
893 strcpy(hostname, hostutil_GetNameByINet(a_servID));
894 strcpy(address, inet_ntoa(s));
895 server_cache = a_servID;
897 if (a_partID != partition_cache) {
898 MapPartIdIntoName(a_partID, pname);
899 partition_cache = a_partID;
902 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
903 fprintf(STDOUT, "id\t\t%lu\n", a_xInfoP->volid);
904 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
905 fprintf(STDOUT, "part\t\t%s\n", pname);
906 switch (a_xInfoP->status) {
908 fprintf(STDOUT, "status\t\tOK\n");
911 fprintf(STDOUT, "status\t\tBUSY\n");
914 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
917 fprintf(STDOUT, "backupID\t%lu\n", a_xInfoP->backupID);
918 fprintf(STDOUT, "parentID\t%lu\n", a_xInfoP->parentID);
919 fprintf(STDOUT, "cloneID\t\t%lu\n", a_xInfoP->cloneID);
920 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
921 switch (a_xInfoP->type) {
923 fprintf(STDOUT, "type\t\tRW\n");
926 fprintf(STDOUT, "type\t\tRO\n");
929 fprintf(STDOUT, "type\t\tBK\n");
932 fprintf(STDOUT, "type\t\t?\n");
935 fprintf(STDOUT, "creationDate\t%-9lu\t%s", a_xInfoP->creationDate,
936 vos_ctime(&a_xInfoP->creationDate));
937 fprintf(STDOUT, "accessDate\t%-9lu\t%s", a_xInfoP->accessDate,
938 vos_ctime(&a_xInfoP->accessDate));
939 fprintf(STDOUT, "updateDate\t%-9lu\t%s", a_xInfoP->updateDate,
940 vos_ctime(&a_xInfoP->updateDate));
941 fprintf(STDOUT, "backupDate\t%-9lu\t%s", a_xInfoP->backupDate,
942 vos_ctime(&a_xInfoP->backupDate));
943 fprintf(STDOUT, "copyDate\t%-9lu\t%s", a_xInfoP->copyDate,
944 vos_ctime(&a_xInfoP->copyDate));
946 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
947 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
949 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
950 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
954 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
955 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
956 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
957 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
959 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
960 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
961 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
962 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
966 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
967 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
968 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
969 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
972 } /*Volume status OK */
973 else if (a_xInfoP->status == VBUSY) {
975 qPut(&busyHead, a_xInfoP->volid);
977 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
978 (unsigned long)a_xInfoP->volid);
982 qPut(¬okHead, a_xInfoP->volid);
984 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
985 (unsigned long)a_xInfoP->volid);
986 } /*Screwed volume */
992 if (a_xInfoP->status == VOK) {
993 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
994 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
995 if (a_xInfoP->type == 0)
996 fprintf(STDOUT, "type\tRW\n");
997 if (a_xInfoP->type == 1)
998 fprintf(STDOUT, "type\tRO\n");
999 if (a_xInfoP->type == 2)
1000 fprintf(STDOUT, "type\tBK\n");
1001 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1003 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1004 if (a_xInfoP->inUse == 1)
1010 else if (a_xInfoP->status == VBUSY) {
1012 qPut(&busyHead, a_xInfoP->volid);
1014 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1015 (unsigned long)a_xInfoP->volid);
1019 qPut(¬okHead, a_xInfoP->volid);
1021 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1022 (unsigned long)a_xInfoP->volid);
1023 } /*Screwed volume */
1024 } /*Default listing */
1025 } /*XDisplayFormat */
1026 #endif /*FULL_LISTVOL_SWITCH*/
1028 #ifdef FULL_LISTVOL_SWITCH
1030 DisplayFormat2(server, partition, pntr)
1031 long server, partition;
1034 static long server_cache = -1, partition_cache = -1;
1035 static char hostname[256], address[32], pname[16];
1037 if (server != server_cache) {
1041 strcpy(hostname, hostutil_GetNameByINet(server));
1042 strcpy(address, inet_ntoa(s));
1043 server_cache = server;
1045 if (partition != partition_cache) {
1046 MapPartIdIntoName(partition, pname);
1047 partition_cache = partition;
1049 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1050 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
1051 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1052 fprintf(STDOUT, "part\t\t%s\n", pname);
1053 switch (pntr->status) {
1055 fprintf(STDOUT, "status\t\tOK\n");
1058 fprintf(STDOUT, "status\t\tBUSY\n");
1061 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1064 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
1065 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
1066 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
1067 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1068 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1069 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1070 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1071 switch (pntr->type) {
1073 fprintf(STDOUT, "type\t\tRW\n");
1076 fprintf(STDOUT, "type\t\tRO\n");
1079 fprintf(STDOUT, "type\t\tBK\n");
1082 fprintf(STDOUT, "type\t\t?\n");
1085 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
1086 vos_ctime(&pntr->creationDate));
1087 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
1088 vos_ctime(&pntr->accessDate));
1089 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
1090 vos_ctime(&pntr->updateDate));
1091 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
1092 vos_ctime(&pntr->backupDate));
1093 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
1094 vos_ctime(&pntr->copyDate));
1095 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
1096 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1097 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1098 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
1099 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1100 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1101 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
1102 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
1103 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
1108 DisplayVolumes2(server, partition, pntr, count)
1110 long server, partition, count;
1114 for (i = 0; i < count; i++) {
1115 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1116 DisplayFormat2(server, partition, pntr);
1117 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1122 #endif /* FULL_LISTVOL_SWITCH */
1125 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
1126 afs_int32 server, part;
1128 afs_int32 count, longlist, fast;
1131 int totalOK, totalNotOK, totalBusy, i;
1139 for (i = 0; i < count; i++) {
1140 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1145 while (busyHead.count) {
1146 qGet(&busyHead, &volid);
1147 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1148 (unsigned long)volid);
1152 while (notokHead.count) {
1153 qGet(¬okHead, &volid);
1154 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1155 (unsigned long)volid);
1159 fprintf(STDOUT, "\n");
1162 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1163 totalOK, totalNotOK, totalBusy);
1167 /*------------------------------------------------------------------------
1168 * PRIVATE XDisplayVolumes
1171 * Display extended volume information.
1174 * a_servID : Pointer to the Rx call we're performing.
1175 * a_partID : Partition for which we want the extended list.
1176 * a_xInfoP : Ptr to extended volume info.
1177 * a_count : Number of volume records contained above.
1178 * a_int32 : Int32 listing generated?
1179 * a_fast : Fast listing generated?
1180 * a_quiet : Quiet listing generated?
1186 * Nothing interesting.
1190 *------------------------------------------------------------------------*/
1193 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1197 volintXInfo *a_xInfoP;
1203 { /*XDisplayVolumes */
1205 int totalOK; /*Total OK volumes */
1206 int totalNotOK; /*Total screwed volumes */
1207 int totalBusy; /*Total busy volumes */
1208 int i; /*Loop variable */
1209 afs_int32 volid; /*Current volume ID */
1212 * Initialize counters and (global!!) queues.
1221 * Display each volume in the list.
1223 for (i = 0; i < a_count; i++) {
1224 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1225 &totalBusy, a_fast, a_int32, 0);
1230 * If any volumes were found to be busy or screwed, display them.
1233 while (busyHead.count) {
1234 qGet(&busyHead, &volid);
1235 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1236 (unsigned long)volid);
1240 while (notokHead.count) {
1241 qGet(¬okHead, &volid);
1242 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1243 (unsigned long)volid);
1248 fprintf(STDOUT, "\n");
1251 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1252 totalOK, totalNotOK, totalBusy);
1256 } /*XDisplayVolumes */
1257 #ifdef FULL_LISTVOL_SWITCH
1258 /*------------------------------------------------------------------------
1259 * PRIVATE XDisplayVolumes2
1262 * Display extended formated volume information.
1265 * a_servID : Pointer to the Rx call we're performing.
1266 * a_partID : Partition for which we want the extended list.
1267 * a_xInfoP : Ptr to extended volume info.
1268 * a_count : Number of volume records contained above.
1269 * a_int32 : Int32 listing generated?
1270 * a_fast : Fast listing generated?
1271 * a_quiet : Quiet listing generated?
1277 * Nothing interesting.
1281 *------------------------------------------------------------------------*/
1284 XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1288 volintXInfo *a_xInfoP;
1294 { /*XDisplayVolumes */
1296 int totalOK; /*Total OK volumes */
1297 int totalNotOK; /*Total screwed volumes */
1298 int totalBusy; /*Total busy volumes */
1299 int i; /*Loop variable */
1300 afs_int32 volid; /*Current volume ID */
1303 * Initialize counters and (global!!) queues.
1312 * Display each volume in the list.
1314 for (i = 0; i < a_count; i++) {
1315 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1316 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1317 &totalBusy, a_fast, a_int32, 0);
1318 fprintf(STDOUT, "END_OF_ENTRY\n");
1323 * If any volumes were found to be busy or screwed, display them.
1326 while (busyHead.count) {
1327 qGet(&busyHead, &volid);
1328 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1329 (unsigned long)volid);
1333 while (notokHead.count) {
1334 qGet(¬okHead, &volid);
1335 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1336 (unsigned long)volid);
1341 fprintf(STDOUT, "\n");
1344 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1345 totalOK, totalNotOK, totalBusy);
1349 } /*XDisplayVolumes2 */
1350 #endif /* FULL_LISTVOL_SWITCH */
1353 /* set <server> and <part> to the correct values depending on
1354 * <voltype> and <entry> */
1356 GetServerAndPart(entry, voltype, server, part, previdx)
1357 struct nvldbentry *entry;
1358 afs_int32 *server, *part;
1362 int i, istart, vtype;
1367 /* Doesn't check for non-existance of backup volume */
1368 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1370 istart = 0; /* seach the entire entry */
1373 /* Seach from beginning of entry or pick up where we left off */
1374 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1377 for (i = istart; i < entry->nServers; i++) {
1378 if (entry->serverFlags[i] & vtype) {
1379 *server = entry->serverNumber[i];
1380 *part = entry->serverPartition[i];
1386 /* Didn't find any, return -1 */
1392 PostVolumeStats(entry)
1393 struct nvldbentry *entry;
1395 SubEnumerateEntry(entry);
1396 /* Check for VLOP_ALLOPERS */
1397 if (entry->flags & VLOP_ALLOPERS)
1398 fprintf(STDOUT, " Volume is currently LOCKED \n");
1402 /*------------------------------------------------------------------------
1403 * PRIVATE XVolumeStats
1406 * Display extended volume information.
1409 * a_xInfoP : Ptr to extended volume info.
1410 * a_entryP : Ptr to the volume's VLDB entry.
1411 * a_srvID : Server ID.
1412 * a_partID : Partition ID.
1413 * a_volType : Type of volume to print.
1419 * Nothing interesting.
1423 *------------------------------------------------------------------------*/
1426 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1427 volintXInfo *a_xInfoP;
1428 struct nvldbentry *a_entryP;
1435 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1437 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1438 a_srvID, /*Server ID to print */
1439 a_partID, /*Partition ID to print */
1440 &totalOK, /*Ptr to total-OK counter */
1441 &totalNotOK, /*Ptr to total-screwed counter */
1442 &totalBusy, /*Ptr to total-busy counter */
1443 0, /*Don't do a fast listing */
1444 1, /*Do a long listing */
1445 1); /*Show volume problems */
1451 VolumeStats(pntr, entry, server, part, voltype)
1453 struct nvldbentry *entry;
1455 afs_int32 server, part;
1457 int totalOK, totalNotOK, totalBusy;
1459 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1464 /* command to forcibly remove a volume */
1467 register struct cmd_syndesc *as;
1469 register afs_int32 code;
1470 afs_int32 volID, err;
1475 server = GetServer(tp = as->parms[0].items->data);
1477 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1481 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1483 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1487 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1490 PrintError("", err);
1493 "vos: could not parse '%s' as a numeric volume ID", tp);
1498 "vos: forcibly removing all traces of volume %d, please wait...",
1501 code = UV_NukeVolume(server, partID, volID);
1503 fprintf(STDOUT, "done.\n");
1505 fprintf(STDOUT, "failed with code %d.\n", code);
1510 /*------------------------------------------------------------------------
1511 * PRIVATE ExamineVolume
1514 * Routine used to examine a single volume, contacting the VLDB as
1515 * well as the Volume Server.
1518 * as : Ptr to parsed command line arguments.
1521 * 0 for a successful operation,
1522 * Otherwise, one of the ubik or VolServer error values.
1525 * Nothing interesting.
1529 *------------------------------------------------------------------------
1533 register struct cmd_syndesc *as;
1535 struct nvldbentry entry;
1536 afs_int32 vcode = 0;
1537 volintInfo *pntr = (volintInfo *) 0;
1538 volintXInfo *xInfoP = (volintXInfo *) 0;
1540 afs_int32 code, err, error = 0;
1541 int voltype, foundserv = 0, foundentry = 0;
1542 afs_int32 aserver, apart;
1544 int wantExtendedInfo; /*Do we want extended vol info? */
1546 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1548 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1551 PrintError("", err);
1553 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1554 as->parms[0].items->data);
1559 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1560 (unsigned long)volid);
1563 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1566 "Could not fetch the entry for volume number %lu from VLDB \n",
1567 (unsigned long)volid);
1571 fprintf(STDOUT, "done\n");
1572 MapHostToNetwork(&entry);
1574 if (entry.volumeId[RWVOL] == volid)
1576 else if (entry.volumeId[BACKVOL] == volid)
1578 else /* (entry.volumeId[ROVOL] == volid) */
1581 do { /* do {...} while (voltype == ROVOL) */
1582 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1583 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1584 * If its a RO vol, get the next RO entry.
1586 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1587 &aserver, &apart, &previdx);
1588 if (previdx == -1) { /* searched all entries */
1590 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1591 as->parms[0].items->data);
1598 /* Get information about the volume from the server */
1600 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1601 hostutil_GetNameByINet(aserver));
1604 if (wantExtendedInfo)
1605 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1607 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1609 fprintf(STDOUT, "done\n");
1613 if (code == ENODEV) {
1614 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1615 /* The VLDB says there is no backup volume and its not on disk */
1616 fprintf(STDERR, "Volume %s does not exist\n",
1617 as->parms[0].items->data);
1621 "Volume does not exist on server %s as indicated by the VLDB\n",
1622 hostutil_GetNameByINet(aserver));
1625 PrintDiagnostics("examine", code);
1627 fprintf(STDOUT, "\n");
1630 if (wantExtendedInfo)
1631 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1633 #ifdef FULL_LISTVOL_SWITCH
1634 if (as->parms[2].items) {
1635 DisplayFormat2(aserver, apart, pntr);
1636 EnumerateEntry(&entry);
1638 #endif /* FULL_LISTVOL_SWITCH */
1639 VolumeStats(pntr, &entry, aserver, apart, voltype);
1641 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1642 /* The VLDB says there is no backup volume yet we found one on disk */
1643 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1644 as->parms[0].items->data);
1653 } while (voltype == ROVOL);
1656 fprintf(STDERR, "Dump only information from VLDB\n\n");
1657 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1659 PostVolumeStats(&entry);
1664 /*------------------------------------------------------------------------
1668 * Routine used to change the status of a single volume.
1671 * as : Ptr to parsed command line arguments.
1674 * 0 for a successful operation,
1675 * Otherwise, one of the ubik or VolServer error values.
1678 * Nothing interesting.
1682 *------------------------------------------------------------------------
1686 register struct cmd_syndesc *as;
1688 struct nvldbentry entry;
1689 afs_int32 vcode = 0;
1692 afs_int32 code, err;
1693 afs_int32 aserver, apart;
1696 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1699 PrintError("", err);
1701 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1702 as->parms[0].items->data);
1706 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1709 "Could not fetch the entry for volume number %lu from VLDB \n",
1710 (unsigned long)volid);
1713 MapHostToNetwork(&entry);
1715 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1716 if (previdx == -1) {
1717 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1718 as->parms[0].items->data);
1722 init_volintInfo(&info);
1726 if (as->parms[1].items) {
1728 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1730 fprintf(STDERR, "invalid quota value\n");
1734 if (as->parms[2].items) {
1738 if (as->parms[3].items) {
1739 /* -clearVolUpCounter */
1742 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1745 "Could not update volume info fields for volume number %lu\n",
1746 (unsigned long)volid);
1750 /*------------------------------------------------------------------------
1754 * Brings a volume online.
1757 * as : Ptr to parsed command line arguments.
1760 * 0 for a successful operation,
1763 * Nothing interesting.
1767 *------------------------------------------------------------------------
1771 register struct cmd_syndesc *as;
1773 afs_int32 server, partition, volid;
1774 afs_int32 code, err = 0;
1776 server = GetServer(as->parms[0].items->data);
1778 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1779 as->parms[0].items->data);
1783 partition = volutil_GetPartitionID(as->parms[1].items->data);
1784 if (partition < 0) {
1785 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1786 as->parms[1].items->data);
1790 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1793 PrintError("", err);
1795 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1796 as->parms[0].items->data);
1800 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1803 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1810 /*------------------------------------------------------------------------
1811 * PRIVATE volOffline
1814 * Brings a volume offline.
1817 * as : Ptr to parsed command line arguments.
1820 * 0 for a successful operation,
1823 * Nothing interesting.
1827 *------------------------------------------------------------------------
1830 volOffline(register struct cmd_syndesc *as)
1832 afs_int32 server, partition, volid;
1833 afs_int32 code, err = 0;
1834 afs_int32 transflag, sleeptime, transdone;
1836 server = GetServer(as->parms[0].items->data);
1838 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1839 as->parms[0].items->data);
1843 partition = volutil_GetPartitionID(as->parms[1].items->data);
1844 if (partition < 0) {
1845 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1846 as->parms[1].items->data);
1850 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1853 PrintError("", err);
1855 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1856 as->parms[0].items->data);
1860 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1861 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1862 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1863 if (as->parms[4].items && !as->parms[3].items) {
1864 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1869 UV_SetVolume(server, partition, volid, transflag, transdone,
1872 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1880 CreateVolume(register struct cmd_syndesc *as)
1884 afs_int32 volid, code;
1885 struct nvldbentry entry;
1890 tserver = GetServer(as->parms[0].items->data);
1892 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1893 as->parms[0].items->data);
1896 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1898 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1899 as->parms[1].items->data);
1902 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1904 PrintError("", code);
1907 "vos : partition %s does not exist on the server\n",
1908 as->parms[1].items->data);
1911 if (!ISNAMEVALID(as->parms[2].items->data)) {
1913 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1914 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1917 if (!VolNameOK(as->parms[2].items->data)) {
1919 "Illegal volume name %s, should not end in .readonly or .backup\n",
1920 as->parms[2].items->data);
1923 if (IsNumeric(as->parms[2].items->data)) {
1924 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1925 as->parms[2].items->data);
1928 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1930 fprintf(STDERR, "Volume %s already exists\n",
1931 as->parms[2].items->data);
1932 PrintDiagnostics("create", code);
1936 if (as->parms[3].items) {
1937 if (!IsNumeric(as->parms[3].items->data)) {
1938 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1939 as->parms[3].items->data);
1943 code = util_GetInt32(as->parms[3].items->data, "a);
1945 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1951 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1954 PrintDiagnostics("create", code);
1957 MapPartIdIntoName(pnum, part);
1958 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1959 (unsigned long)volid, part, as->parms[0].items->data);
1966 struct nvldbentry *entry;
1969 afs_int32 error, code, curserver, curpart, volid;
1971 MapHostToNetwork(entry);
1973 for (i = 0; i < entry->nServers; i++) {
1974 curserver = entry->serverNumber[i];
1975 curpart = entry->serverPartition[i];
1976 if (entry->serverFlags[i] & ITSROVOL) {
1977 volid = entry->volumeId[ROVOL];
1979 volid = entry->volumeId[RWVOL];
1981 code = UV_DeleteVolume(curserver, curpart, volid);
1990 struct cmd_syndesc *as;
1992 afs_int32 err, code = 0;
1993 afs_int32 server = 0, partition = -1, volid;
1997 if (as->parms[0].items) {
1998 server = GetServer(as->parms[0].items->data);
2000 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2001 as->parms[0].items->data);
2006 if (as->parms[1].items) {
2007 partition = volutil_GetPartitionID(as->parms[1].items->data);
2008 if (partition < 0) {
2009 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2010 as->parms[1].items->data);
2014 /* Check for validity of the partition */
2015 if (!IsPartValid(partition, server, &code)) {
2017 PrintError("", code);
2020 "vos : partition %s does not exist on the server\n",
2021 as->parms[1].items->data);
2027 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2029 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2030 as->parms[2].items->data);
2032 PrintError("", err);
2036 /* If the server or partition option are not complete, try to fill
2037 * them in from the VLDB entry.
2039 if ((partition == -1) || !server) {
2040 struct nvldbentry entry;
2042 code = VLDB_GetEntryByID(volid, -1, &entry);
2045 "Could not fetch the entry for volume %lu from VLDB\n",
2046 (unsigned long)volid);
2047 PrintError("", code);
2051 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2052 || ((volid == entry.volumeId[BACKVOL])
2053 && (entry.flags & BACK_EXISTS))) {
2054 idx = Lp_GetRwIndex(&entry);
2055 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2056 || ((partition != -1)
2057 && (partition != entry.serverPartition[idx]))) {
2058 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2059 as->parms[2].items->data);
2062 } else if ((volid == entry.volumeId[ROVOL])
2063 && (entry.flags & RO_EXISTS)) {
2064 for (idx = -1, j = 0; j < entry.nServers; j++) {
2065 if (entry.serverFlags[j] != ITSROVOL)
2068 if (((server == 0) || (server == entry.serverNumber[j]))
2069 && ((partition == -1)
2070 || (partition == entry.serverPartition[j]))) {
2073 "VLDB: Volume '%s' matches more than one RO\n",
2074 as->parms[2].items->data);
2081 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2082 as->parms[2].items->data);
2086 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2087 as->parms[2].items->data);
2091 server = htonl(entry.serverNumber[idx]);
2092 partition = entry.serverPartition[idx];
2096 code = UV_DeleteVolume(server, partition, volid);
2098 PrintDiagnostics("remove", code);
2102 MapPartIdIntoName(partition, pname);
2103 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2104 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2108 #define TESTM 0 /* set for move space tests, clear for production */
2111 register struct cmd_syndesc *as;
2114 afs_int32 volid, fromserver, toserver, frompart, topart;
2115 afs_int32 flags, code, err;
2116 char fromPartName[10], toPartName[10];
2118 struct diskPartition partition; /* for space check */
2121 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2124 PrintError("", err);
2126 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2127 as->parms[0].items->data);
2130 fromserver = GetServer(as->parms[1].items->data);
2131 if (fromserver == 0) {
2132 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2133 as->parms[1].items->data);
2136 toserver = GetServer(as->parms[3].items->data);
2137 if (toserver == 0) {
2138 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2139 as->parms[3].items->data);
2142 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2144 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2145 as->parms[2].items->data);
2148 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2150 PrintError("", code);
2153 "vos : partition %s does not exist on the server\n",
2154 as->parms[2].items->data);
2157 topart = volutil_GetPartitionID(as->parms[4].items->data);
2159 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2160 as->parms[4].items->data);
2163 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2165 PrintError("", code);
2168 "vos : partition %s does not exist on the server\n",
2169 as->parms[4].items->data);
2174 if (as->parms[5].items) flags |= RV_NOCLONE;
2177 * check source partition for space to clone volume
2180 MapPartIdIntoName(topart, toPartName);
2181 MapPartIdIntoName(frompart, fromPartName);
2184 * check target partition for space to move volume
2187 code = UV_PartitionInfo(toserver, toPartName, &partition);
2189 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2193 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2196 p = (volintInfo *) 0;
2197 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2199 fprintf(STDERR, "vos:cannot access volume %lu\n",
2200 (unsigned long)volid);
2204 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2206 if (partition.free <= p->size) {
2208 "vos: no space on target partition %s to move volume %lu\n",
2209 toPartName, (unsigned long)volid);
2216 fprintf(STDOUT, "size test - don't do move\n");
2220 /* successful move still not guaranteed but shoot for it */
2223 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2225 PrintDiagnostics("move", code);
2228 MapPartIdIntoName(topart, toPartName);
2229 MapPartIdIntoName(frompart, fromPartName);
2230 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2231 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2232 as->parms[3].items->data, toPartName);
2239 register struct cmd_syndesc *as;
2241 afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
2242 char fromPartName[10], toPartName[10], *tovolume;
2243 struct nvldbentry entry;
2244 struct diskPartition partition; /* for space check */
2247 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2250 PrintError("", err);
2252 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2253 as->parms[0].items->data);
2256 fromserver = GetServer(as->parms[1].items->data);
2257 if (fromserver == 0) {
2258 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2259 as->parms[1].items->data);
2263 toserver = GetServer(as->parms[4].items->data);
2264 if (toserver == 0) {
2265 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2266 as->parms[4].items->data);
2270 tovolume = as->parms[3].items->data;
2271 if (!ISNAMEVALID(tovolume)) {
2273 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2274 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2277 if (!VolNameOK(tovolume)) {
2279 "Illegal volume name %s, should not end in .readonly or .backup\n",
2283 if (IsNumeric(tovolume)) {
2284 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2288 code = VLDB_GetEntryByName(tovolume, &entry);
2290 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2291 PrintDiagnostics("copy", code);
2295 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2297 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2298 as->parms[2].items->data);
2301 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2303 PrintError("", code);
2306 "vos : partition %s does not exist on the server\n",
2307 as->parms[2].items->data);
2311 topart = volutil_GetPartitionID(as->parms[5].items->data);
2313 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2314 as->parms[5].items->data);
2317 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2319 PrintError("", code);
2322 "vos : partition %s does not exist on the server\n",
2323 as->parms[5].items->data);
2328 if (as->parms[6].items) flags |= RV_OFFLINE;
2329 if (as->parms[7].items) flags |= RV_RDONLY;
2330 if (as->parms[8].items) flags |= RV_NOCLONE;
2332 MapPartIdIntoName(topart, toPartName);
2333 MapPartIdIntoName(frompart, fromPartName);
2336 * check target partition for space to move volume
2339 code = UV_PartitionInfo(toserver, toPartName, &partition);
2341 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2345 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2348 p = (volintInfo *) 0;
2349 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2351 fprintf(STDERR, "vos:cannot access volume %lu\n",
2352 (unsigned long)volid);
2356 if (partition.free <= p->size) {
2358 "vos: no space on target partition %s to copy volume %lu\n",
2359 toPartName, (unsigned long)volid);
2365 /* successful copy still not guaranteed but shoot for it */
2368 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2371 PrintDiagnostics("copy", code);
2374 MapPartIdIntoName(topart, toPartName);
2375 MapPartIdIntoName(frompart, fromPartName);
2376 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2377 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2378 tovolume, as->parms[4].items->data, toPartName);
2386 register struct cmd_syndesc *as;
2388 afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
2389 afs_int32 code, err, flags;
2390 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2391 struct nvldbentry entry;
2392 struct diskPartition partition; /* for space check */
2395 p = (volintInfo *) 0;
2396 q = (volintInfo *) 0;
2398 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2401 PrintError("", err);
2403 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2404 as->parms[0].items->data);
2407 fromserver = GetServer(as->parms[1].items->data);
2408 if (fromserver == 0) {
2409 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2410 as->parms[1].items->data);
2414 toserver = GetServer(as->parms[3].items->data);
2415 if (toserver == 0) {
2416 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2417 as->parms[3].items->data);
2421 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2423 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2424 as->parms[2].items->data);
2427 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2429 PrintError("", code);
2432 "vos : partition %s does not exist on the server\n",
2433 as->parms[2].items->data);
2437 topart = volutil_GetPartitionID(as->parms[4].items->data);
2439 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2440 as->parms[4].items->data);
2443 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2445 PrintError("", code);
2448 "vos : partition %s does not exist on the server\n",
2449 as->parms[4].items->data);
2453 if (as->parms[5].items) {
2454 tovolume = as->parms[5].items->data;
2455 if (!ISNAMEVALID(tovolume)) {
2457 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2458 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2461 if (!VolNameOK(tovolume)) {
2463 "Illegal volume name %s, should not end in .readonly or .backup\n",
2467 if (IsNumeric(tovolume)) {
2469 "Illegal volume name %s, should not be a number\n",
2474 /* use actual name of source volume */
2475 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2477 fprintf(STDERR, "vos:cannot access volume %lu\n",
2478 (unsigned long)volid);
2481 strcpy(toVolName, p->name);
2482 tovolume = toVolName;
2483 /* save p for size checks later */
2486 if (as->parms[6].items) {
2487 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2490 PrintError("", err);
2492 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2493 as->parms[6].items->data);
2499 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2502 PrintError("", err);
2504 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2513 if (as->parms[7].items) flags |= RV_OFFLINE;
2514 if (as->parms[8].items) flags |= RV_RDONLY;
2515 if (as->parms[9].items) flags |= RV_NOCLONE;
2516 if (as->parms[10].items) flags |= RV_CPINCR;
2518 MapPartIdIntoName(topart, toPartName);
2519 MapPartIdIntoName(frompart, fromPartName);
2522 * check target partition for space to move volume
2525 code = UV_PartitionInfo(toserver, toPartName, &partition);
2527 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2531 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2534 /* Don't do this again if we did it above */
2536 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2538 fprintf(STDERR, "vos:cannot access volume %lu\n",
2539 (unsigned long)volid);
2544 /* OK if this fails */
2545 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2547 /* Treat existing volume size as "free" */
2549 p->size = (q->size < p->size) ? p->size - q->size : 0;
2551 if (partition.free <= p->size) {
2553 "vos: no space on target partition %s to copy volume %lu\n",
2554 toPartName, (unsigned long)volid);
2562 /* successful copy still not guaranteed but shoot for it */
2565 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2566 topart, tovolid, flags);
2568 PrintDiagnostics("shadow", code);
2571 MapPartIdIntoName(topart, toPartName);
2572 MapPartIdIntoName(frompart, fromPartName);
2573 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2574 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2575 as->parms[3].items->data, toPartName);
2583 register struct cmd_syndesc *as;
2585 afs_int32 server, part, volid, cloneid, voltype;
2586 char partName[10], *volname;
2587 afs_int32 code, err, flags;
2588 struct nvldbentry entry;
2590 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2593 PrintError("", err);
2595 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2596 as->parms[0].items->data);
2600 if (as->parms[1].items || as->parms[2].items) {
2601 if (!as->parms[1].items || !as->parms[2].items) {
2603 "Must specify both -server and -partition options\n");
2606 server = GetServer(as->parms[1].items->data);
2608 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2609 as->parms[1].items->data);
2612 part = volutil_GetPartitionID(as->parms[2].items->data);
2614 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2615 as->parms[2].items->data);
2618 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2620 PrintError("", code);
2623 "vos : partition %s does not exist on the server\n",
2624 as->parms[2].items->data);
2628 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2634 if (as->parms[3].items) {
2635 volname = as->parms[3].items->data;
2636 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2638 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2639 volname, VOLSER_OLDMAXVOLNAME - 1);
2642 if (!VolNameOK(volname)) {
2644 "Illegal volume name %s, should not end in .readonly or .backup\n",
2648 if (IsNumeric(volname)) {
2650 "Illegal volume name %s, should not be a number\n",
2657 if (as->parms[4].items) {
2658 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2661 PrintError("", err);
2663 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2664 as->parms[4].items->data);
2670 if (as->parms[5].items) flags |= RV_OFFLINE;
2671 if (as->parms[6].items) flags |= RV_RDONLY;
2675 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2678 PrintDiagnostics("clone", code);
2681 MapPartIdIntoName(part, partName);
2682 fprintf(STDOUT, "Created clone for volume %lu\n",
2683 as->parms[0].items->data);
2691 register struct cmd_syndesc *as;
2693 afs_int32 avolid, aserver, apart, vtype, code, err;
2694 struct nvldbentry entry;
2696 afs_int32 buvolid, buserver, bupart, butype;
2697 struct nvldbentry buentry;
2699 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2702 PrintError("", err);
2704 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2705 as->parms[0].items->data);
2708 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2712 /* verify this is a readwrite volume */
2714 if (vtype != RWVOL) {
2715 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2719 /* is there a backup volume already? */
2721 if (entry.flags & BACK_EXISTS) {
2722 /* yep, where is it? */
2724 buvolid = entry.volumeId[BACKVOL];
2725 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2730 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2733 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2739 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2740 (unsigned long)buvolid, (unsigned long)buserver);
2745 /* nope, carry on */
2747 code = UV_BackupVolume(aserver, apart, avolid);
2750 PrintDiagnostics("backup", code);
2753 fprintf(STDOUT, "Created backup volume for %s \n",
2754 as->parms[0].items->data);
2760 register struct cmd_syndesc *as;
2763 struct nvldbentry entry;
2764 afs_int32 avolid, aserver, apart, vtype, code, err;
2767 if (as->parms[1].items)
2769 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2772 PrintError("", err);
2774 fprintf(STDERR, "vos: can't find volume '%s'\n",
2775 as->parms[0].items->data);
2778 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2782 if (vtype != RWVOL) {
2783 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2787 if (!ISNAMEVALID(entry.name)) {
2789 "Volume name %s is too long, rename before releasing\n",
2794 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2796 PrintDiagnostics("release", code);
2799 fprintf(STDOUT, "Released volume %s successfully\n",
2800 as->parms[0].items->data);
2806 register struct cmd_syndesc *as;
2809 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2810 char filename[MAXPATHLEN];
2811 struct nvldbentry entry;
2813 rx_SetRxDeadTime(60 * 10);
2814 for (i = 0; i < MAXSERVERS; i++) {
2815 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2818 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2819 if (rxConn->service)
2820 rxConn->service->connDeadTime = rx_connDeadTime;
2823 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2826 PrintError("", err);
2828 fprintf(STDERR, "vos: can't find volume '%s'\n",
2829 as->parms[0].items->data);
2833 if (as->parms[3].items || as->parms[4].items) {
2834 if (!as->parms[3].items || !as->parms[4].items) {
2836 "Must specify both -server and -partition options\n");
2839 aserver = GetServer(as->parms[3].items->data);
2841 fprintf(STDERR, "Invalid server name\n");
2844 apart = volutil_GetPartitionID(as->parms[4].items->data);
2846 fprintf(STDERR, "Invalid partition name\n");
2850 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2855 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2856 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2858 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2859 as->parms[1].items->data, code);
2863 if (as->parms[2].items) {
2864 strcpy(filename, as->parms[2].items->data);
2866 strcpy(filename, "");
2869 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2871 if (as->parms[5].items) {
2873 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2874 DumpFunction, filename, flags);
2877 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2880 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2881 flags &= ~VOLDUMPV2_OMITDIRS;
2885 PrintDiagnostics("dump", code);
2888 if (strcmp(filename, ""))
2889 fprintf(STDERR, "Dumped volume %s in file %s\n",
2890 as->parms[0].items->data, filename);
2892 fprintf(STDERR, "Dumped volume %s in stdout \n",
2893 as->parms[0].items->data);
2908 register struct cmd_syndesc *as;
2911 afs_int32 avolid, aparentid, aserver, apart, code, vcode, err;
2912 afs_int32 aoverwrite = ASK;
2913 afs_int32 acreation = 0, alastupdate = 0;
2914 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2916 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2917 char volname[VOLSER_MAXVOLNAME + 1];
2918 struct nvldbentry entry;
2923 if (as->parms[4].items) {
2924 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2927 PrintError("", err);
2929 fprintf(STDERR, "vos: can't find volume '%s'\n",
2930 as->parms[4].items->data);
2936 if (as->parms[5].items) {
2937 if ((strcmp(as->parms[5].items->data, "a") == 0)
2938 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2940 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2941 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2943 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2944 || (strcmp(as->parms[5].items->data, "inc") == 0)
2945 || (strcmp(as->parms[5].items->data, "increment") == 0)
2946 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2949 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2950 as->parms[5].items->data);
2954 if (as->parms[6].items)
2956 if (as->parms[7].items) {
2961 if (as->parms[8].items) {
2962 if ((strcmp(as->parms[8].items->data, "d") == 0)
2963 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2964 acreation = TS_DUMP;
2965 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2966 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2967 acreation = TS_KEEP;
2968 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2969 || (strcmp(as->parms[8].items->data, "new") == 0)) {
2972 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
2973 as->parms[8].items->data);
2978 if (as->parms[9].items) {
2979 if ((strcmp(as->parms[9].items->data, "d") == 0)
2980 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
2981 alastupdate = TS_DUMP;
2982 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
2983 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
2984 alastupdate = TS_KEEP;
2985 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
2986 || (strcmp(as->parms[9].items->data, "new") == 0)) {
2987 alastupdate = TS_NEW;
2989 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
2990 as->parms[9].items->data);
2995 aserver = GetServer(as->parms[0].items->data);
2997 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2998 as->parms[0].items->data);
3001 apart = volutil_GetPartitionID(as->parms[1].items->data);
3003 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3004 as->parms[1].items->data);
3007 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3009 PrintError("", code);
3012 "vos : partition %s does not exist on the server\n",
3013 as->parms[1].items->data);
3016 strcpy(avolname, as->parms[2].items->data);
3017 if (!ISNAMEVALID(avolname)) {
3019 "vos: the name of the volume %s exceeds the size limit\n",
3023 if (!VolNameOK(avolname)) {
3025 "Illegal volume name %s, should not end in .readonly or .backup\n",
3029 if (as->parms[3].items) {
3030 strcpy(afilename, as->parms[3].items->data);
3031 if (!FileExists(afilename)) {
3032 fprintf(STDERR, "Can't access file %s\n", afilename);
3036 strcpy(afilename, "");
3039 /* Check if volume exists or not */
3041 vsu_ExtractName(volname, avolname);
3042 vcode = VLDB_GetEntryByName(volname, &entry);
3043 if (vcode) { /* no volume - do a full restore */
3044 restoreflags = RV_FULLRST;
3045 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3047 "Volume does not exist; Will perform a full restore\n");
3050 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3051 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3052 restoreflags = RV_FULLRST;
3053 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3055 "%s Volume does not exist; Will perform a full restore\n",
3056 readonly ? "RO" : "RW");
3059 avolid = entry.volumeId[voltype];
3060 } else if (entry.volumeId[voltype] != 0
3061 && entry.volumeId[voltype] != avolid) {
3062 avolid = entry.volumeId[voltype];
3064 aparentid = entry.volumeId[RWVOL];
3067 else { /* volume exists - do we do a full incremental or abort */
3068 int Oserver, Opart, Otype, vol_elsewhere = 0;
3069 struct nvldbentry Oentry;
3073 avolid = entry.volumeId[voltype];
3074 } else if (entry.volumeId[voltype] != 0
3075 && entry.volumeId[voltype] != avolid) {
3076 avolid = entry.volumeId[voltype];
3078 aparentid = entry.volumeId[RWVOL];
3080 /* A file name was specified - check if volume is on another partition */
3081 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3085 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3088 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3092 if (!vcode || (Opart != apart))
3095 if (aoverwrite == ASK) {
3096 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3098 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3102 /* Ask what to do */
3103 if (vol_elsewhere) {
3105 "The volume %s %u already exists on a different server/part\n",
3106 volname, entry.volumeId[voltype]);
3108 "Do you want to do a full restore or abort? [fa](a): ");
3111 "The volume %s %u already exists in the VLDB\n",
3112 volname, entry.volumeId[voltype]);
3114 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3117 while (!(dc == EOF || dc == '\n'))
3118 dc = getchar(); /* goto end of line */
3119 if ((c == 'f') || (c == 'F'))
3121 else if ((c == 'i') || (c == 'I'))
3127 if (aoverwrite == ABORT) {
3128 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3130 } else if (aoverwrite == FULL) {
3131 restoreflags = RV_FULLRST;
3133 "Volume exists; Will delete and perform full restore\n");
3134 } else if (aoverwrite == INC) {
3136 if (vol_elsewhere) {
3138 "%s volume %lu already exists on a different server/part; not allowed\n",
3139 readonly ? "RO" : "RW", (unsigned long)avolid);
3145 restoreflags |= RV_OFFLINE;
3147 restoreflags |= RV_RDONLY;
3149 switch (acreation) {
3151 restoreflags |= RV_CRDUMP;
3154 restoreflags |= RV_CRKEEP;
3157 restoreflags |= RV_CRNEW;
3160 if (aoverwrite == FULL)
3161 restoreflags |= RV_CRNEW;
3163 restoreflags |= RV_CRKEEP;
3166 switch (alastupdate) {
3168 restoreflags |= RV_LUDUMP;
3171 restoreflags |= RV_LUKEEP;
3174 restoreflags |= RV_LUNEW;
3177 restoreflags |= RV_LUDUMP;
3181 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3182 avolname, restoreflags, WriteData, afilename);
3184 PrintDiagnostics("restore", code);
3187 MapPartIdIntoName(apart, apartName);
3190 * patch typo here - originally "parms[1]", should be "parms[0]"
3193 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3194 as->parms[0].items->data, apartName);
3200 register struct cmd_syndesc *as;
3203 afs_int32 avolid, code, err;
3205 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3208 PrintError("", err);
3210 fprintf(STDERR, "vos: can't find volume '%s'\n",
3211 as->parms[0].items->data);
3215 code = UV_LockRelease(avolid);
3217 PrintDiagnostics("unlock", code);
3220 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3221 as->parms[0].items->data);
3227 register struct cmd_syndesc *as;
3229 afs_int32 avolid, aserver, apart, code, err;
3230 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3232 vsu_ExtractName(avolname, as->parms[2].items->data);;
3233 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3236 PrintError("", err);
3238 fprintf(STDERR, "vos: can't find volume '%s'\n",
3239 as->parms[2].items->data);
3242 aserver = GetServer(as->parms[0].items->data);
3244 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3245 as->parms[0].items->data);
3248 apart = volutil_GetPartitionID(as->parms[1].items->data);
3250 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3251 as->parms[1].items->data);
3254 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3256 PrintError("", code);
3259 "vos : partition %s does not exist on the server\n",
3260 as->parms[1].items->data);
3263 code = UV_AddSite(aserver, apart, avolid);
3265 PrintDiagnostics("addsite", code);
3268 MapPartIdIntoName(apart, apartName);
3269 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3270 as->parms[0].items->data, apartName, as->parms[2].items->data);
3276 register struct cmd_syndesc *as;
3279 afs_int32 avolid, aserver, apart, code, err;
3280 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3282 vsu_ExtractName(avolname, as->parms[2].items->data);
3283 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3286 PrintError("", err);
3288 fprintf(STDERR, "vos: can't find volume '%s'\n",
3289 as->parms[2].items->data);
3292 aserver = GetServer(as->parms[0].items->data);
3294 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3295 as->parms[0].items->data);
3298 apart = volutil_GetPartitionID(as->parms[1].items->data);
3300 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3301 as->parms[1].items->data);
3305 *skip the partition validity check, since it is possible that the partition
3306 *has since been decomissioned.
3309 if (!IsPartValid(apart,aserver,&code)){
3310 if(code) PrintError("",code);
3311 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3315 code = UV_RemoveSite(aserver, apart, avolid);
3317 PrintDiagnostics("remsite", code);
3320 MapPartIdIntoName(apart, apartName);
3321 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3322 as->parms[0].items->data, apartName, as->parms[2].items->data);
3328 register struct cmd_syndesc *as;
3330 afs_int32 avolid, aserver, apart, code, err;
3333 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3336 PrintError("", err);
3338 fprintf(STDERR, "vos: can't find volume '%s'\n",
3339 as->parms[2].items->data);
3342 aserver = GetServer(as->parms[0].items->data);
3344 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3345 as->parms[0].items->data);
3348 apart = volutil_GetPartitionID(as->parms[1].items->data);
3350 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3351 as->parms[1].items->data);
3354 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3356 PrintError("", code);
3359 "vos : partition %s does not exist on the server\n",
3360 as->parms[1].items->data);
3363 code = UV_ChangeLocation(aserver, apart, avolid);
3365 PrintDiagnostics("addsite", code);
3368 MapPartIdIntoName(apart, apartName);
3369 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3370 as->parms[0].items->data, apartName, as->parms[2].items->data);
3376 register struct cmd_syndesc *as;
3378 afs_int32 aserver, code;
3379 struct partList dummyPartList;
3384 aserver = GetServer(as->parms[0].items->data);
3386 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3387 as->parms[0].items->data);
3392 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3394 PrintDiagnostics("listpart", code);
3398 fprintf(STDOUT, "The partitions on the server are:\n");
3399 for (i = 0; i < cnt; i++) {
3400 if (dummyPartList.partFlags[i] & PARTVALID) {
3401 memset(pname, 0, sizeof(pname));
3402 MapPartIdIntoName(dummyPartList.partId[i], pname);
3403 fprintf(STDOUT, " %10s ", pname);
3405 if ((i % 5) == 0 && (i != 0))
3406 fprintf(STDOUT, "\n");
3409 fprintf(STDOUT, "\n");
3410 fprintf(STDOUT, "Total: %d\n", total);
3416 CompareVolName(p1, p2)
3419 volintInfo *arg1, *arg2;
3421 arg1 = (volintInfo *) p1;
3422 arg2 = (volintInfo *) p2;
3423 return (strcmp(arg1->name, arg2->name));
3427 /*------------------------------------------------------------------------
3428 * PRIVATE XCompareVolName
3431 * Comparison routine for volume names coming from an extended
3435 * a_obj1P : Char ptr to first extended vol info object
3436 * a_obj1P : Char ptr to second extended vol info object
3439 * The value of strcmp() on the volume names within the passed
3440 * objects (i,e., -1, 0, or 1).
3443 * Passed to qsort() as the designated comparison routine.
3447 *------------------------------------------------------------------------*/
3450 XCompareVolName(a_obj1P, a_obj2P)
3451 char *a_obj1P, *a_obj2P;
3453 { /*XCompareVolName */
3456 (((struct volintXInfo *)(a_obj1P))->name,
3457 ((struct volintXInfo *)(a_obj2P))->name));
3459 } /*XCompareVolName */
3462 CompareVolID(p1, p2)
3465 volintInfo *arg1, *arg2;
3467 arg1 = (volintInfo *) p1;
3468 arg2 = (volintInfo *) p2;
3469 if (arg1->volid == arg2->volid)
3471 if (arg1->volid > arg2->volid)
3478 /*------------------------------------------------------------------------
3479 * PRIVATE XCompareVolID
3482 * Comparison routine for volume IDs coming from an extended
3486 * a_obj1P : Char ptr to first extended vol info object
3487 * a_obj1P : Char ptr to second extended vol info object
3490 * The value of strcmp() on the volume names within the passed
3491 * objects (i,e., -1, 0, or 1).
3494 * Passed to qsort() as the designated comparison routine.
3498 *------------------------------------------------------------------------*/
3501 XCompareVolID(a_obj1P, a_obj2P)
3502 char *a_obj1P, *a_obj2P;
3504 { /*XCompareVolID */
3506 afs_int32 id1, id2; /*Volume IDs we're comparing */
3508 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3509 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3517 } /*XCompareVolID */
3519 /*------------------------------------------------------------------------
3520 * PRIVATE ListVolumes
3523 * Routine used to list volumes, contacting the Volume Server
3524 * directly, bypassing the VLDB.
3527 * as : Ptr to parsed command line arguments.
3530 * 0 Successful operation
3533 * Nothing interesting.
3537 *------------------------------------------------------------------------*/
3541 register struct cmd_syndesc *as;
3543 afs_int32 apart, int32list, fast;
3544 afs_int32 aserver, code;
3545 volintInfo *pntr, *oldpntr;
3549 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
3550 int wantExtendedInfo; /*Do we want extended vol info? */
3553 struct partList dummyPartList;
3561 if (as->parms[3].items)
3563 if (as->parms[4].items)
3567 if (as->parms[2].items)
3573 if (as->parms[5].items) {
3575 * We can't coexist with the fast flag.
3579 "vos: Can't use the -fast and -extended flags together\n");
3584 * We need to turn on ``long'' listings to get the full effect.
3586 wantExtendedInfo = 1;
3589 wantExtendedInfo = 0;
3590 if (as->parms[1].items) {
3591 apart = volutil_GetPartitionID(as->parms[1].items->data);
3593 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3594 as->parms[1].items->data);
3597 dummyPartList.partId[0] = apart;
3598 dummyPartList.partFlags[0] = PARTVALID;
3601 aserver = GetServer(as->parms[0].items->data);
3603 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3604 as->parms[0].items->data);
3609 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3611 PrintError("", code);
3614 "vos : partition %s does not exist on the server\n",
3615 as->parms[1].items->data);
3619 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3621 PrintDiagnostics("listvol", code);
3625 for (i = 0; i < cnt; i++) {
3626 if (dummyPartList.partFlags[i] & PARTVALID) {
3627 if (wantExtendedInfo)
3629 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3633 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3636 PrintDiagnostics("listvol", code);
3641 if (wantExtendedInfo) {
3642 origxInfoP = xInfoP;
3643 base = (char *)xInfoP;
3646 base = (char *)pntr;
3650 if (wantExtendedInfo)
3651 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3653 qsort(base, count, sizeof(volintInfo), CompareVolName);
3655 if (wantExtendedInfo)
3656 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3658 qsort(base, count, sizeof(volintInfo), CompareVolID);
3660 MapPartIdIntoName(dummyPartList.partId[i], pname);
3663 "Total number of volumes on server %s partition %s: %lu \n",
3664 as->parms[0].items->data, pname,
3665 (unsigned long)count);
3666 if (wantExtendedInfo) {
3667 #ifdef FULL_LISTVOL_SWITCH
3668 if (as->parms[6].items)
3669 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3670 count, int32list, fast, quiet);
3672 #endif /* FULL_LISTVOL_SWITCH */
3673 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3674 count, int32list, fast, quiet);
3677 xInfoP = (volintXInfo *) 0;
3679 #ifdef FULL_LISTVOL_SWITCH
3680 if (as->parms[6].items)
3681 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3684 #endif /* FULL_LISTVOL_SWITCH */
3685 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3686 count, int32list, fast, quiet);
3689 pntr = (volintInfo *) 0;
3698 register struct cmd_syndesc *as;
3700 afs_int32 pnum = 0, code; /* part name */
3706 if (as->parms[0].items) {
3707 tserver = GetServer(as->parms[0].items->data);
3709 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3710 as->parms[0].items->data);
3715 if (as->parms[1].items) {
3716 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3718 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3719 as->parms[1].items->data);
3722 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3724 PrintError("", code);
3727 "vos: partition %s does not exist on the server\n",
3728 as->parms[1].items->data);
3735 "The -partition option requires a -server option\n");
3740 if (as->parms[2].items) {
3741 /* Synchronize an individual volume */
3742 volname = as->parms[2].items->data;
3743 code = UV_SyncVolume(tserver, pnum, volname, flags);
3747 "Without a -volume option, the -server option is required\n");
3750 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3754 PrintDiagnostics("syncvldb", code);
3758 /* Print a summary of what we did */
3760 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3762 fprintf(STDOUT, "VLDB synchronized");
3764 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3767 MapPartIdIntoName(pnum, part);
3768 fprintf(STDOUT, " partition %s\n", part);
3770 fprintf(STDOUT, "\n");
3777 register struct cmd_syndesc *as;
3780 afs_int32 pnum, code; /* part name */
3785 tserver = GetServer(as->parms[0].items->data);
3787 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3788 as->parms[0].items->data);
3791 if (as->parms[1].items) {
3792 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3794 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3795 as->parms[1].items->data);
3798 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3800 PrintError("", code);
3803 "vos : partition %s does not exist on the server\n",
3804 as->parms[1].items->data);
3812 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3814 PrintDiagnostics("syncserv", code);
3818 MapPartIdIntoName(pnum, part);
3819 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3820 as->parms[0].items->data, part);
3822 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3823 as->parms[0].items->data);
3832 struct nvldbentry entry;
3835 /* The vlserver will handle names with the .readonly
3836 * and .backup extension as well as volume ids.
3838 vcode = VLDB_GetEntryByName(name, &entry);
3840 PrintError("", vcode);
3843 MapHostToNetwork(&entry);
3844 EnumerateEntry(&entry);
3846 /* Defect #3027: grubby check to handle locked volume.
3847 * If VLOP_ALLOPERS is set, the entry is locked.
3848 * Leave this routine as is, but put in correct check.
3850 if (entry.flags & VLOP_ALLOPERS)
3851 fprintf(STDOUT, " Volume is currently LOCKED \n");
3858 register struct cmd_syndesc *as;
3861 struct nvldbentry entry;
3862 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3864 if (as->parms[3].items) {
3865 /* force flag is on, use the other version */
3866 return NukeVolume(as);
3869 if (as->parms[4].items) {
3873 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3876 PrintError("", err);
3878 fprintf(STDERR, "vos: can't find volume '%s'\n",
3879 as->parms[2].items->data);
3882 part = volutil_GetPartitionID(as->parms[1].items->data);
3884 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3885 as->parms[1].items->data);
3888 server = GetServer(as->parms[0].items->data);
3890 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3891 as->parms[0].items->data);
3894 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3896 PrintError("", code);
3899 "vos : partition %s does not exist on the server\n",
3900 as->parms[1].items->data);
3903 code = VLDB_GetEntryByID(volid, -1, &entry);
3905 if (volid == entry.volumeId[RWVOL])
3906 backupid = entry.volumeId[BACKVOL];
3908 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3909 (unsigned long)volid);
3912 volintInfo *pntr = (volintInfo *) 0;
3915 code = UV_ListOneVolume(server, part, volid, &pntr);
3917 if (volid == pntr->parentID)
3918 backupid = pntr->backupID;
3924 code = UV_VolumeZap(server, part, backupid);
3926 PrintDiagnostics("zap", code);
3929 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3930 (unsigned long)backupid);
3933 code = UV_VolumeZap(server, part, volid);
3935 PrintDiagnostics("zap", code);
3938 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3945 register struct cmd_syndesc *as;
3948 afs_int32 server, code;
3949 transDebugInfo *pntr, *oldpntr;
3954 server = GetServer(as->parms[0].items->data);
3956 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3957 as->parms[0].items->data);
3960 code = UV_VolserStatus(server, &pntr, &count);
3962 PrintDiagnostics("status", code);
3967 fprintf(STDOUT, "No active transactions on %s\n",
3968 as->parms[0].items->data);
3970 fprintf(STDOUT, "Total transactions: %d\n", count);
3972 for (i = 0; i < count; i++) {
3973 /*print out the relevant info */
3974 fprintf(STDOUT, "--------------------------------------\n");
3975 fprintf(STDOUT, "transaction: %lu created: %s",
3976 (unsigned long)pntr->tid, vos_ctime( & pntr->time));
3977 if (pntr->returnCode) {
3978 fprintf(STDOUT, "returnCode: %lu\n",
3979 (unsigned long)pntr->returnCode);
3982 fprintf(STDOUT, "attachFlags: ");
3983 switch (pntr->iflags) {
3985 fprintf(STDOUT, "offline ");
3988 fprintf(STDOUT, "busy ");
3991 fprintf(STDOUT, "readonly ");
3994 fprintf(STDOUT, "create ");
3997 fprintf(STDOUT, "create volid ");
4000 fprintf(STDOUT, "\n");
4003 fprintf(STDOUT, "volumeStatus: ");
4004 switch (pntr->vflags) {
4005 case VTDeleteOnSalvage:
4006 fprintf(STDOUT, "deleteOnSalvage ");
4007 case VTOutOfService:
4008 fprintf(STDOUT, "outOfService ");
4010 fprintf(STDOUT, "deleted ");
4012 fprintf(STDOUT, "\n");
4015 fprintf(STDOUT, "transactionFlags: ");
4016 fprintf(STDOUT, "delete\n");
4018 MapPartIdIntoName(pntr->partition, pname);
4019 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4020 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4021 if (pntr->callValid) {
4023 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
4024 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4025 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4028 fprintf(STDOUT, "--------------------------------------\n");
4029 fprintf(STDOUT, "\n");
4038 register struct cmd_syndesc *as;
4040 afs_int32 code1, code2, code;
4041 struct nvldbentry entry;
4043 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4045 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4046 as->parms[0].items->data);
4049 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4050 if ((!code1) && (!code2)) { /*the newname already exists */
4051 fprintf(STDERR, "vos: volume %s already exists\n",
4052 as->parms[1].items->data);
4056 if (code1 && code2) {
4057 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4058 as->parms[0].items->data, as->parms[1].items->data);
4061 if (!VolNameOK(as->parms[0].items->data)) {
4063 "Illegal volume name %s, should not end in .readonly or .backup\n",
4064 as->parms[0].items->data);
4067 if (!ISNAMEVALID(as->parms[1].items->data)) {
4069 "vos: the new volume name %s exceeds the size limit of %d\n",
4070 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4073 if (!VolNameOK(as->parms[1].items->data)) {
4075 "Illegal volume name %s, should not end in .readonly or .backup\n",
4076 as->parms[1].items->data);
4079 if (IsNumeric(as->parms[1].items->data)) {
4080 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4081 as->parms[1].items->data);
4084 MapHostToNetwork(&entry);
4086 UV_RenameVolume(&entry, as->parms[0].items->data,
4087 as->parms[1].items->data);
4089 PrintDiagnostics("rename", code);
4092 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4093 as->parms[1].items->data);
4097 GetVolumeInfo(volid, server, part, voltype, rentry)
4098 afs_int32 *server, volid, *part, *voltype;
4099 register struct nvldbentry *rentry;
4104 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4107 "Could not fetch the entry for volume %lu from VLDB \n",
4108 (unsigned long)volid);
4109 PrintError("", vcode);
4112 MapHostToNetwork(rentry);
4113 if (volid == rentry->volumeId[ROVOL]) {
4115 for (i = 0; i < rentry->nServers; i++) {
4116 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4117 && !(rentry->serverFlags[i] & RO_DONTUSE))
4122 "RO volume is not found in VLDB entry for volume %lu\n",
4123 (unsigned long)volid);
4127 *server = rentry->serverNumber[index];
4128 *part = rentry->serverPartition[index];
4132 index = Lp_GetRwIndex(rentry);
4135 "RW Volume is not found in VLDB entry for volume %lu\n",
4136 (unsigned long)volid);
4139 if (volid == rentry->volumeId[RWVOL]) {
4141 *server = rentry->serverNumber[index];
4142 *part = rentry->serverPartition[index];
4145 if (volid == rentry->volumeId[BACKVOL]) {
4147 *server = rentry->serverNumber[index];
4148 *part = rentry->serverPartition[index];
4152 "unexpected volume type for volume %lu\n",
4153 (unsigned long)volid);
4159 register struct cmd_syndesc *as;
4165 struct VldbListByAttributes attributes;
4166 nbulkentries arrayEntries;
4167 register struct nvldbentry *vllist;
4168 struct cmd_item *itp;
4171 char prefix[VOLSER_MAXVOLNAME + 1];
4173 afs_int32 totalBack = 0, totalFail = 0, err;
4175 if (as->parms[0].items) { /* -id */
4176 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4178 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4181 for (itp = as->parms[0].items; itp; itp = itp->next) {
4182 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4185 PrintError("", err);
4187 fprintf(STDERR, "vos: can't find volume '%s'\n",
4191 if (as->parms[4].items) { /* -noexecute */
4192 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4197 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4199 fprintf(STDERR, "Could not delete entry for volume %s\n",
4202 "You must specify a RW volume name or ID "
4203 "(the entire VLDB entry will be deleted)\n");
4204 PrintError("", vcode);
4210 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4214 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4215 fprintf(STDERR, "You must specify an option\n");
4219 /* Zero out search attributes */
4220 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4222 if (as->parms[1].items) { /* -prefix */
4223 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4225 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4227 "You must provide -server with the -prefix argument\n");
4232 if (as->parms[2].items) { /* -server */
4234 aserver = GetServer(as->parms[2].items->data);
4236 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4237 as->parms[2].items->data);
4240 attributes.server = ntohl(aserver);
4241 attributes.Mask |= VLLIST_SERVER;
4244 if (as->parms[3].items) { /* -partition */
4245 if (!as->parms[2].items) {
4247 "You must provide -server with the -partition argument\n");
4250 apart = volutil_GetPartitionID(as->parms[3].items->data);
4252 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4253 as->parms[3].items->data);
4256 attributes.partition = apart;
4257 attributes.Mask |= VLLIST_PARTITION;
4260 /* Print status line of what we are doing */
4261 fprintf(STDOUT, "Deleting VLDB entries for ");
4262 if (as->parms[2].items) {
4263 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4265 if (as->parms[3].items) {
4267 MapPartIdIntoName(apart, pname);
4268 fprintf(STDOUT, "partition %s ", pname);
4271 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4273 fprintf(STDOUT, "\n");
4276 /* Get all the VLDB entries on a server and/or partition */
4277 memset(&arrayEntries, 0, sizeof(arrayEntries));
4278 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4280 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4281 PrintError("", vcode);
4285 /* Process each entry */
4286 for (j = 0; j < nentries; j++) {
4287 vllist = &arrayEntries.nbulkentries_val[j];
4289 /* It only deletes the RW volumes */
4290 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4293 "Omitting to delete %s due to prefix %s mismatch\n",
4294 vllist->name, prefix);
4301 if (as->parms[4].items) { /* -noexecute */
4302 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4308 /* Only matches the RW volume name */
4309 avolid = vllist->volumeId[RWVOL];
4310 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4312 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4315 PrintError("", vcode);
4320 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4325 fprintf(STDOUT, "----------------------\n");
4327 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4328 (unsigned long)totalBack, (unsigned long)totalFail);
4329 if (arrayEntries.nbulkentries_val)
4330 free(arrayEntries.nbulkentries_val);
4336 CompareVldbEntryByName(p1, p2)
4339 struct nvldbentry *arg1, *arg2;
4341 arg1 = (struct nvldbentry *)p1;
4342 arg2 = (struct nvldbentry *)p2;
4343 return (strcmp(arg1->name, arg2->name));
4347 static int CompareVldbEntry(p1,p2)
4350 struct nvldbentry *arg1,*arg2;
4353 char comp1[100],comp2[100];
4354 char temp1[20],temp2[20];
4356 arg1 = (struct nvldbentry *)p1;
4357 arg2 = (struct nvldbentry *)p2;
4361 for(i = 0; i < arg1->nServers; i++)
4362 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4363 for(i = 0; i < arg2->nServers; i++)
4364 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4365 if(pos1 == -1 || pos2 == -1){
4369 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4370 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4371 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4372 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4373 strcat(comp1,temp1);
4374 strcat(comp2,temp2);
4375 strcat(comp1,arg1->name);
4376 strcat(comp1,arg2->name);
4377 return(strcmp(comp1,comp2));
4384 struct cmd_syndesc *as;
4387 afs_int32 aserver, code;
4389 struct VldbListByAttributes attributes;
4390 nbulkentries arrayEntries;
4391 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4392 afs_int32 centries, nentries = 0, tarraysize, parraysize;
4395 int quiet, sort, lock;
4396 afs_int32 thisindex, nextindex;
4401 attributes.Mask = 0;
4402 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4403 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4404 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4406 /* If the volume name is given, Use VolumeInfoCmd to look it up
4407 * and not ListAttributes.
4409 if (as->parms[0].items) {
4412 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4415 code = VolumeInfoCmd(as->parms[0].items->data);
4417 PrintError("", code);
4423 /* Server specified */
4424 if (as->parms[1].items) {
4425 aserver = GetServer(as->parms[1].items->data);
4427 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4428 as->parms[1].items->data);
4431 attributes.server = ntohl(aserver);
4432 attributes.Mask |= VLLIST_SERVER;
4435 /* Partition specified */
4436 if (as->parms[2].items) {
4437 apart = volutil_GetPartitionID(as->parms[2].items->data);
4439 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4440 as->parms[2].items->data);
4443 attributes.partition = apart;
4444 attributes.Mask |= VLLIST_PARTITION;
4448 attributes.Mask |= VLLIST_FLAG;
4449 attributes.flag = VLOP_ALLOPERS;
4452 /* Print header information */
4454 MapPartIdIntoName(apart, pname);
4455 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4456 (as->parms[1].items ? "server" : "all"),
4457 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4458 (as->parms[2].items ? " partition " : ""),
4459 (as->parms[2].items ? pname : ""),
4460 (lock ? "which are locked:" : ""));
4463 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4464 memset(&arrayEntries, 0, sizeof(arrayEntries));
4469 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4470 &arrayEntries, &nextindex);
4471 if (vcode == RXGEN_OPCODE) {
4472 /* Vlserver not running with ListAttributesN2. Fall back */
4474 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4478 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4479 PrintError("", vcode);
4482 nentries += centries;
4484 /* We don't sort, so just print the entries now */
4486 for (j = 0; j < centries; j++) { /* process each entry */
4487 vllist = &arrayEntries.nbulkentries_val[j];
4488 MapHostToNetwork(vllist);
4489 EnumerateEntry(vllist);
4491 if (vllist->flags & VLOP_ALLOPERS)
4492 fprintf(STDOUT, " Volume is currently LOCKED \n");
4496 /* So we sort. First we must collect all the entries and keep
4499 else if (centries > 0) {
4501 /* steal away the first bulk entries array */
4502 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4503 tarraysize = centries * sizeof(struct nvldbentry);
4504 arrayEntries.nbulkentries_val = 0;
4506 /* Grow the tarray to keep the extra entries */
4507 parraysize = (centries * sizeof(struct nvldbentry));
4509 (struct nvldbentry *)realloc(tarray,
4510 tarraysize + parraysize);
4513 "Could not allocate enough space for the VLDB entries\n");
4519 memcpy(((char *)tarray) + tarraysize,
4520 (char *)arrayEntries.nbulkentries_val, parraysize);
4521 tarraysize += parraysize;
4525 /* Free the bulk array */
4526 if (arrayEntries.nbulkentries_val) {
4527 free(arrayEntries.nbulkentries_val);
4528 arrayEntries.nbulkentries_val = 0;
4532 /* Here is where we now sort all the entries and print them */
4533 if (sort && (nentries > 0)) {
4534 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4535 CompareVldbEntryByName);
4536 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4537 MapHostToNetwork(vllist);
4538 EnumerateEntry(vllist);
4540 if (vllist->flags & VLOP_ALLOPERS)
4541 fprintf(STDOUT, " Volume is currently LOCKED \n");
4547 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4555 register struct cmd_syndesc *as;
4557 afs_int32 apart = 0, avolid;
4558 afs_int32 aserver = 0, code, aserver1, apart1;
4560 struct VldbListByAttributes attributes;
4561 nbulkentries arrayEntries;
4562 register struct nvldbentry *vllist;
4566 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4567 afs_int32 totalBack = 0;
4568 afs_int32 totalFail = 0;
4569 int previdx = -1, error, same;
4571 struct cmd_item *ti;
4575 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4576 attributes.Mask = 0;
4578 seenprefix = (as->parms[0].items ? 1 : 0);
4579 exclude = (as->parms[3].items ? 1 : 0);
4580 seenxprefix = (as->parms[4].items ? 1 : 0);
4581 noaction = (as->parms[5].items ? 1 : 0);
4583 if (as->parms[1].items) { /* -server */
4584 aserver = GetServer(as->parms[1].items->data);
4586 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4587 as->parms[1].items->data);
4590 attributes.server = ntohl(aserver);
4591 attributes.Mask |= VLLIST_SERVER;
4594 if (as->parms[2].items) { /* -partition */
4595 apart = volutil_GetPartitionID(as->parms[2].items->data);
4597 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4598 as->parms[2].items->data);
4601 attributes.partition = apart;
4602 attributes.Mask |= VLLIST_PARTITION;
4605 /* Check to make sure the prefix and xprefix expressions compile ok */
4607 for (ti = as->parms[0].items; ti; ti = ti->next) {
4608 if (strncmp(ti->data, "^", 1) == 0) {
4609 #ifdef HAVE_POSIX_REGEX
4613 code = regcomp(&re, ti->data, REG_NOSUB);
4615 regerror(code, &re, errbuf, sizeof errbuf);
4617 "Unrecognizable -prefix regular expression: '%s': %s\n",
4623 ccode = (char *)re_comp(ti->data);
4626 "Unrecognizable -prefix regular expression: '%s': %s\n",
4635 for (ti = as->parms[4].items; ti; ti = ti->next) {
4636 if (strncmp(ti->data, "^", 1) == 0) {
4637 #ifdef HAVE_POSIX_REGEX
4641 code = regcomp(&re, ti->data, REG_NOSUB);
4643 regerror(code, &re, errbuf, sizeof errbuf);
4645 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4651 ccode = (char *)re_comp(ti->data);
4654 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4663 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4664 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4666 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4667 PrintError("", vcode);
4671 if (as->parms[1].items || as->parms[2].items || verbose) {
4672 fprintf(STDOUT, "%s up volumes",
4673 (noaction ? "Would have backed" : "Backing"));
4675 if (as->parms[1].items) {
4676 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4677 } else if (as->parms[2].items) {
4678 fprintf(STDOUT, " for all servers");
4681 if (as->parms[2].items) {
4682 MapPartIdIntoName(apart, pname);
4683 fprintf(STDOUT, " partition %s", pname);
4686 if (seenprefix || (!seenprefix && seenxprefix)) {
4687 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4688 ex = (seenprefix ? exclude : !exclude);
4689 exp = (strncmp(ti->data, "^", 1) == 0);
4690 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4691 (exp ? "expression" : "prefix"), ti->data);
4692 for (ti = ti->next; ti; ti = ti->next) {
4693 exp = (strncmp(ti->data, "^", 1) == 0);
4694 printf(" %sor %s '%s'", (ex ? "n" : ""),
4695 (exp ? "expression" : "prefix"), ti->data);
4699 if (seenprefix && seenxprefix) {
4700 ti = as->parms[4].items;
4701 exp = (strncmp(ti->data, "^", 1) == 0);
4702 fprintf(STDOUT, " %swhich match %s '%s'",
4703 (exclude ? "adding those " : "removing those "),
4704 (exp ? "expression" : "prefix"), ti->data);
4705 for (ti = ti->next; ti; ti = ti->next) {
4706 exp = (strncmp(ti->data, "^", 1) == 0);
4707 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4711 fprintf(STDOUT, " .. ");
4713 fprintf(STDOUT, "\n");
4717 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4718 vllist = &arrayEntries.nbulkentries_val[j];
4721 for (ti = as->parms[0].items; ti; ti = ti->next) {
4722 if (strncmp(ti->data, "^", 1) == 0) {
4723 #ifdef HAVE_POSIX_REGEX
4727 /* XXX -- should just do the compile once! */
4728 code = regcomp(&re, ti->data, REG_NOSUB);
4730 regerror(code, &re, errbuf, sizeof errbuf);
4732 "Error in -prefix regular expression: '%s': %s\n",
4736 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4739 ccode = (char *)re_comp(ti->data);
4742 "Error in -prefix regular expression: '%s': %s\n",
4746 match = (re_exec(vllist->name) == 1);
4750 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4760 /* Without the -exclude flag: If it matches the prefix, then
4761 * check if we want to exclude any from xprefix.
4762 * With the -exclude flag: If it matches the prefix, then
4763 * check if we want to add any from xprefix.
4765 if (match && seenxprefix) {
4766 for (ti = as->parms[4].items; ti; ti = ti->next) {
4767 if (strncmp(ti->data, "^", 1) == 0) {
4768 #ifdef HAVE_POSIX_REGEX
4772 /* XXX -- should just do the compile once! */
4773 code = regcomp(&re, ti->data, REG_NOSUB);
4775 regerror(code, &re, errbuf, sizeof errbuf);
4777 "Error in -xprefix regular expression: '%s': %s\n",
4781 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4785 ccode = (char *)re_comp(ti->data);
4788 "Error in -xprefix regular expression: '%s': %s\n",
4792 if (re_exec(vllist->name) == 1) {
4798 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4808 match = !match; /* -exclude will reverse the match */
4810 continue; /* Skip if no match */
4812 /* Print list of volumes to backup */
4814 fprintf(STDOUT, " %s\n", vllist->name);
4818 if (!(vllist->flags & RW_EXISTS)) {
4821 "Omitting to backup %s since RW volume does not exist \n",
4823 fprintf(STDOUT, "\n");
4829 avolid = vllist->volumeId[RWVOL];
4830 MapHostToNetwork(vllist);
4831 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4832 if (aserver1 == -1 || apart1 == -1) {
4833 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4839 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4842 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4848 if ((aserver && !same) || (apart && (apart != apart1))) {
4851 "Omitting to backup %s since the RW is in a different location\n",
4857 time_t now = time(0);
4858 fprintf(STDOUT, "Creating backup volume for %s on %s",
4859 vllist->name, ctime(&now));
4863 code = UV_BackupVolume(aserver1, apart1, avolid);
4865 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4871 fprintf(STDOUT, "\n");
4873 } /* process each vldb entry */
4874 fprintf(STDOUT, "done\n");
4875 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4876 (unsigned long)totalBack, (unsigned long)totalFail);
4878 if (arrayEntries.nbulkentries_val)
4879 free(arrayEntries.nbulkentries_val);
4885 register struct cmd_syndesc *as;
4888 afs_int32 aserver, code;
4890 struct VldbListByAttributes attributes;
4891 nbulkentries arrayEntries;
4892 register struct nvldbentry *vllist;
4901 attributes.Mask = 0;
4903 if (as->parms[0].items) { /* server specified */
4904 aserver = GetServer(as->parms[0].items->data);
4906 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4907 as->parms[0].items->data);
4910 attributes.server = ntohl(aserver);
4911 attributes.Mask |= VLLIST_SERVER;
4913 if (as->parms[1].items) { /* partition specified */
4914 apart = volutil_GetPartitionID(as->parms[1].items->data);
4916 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4917 as->parms[1].items->data);
4920 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4922 PrintError("", code);
4925 "vos : partition %s does not exist on the server\n",
4926 as->parms[1].items->data);
4929 attributes.partition = apart;
4930 attributes.Mask |= VLLIST_PARTITION;
4932 attributes.flag = VLOP_ALLOPERS;
4933 attributes.Mask |= VLLIST_FLAG;
4934 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4935 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4937 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4938 PrintError("", vcode);
4941 for (j = 0; j < nentries; j++) { /* process each entry */
4942 vllist = &arrayEntries.nbulkentries_val[j];
4943 volid = vllist->volumeId[RWVOL];
4945 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4946 LOCKREL_OPCODE | LOCKREL_AFSID |
4949 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4951 PrintError("", vcode);
4956 MapPartIdIntoName(apart, pname);
4959 "Could not lock %lu VLDB entries of %lu locked entries\n",
4960 (unsigned long)totalE, (unsigned long)nentries);
4962 if (as->parms[0].items) {
4964 "Unlocked all the VLDB entries for volumes on server %s ",
4965 as->parms[0].items->data);
4966 if (as->parms[1].items) {
4967 MapPartIdIntoName(apart, pname);
4968 fprintf(STDOUT, "partition %s\n", pname);
4970 fprintf(STDOUT, "\n");
4972 } else if (as->parms[1].items) {
4973 MapPartIdIntoName(apart, pname);
4975 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4980 if (arrayEntries.nbulkentries_val)
4981 free(arrayEntries.nbulkentries_val);
4986 PrintInt64Size(afs_uint64 in)
4988 register afs_uint32 hi, lo;
4989 register char * units;
4990 static char output[16];
4992 SplitInt64(in,hi,lo);
4996 } else if (!(hi & 0xFFFFFC00)) {
4998 lo = (hi << 22) | (lo >> 10);
4999 } else if (!(hi & 0xFFF00000)) {
5001 lo = (hi << 12) | (lo >> 20);
5002 } else if (!(hi & 0xC0000000)) {
5004 lo = (hi << 2) | (lo >> 30);
5009 sprintf(output,"%u %s", lo, units);
5015 register struct cmd_syndesc *as;
5018 afs_int32 aserver, code;
5020 struct diskPartition partition;
5021 struct partList dummyPartList;
5023 int printSummary=0, sumPartitions=0;
5024 afs_uint64 sumFree, sumStorage, tmp;
5027 ZeroInt64(sumStorage);
5029 aserver = GetServer(as->parms[0].items->data);
5031 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5032 as->parms[0].items->data);
5035 if (as->parms[1].items) {
5036 apart = volutil_GetPartitionID(as->parms[1].items->data);
5038 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5039 as->parms[1].items->data);
5042 dummyPartList.partId[0] = apart;
5043 dummyPartList.partFlags[0] = PARTVALID;
5046 if (as->parms[2].items) {
5050 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5052 PrintError("", code);
5055 "vos : partition %s does not exist on the server\n",
5056 as->parms[1].items->data);
5060 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5062 PrintDiagnostics("listpart", code);
5066 for (i = 0; i < cnt; i++) {
5067 if (dummyPartList.partFlags[i] & PARTVALID) {
5068 MapPartIdIntoName(dummyPartList.partId[i], pname);
5069 code = UV_PartitionInfo(aserver, pname, &partition);
5071 fprintf(STDERR, "Could not get information on partition %s\n",
5073 PrintError("", code);
5077 "Free space on partition %s: %d K blocks out of total %d\n",
5078 pname, partition.free, partition.minFree);
5080 FillInt64(tmp,0,partition.free);
5081 AddUInt64(sumFree,tmp,&sumFree);
5082 FillInt64(tmp,0,partition.minFree);
5083 AddUInt64(sumStorage,tmp,&sumStorage);
5088 "Summary: %s free out of ",
5089 PrintInt64Size(sumFree));
5091 "%s on %d partitions\n",
5092 PrintInt64Size(sumStorage),
5100 register struct cmd_syndesc *as;
5103 afs_int32 ip1, ip2, vcode;
5106 ip1 = GetServer(as->parms[0].items->data);
5108 fprintf(STDERR, "vos: invalid host address\n");
5112 if ((as->parms[1].items && as->parms[2].items)
5113 || (!as->parms[1].items && !as->parms[2].items)) {
5115 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5119 if (as->parms[1].items) {
5120 ip2 = GetServer(as->parms[1].items->data);
5122 fprintf(STDERR, "vos: invalid host address\n");
5126 /* Play a trick here. If we are removing an address, ip1 will be -1
5127 * and ip2 will be the original address. This switch prevents an
5128 * older revision vlserver from removing the IP address.
5135 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
5138 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5139 as->parms[0].items->data);
5140 if (vcode == VL_NOENT) {
5142 "vlserver does not support the remove flag or ");
5145 fprintf(STDERR, "Could not change server %s to server %s\n",
5146 as->parms[0].items->data, as->parms[1].items->data);
5148 PrintError("", vcode);
5153 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5154 as->parms[0].items->data);
5156 fprintf(STDOUT, "Changed server %s to server %s\n",
5157 as->parms[0].items->data, as->parms[1].items->data);
5163 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
5164 int print, int noresolve)
5168 struct VLCallBack vlcb;
5171 ListAddrByAttributes m_attrs;
5172 afs_int32 m_nentries, *m_addrp;
5173 afs_int32 base, index;
5177 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5178 printf("UUID: %s\n", buf);
5181 /* print out the list of all the server */
5182 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5183 for (i = 0; i < nentries; i++, addrp++) {
5184 /* If it is a multihomed address, then we will need to
5185 * get the addresses for this multihomed server from
5186 * the vlserver and print them.
5188 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5189 /* Get the list of multihomed fileservers */
5190 base = (*addrp >> 16) & 0xff;
5191 index = (*addrp) & 0xffff;
5193 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5194 && (index <= VL_MHSRV_PERBLK)) {
5195 m_attrs.Mask = VLADDR_INDEX;
5196 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5198 m_addrs.bulkaddrs_val = 0;
5199 m_addrs.bulkaddrs_len = 0;
5201 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, &m_uuid,
5202 &vlcb, &m_nentries, &m_addrs);
5205 "vos: could not list the multi-homed server addresses\n");
5206 PrintError("", vcode);
5209 /* Print the list */
5210 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5211 for (j = 0; j < m_nentries; j++, m_addrp++) {
5212 *m_addrp = htonl(*m_addrp);
5215 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5217 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5221 printf("<unknown>\n");
5230 /* Otherwise, it is a non-multihomed entry and contains
5231 * the IP address of the server - print it.
5233 *addrp = htonl(*addrp);
5236 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5238 printf("%s\n", hostutil_GetNameByINet(*addrp));
5250 register struct cmd_syndesc *as;
5253 afs_int32 i, noresolve = 0, printuuid = 0;
5254 struct VLCallBack vlcb;
5257 ListAddrByAttributes m_attrs;
5258 afsUUID m_uuid, askuuid;
5259 afs_int32 m_nentries;
5261 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5262 m_attrs.Mask = VLADDR_INDEX;
5264 memset(&m_addrs, 0, sizeof(bulkaddrs));
5265 memset(&askuuid, 0, sizeof(afsUUID));
5266 if (as->parms[0].items) {
5268 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5269 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5270 as->parms[0].items->data);
5273 m_attrs.Mask = VLADDR_UUID;
5274 m_attrs.uuid = askuuid;
5276 if (as->parms[1].items) {
5280 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5282 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5283 as->parms[1].items->data);
5286 memcpy(&saddr, he->h_addr, 4);
5287 m_attrs.Mask = VLADDR_IPADDR;
5288 m_attrs.ipaddr = ntohl(saddr);
5290 if (as->parms[2].items) {
5293 if (as->parms[3].items) {
5297 m_addrs.bulkaddrs_val = 0;
5298 m_addrs.bulkaddrs_len = 0;
5301 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries,
5304 fprintf(STDERR, "vos: could not list the server addresses\n");
5305 PrintError("", vcode);
5310 m_addrs.bulkaddrs_val = 0;
5311 m_addrs.bulkaddrs_len = 0;
5317 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
5318 &vlcb, &m_nentries, &m_addrs);
5320 if (vcode == VL_NOENT) {
5321 if (m_attrs.Mask == VLADDR_UUID) {
5322 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5323 as->parms[0].items->data);
5325 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5326 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5327 as->parms[1].items->data, m_attrs.ipaddr);
5336 if (vcode == VL_INDEXERANGE) {
5341 fprintf(STDERR, "vos: could not list the server addresses\n");
5342 PrintError("", vcode);
5346 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
5349 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5358 register struct cmd_syndesc *as;
5361 afs_int32 avolid, vcode, err;
5363 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5366 PrintError("", err);
5368 fprintf(STDERR, "vos: can't find volume '%s'\n",
5369 as->parms[0].items->data);
5372 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5374 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5375 as->parms[0].items->data);
5376 PrintError("", vcode);
5379 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5380 as->parms[0].items->data);
5386 register struct cmd_syndesc *as;
5389 afs_int32 partition = -1;
5390 afs_int32 server, volid, code, i, same;
5391 struct nvldbentry entry, storeEntry;
5394 afs_int32 rwserver = 0;
5395 afs_int32 rwpartition;
5397 afs_int32 roserver = 0;
5398 afs_int32 ropartition;
5400 struct rx_connection *aconn;
5403 server = GetServer(as->parms[0].items->data);
5405 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5406 as->parms[0].items->data);
5409 partition = volutil_GetPartitionID(as->parms[1].items->data);
5410 if (partition < 0) {
5411 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5412 as->parms[1].items->data);
5415 if (!IsPartValid(partition, server, &code)) {
5417 PrintError("", code);
5420 "vos : partition %s does not exist on the server\n",
5421 as->parms[1].items->data);
5424 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5427 PrintError("", code);
5429 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5430 as->parms[0].items->data);
5433 if (as->parms[3].items)
5436 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5439 "Could not fetch the entry for volume %lu from VLDB\n",
5440 (unsigned long)volid);
5441 PrintError("convertROtoRW", code);
5445 /* use RO volid even if user specified RW or BK volid */
5447 if (volid != entry.volumeId[ROVOL])
5448 volid = entry.volumeId[ROVOL];
5450 MapHostToNetwork(&entry);
5451 for (i = 0; i < entry.nServers; i++) {
5452 if (entry.serverFlags[i] & ITSRWVOL) {
5454 rwserver = entry.serverNumber[i];
5455 rwpartition = entry.serverPartition[i];
5457 if (entry.serverFlags[i] & ITSROVOL) {
5458 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5461 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5467 roserver = entry.serverNumber[i];
5468 ropartition = entry.serverPartition[i];
5474 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5476 if (ropartition != partition) {
5478 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5479 ropartition, partition);
5484 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5485 hostutil_GetNameByINet(rwserver),
5486 volutil_PartitionName(rwpartition));
5488 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5490 while (!(dc == EOF || dc == '\n'))
5491 dc = getchar(); /* goto end of line */
5492 if ((c != 'y') && (c != 'Y')) {
5493 fprintf(STDERR, "aborted.\n");
5500 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5502 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5503 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5506 "Converting RO volume %lu to RW volume failed with code %d\n",
5507 (unsigned long)volid, code);
5508 PrintError("convertROtoRW ", code);
5511 entry.serverFlags[roindex] = ITSRWVOL;
5512 entry.flags |= RW_EXISTS;
5513 entry.flags &= ~BACK_EXISTS;
5516 if (rwindex != entry.nServers) {
5517 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5518 entry.serverPartition[rwindex] =
5519 entry.serverPartition[entry.nServers];
5520 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5521 entry.serverNumber[entry.nServers] = 0;
5522 entry.serverPartition[entry.nServers] = 0;
5523 entry.serverFlags[entry.nServers] = 0;
5526 entry.flags &= ~RO_EXISTS;
5527 for (i = 0; i < entry.nServers; i++) {
5528 if (entry.serverFlags[i] & ITSROVOL) {
5529 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5530 entry.flags |= RO_EXISTS;
5533 MapNetworkToHost(&entry, &storeEntry);
5535 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5536 (LOCKREL_OPCODE | LOCKREL_AFSID |
5537 LOCKREL_TIMESTAMP));
5540 "Warning: volume converted, but vldb update failed with code %d!\n",
5543 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5545 PrintDiagnostics("unlock", vcode);
5552 register struct cmd_syndesc *as;
5554 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
5555 struct nvldbentry entry;
5556 volintSize vol_size;
5558 rx_SetRxDeadTime(60 * 10);
5559 for (i = 0; i < MAXSERVERS; i++) {
5560 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5563 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5564 if (rxConn->service)
5565 rxConn->service->connDeadTime = rx_connDeadTime;
5568 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5571 PrintError("", err);
5573 fprintf(STDERR, "vos: can't find volume '%s'\n",
5574 as->parms[0].items->data);
5578 if (as->parms[1].items || as->parms[2].items) {
5579 if (!as->parms[1].items || !as->parms[2].items) {
5581 "Must specify both -server and -partition options\n");
5584 aserver = GetServer(as->parms[2].items->data);
5586 fprintf(STDERR, "Invalid server name\n");
5589 apart = volutil_GetPartitionID(as->parms[1].items->data);
5591 fprintf(STDERR, "Invalid partition name\n");
5595 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5602 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5603 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5605 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5606 as->parms[4].items->data, code);
5611 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5613 if (as->parms[3].items) { /* do the dump estimate */
5614 #ifdef AFS_64BIT_ENV
5615 vol_size.dump_size = 0;
5617 FillInt64(vol_size.dump_size,0, 1);
5619 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5621 PrintDiagnostics("size", code);
5624 /* presumably the size info is now gathered in pntr */
5625 /* now we display it */
5627 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5635 PrintDiagnostics(astring, acode)
5639 if (acode == EACCES) {
5641 "You are not authorized to perform the 'vos %s' command (%d)\n",
5644 fprintf(STDERR, "Error in vos %s command.\n", astring);
5645 PrintError("", acode);
5652 MyBeforeProc(as, arock)
5653 struct cmd_syndesc *as;
5656 register char *tcell;
5657 register afs_int32 code;
5658 register afs_int32 sauth;
5660 /* Initialize the ubik_client connection */
5661 rx_SetRxDeadTime(90);
5662 cstruct = (struct ubik_client *)0;
5666 if (as->parms[12].items) /* if -cell specified */
5667 tcell = as->parms[12].items->data;
5668 if (as->parms[14].items) /* -serverauth specified */
5670 if (as->parms[16].items) /* -crypt specified */
5673 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5674 &cstruct, UV_SetSecurity))) {
5675 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5676 (unsigned long)code);
5680 if (as->parms[15].items) /* -verbose flag set */
5690 /* this sucks but it works for now.
5695 #include "AFS_component_version_number.c"
5701 register afs_int32 code;
5703 register struct cmd_syndesc *ts;
5705 #ifdef AFS_AIX32_ENV
5707 * The following signal action for AIX is necessary so that in case of a
5708 * crash (i.e. core is generated) we can include the user's data section
5709 * in the core dump. Unfortunately, by default, only a partial core is
5710 * generated which, in many cases, isn't too useful.
5712 struct sigaction nsa;
5714 sigemptyset(&nsa.sa_mask);
5715 nsa.sa_handler = SIG_DFL;
5716 nsa.sa_flags = SA_FULLDUMP;
5717 sigaction(SIGSEGV, &nsa, NULL);
5720 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5722 cmd_SetBeforeProc(MyBeforeProc, NULL);
5724 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
5725 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5726 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5727 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5728 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5729 "initial quota (KB)");
5731 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5735 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
5736 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5737 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5738 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5742 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
5743 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5744 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5745 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5746 "partition name on source");
5747 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5748 "machine name on destination");
5749 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5750 "partition name on destination");
5751 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5752 "copy live volume without cloning");
5755 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
5756 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5757 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5758 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5759 "partition name on source");
5760 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5761 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5762 "machine name on destination");
5763 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5764 "partition name on destination");
5765 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5766 "leave new volume offline");
5767 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5768 "make new volume read-only");
5769 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5770 "copy live volume without cloning");
5773 ts = cmd_CreateSyntax("shadow", ShadowVolume, 0,
5774 "make or update a shadow volume");
5775 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5776 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5777 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5778 "partition name on source");
5779 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5780 "machine name on destination");
5781 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5782 "partition name on destination");
5783 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5784 "volume name on destination");
5785 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5786 "volume ID on destination");
5787 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5788 "leave shadow volume offline");
5789 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5790 "make shadow volume read-only");
5791 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5792 "copy live volume without cloning");
5793 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5794 "do incremental update if target exists");
5797 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
5798 "make backup of a volume");
5799 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5802 ts = cmd_CreateSyntax("clone", CloneVolume, 0,
5803 "make clone of a volume");
5804 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5805 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5806 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5807 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5808 "volume name on destination");
5809 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5810 "volume ID on destination");
5811 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5812 "leave clone volume offline");
5813 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5814 "make clone volume read-only, not readwrite");
5817 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
5818 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5819 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5820 "force a complete release");
5823 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
5824 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5825 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5826 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5827 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5828 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5829 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5830 "dump a clone of the volume");
5831 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5832 "omit unchanged directories from an incremental dump");
5835 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
5836 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5837 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5838 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5839 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5840 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5841 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5842 "abort | full | incremental");
5843 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5844 "leave restored volume offline");
5845 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5846 "make restored volume read-only");
5847 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
5848 "dump | keep | new");
5849 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
5850 "dump | keep | new");
5853 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
5854 "release lock on VLDB entry for a volume");
5855 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5858 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
5859 "change an RW volume's location in the VLDB");
5860 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5861 "machine name for new location");
5862 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5863 "partition name for new location");
5864 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5867 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5868 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5869 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5870 "partition name for new site");
5871 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5874 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5875 "remove a replication site");
5876 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5877 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5878 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5881 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5882 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5885 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5886 "list volumes on server (bypass VLDB)");
5887 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5888 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5889 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5890 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5891 "list all normal volume fields");
5892 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5893 "generate minimal information");
5894 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5895 "list extended volume fields");
5896 #ifdef FULL_LISTVOL_SWITCH
5897 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5898 "machine readable format");
5899 #endif /* FULL_LISTVOL_SWITCH */
5902 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5903 "synchronize VLDB with server");
5904 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5905 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5906 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5909 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5910 "synchronize server with VLDB");
5911 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5912 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5915 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5916 "everything about the volume");
5917 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5918 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5919 "list extended volume fields");
5920 #ifdef FULL_LISTVOL_SWITCH
5921 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5922 "machine readable format");
5923 #endif /* FULL_LISTVOL_SWITCH */
5925 cmd_CreateAlias(ts, "volinfo");
5927 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5928 "change volume info fields");
5929 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5930 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5931 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5932 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
5935 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5936 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5937 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5938 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5939 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5940 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5943 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5944 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5945 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5946 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5949 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5950 "delete the volume, don't bother with VLDB");
5951 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5952 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5953 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5954 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5955 "force deletion of bad volumes");
5956 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5957 "also delete backup volume if one is found");
5960 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5961 "report on volser status");
5962 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5965 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5966 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5967 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5970 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5971 "list volumes in the VLDB");
5972 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5973 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5974 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5975 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5976 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5977 "generate minimal information");
5978 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5979 "do not alphabetically sort the volume names");
5982 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5983 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5984 "common prefix on volume(s)");
5985 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5986 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5987 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5988 "exclude common prefix volumes");
5989 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5990 "negative prefix on volume(s)");
5991 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5994 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5995 "delete VLDB entry for a volume");
5996 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5997 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5998 "prefix of the volume whose VLDB entry is to be deleted");
5999 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6000 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6001 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
6005 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
6006 "list partition information");
6007 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6008 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6009 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6010 "print storage summary");
6013 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
6014 "unlock all the locked entries in the VLDB");
6015 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6016 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6019 ts = cmd_CreateSyntax("lock", LockEntry, 0,
6020 "lock VLDB entry for a volume");
6021 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6024 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
6025 "change the IP address of a file server");
6026 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6027 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6028 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6029 "remove the IP address from the VLDB");
6032 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
6033 "list the IP address of all file servers registered in the VLDB");
6034 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6035 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6036 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
6037 "don't resolve addresses");
6038 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6039 "print uuid of hosts");
6042 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
6043 "convert a RO volume into a RW volume (after loss of old RW volume)");
6044 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6045 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6046 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6047 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6050 ts = cmd_CreateSyntax("size", Sizes, 0,
6051 "obtain various sizes of the volume.");
6052 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6053 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6054 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6055 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6056 "Obtain the size of the dump");
6057 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6060 code = cmd_Dispatch(argc, argv);
6062 /* Shut down the ubik_client and rx connections */
6064 (void)ubik_ClientDestroy(cstruct);
6070 exit((code ? -1 : 0));