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>
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
17 #include <sys/types.h>
23 #include <WINNT/afsreg.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
33 #include <sys/statfs.h>
41 #include <rx/rx_globals.h>
43 #include <afs/vlserver.h>
44 #include <afs/cellconfig.h>
46 #include <afs/afsutil.h>
48 #include <afs/afsint.h>
53 #include <afs/ihandle.h>
54 #include <afs/vnode.h>
55 #include <afs/volume.h>
56 #include <afs/com_err.h>
63 #include "volser_internal.h"
64 #include "volser_prototypes.h"
65 #include "vsutils_prototypes.h"
66 #include "lockprocs_prototypes.h"
68 #ifdef HAVE_POSIX_REGEX
72 /* Local Prototypes */
73 int PrintDiagnostics(char *astring, afs_int32 acode);
74 int GetVolumeInfo(afs_uint32 volid, afs_int32 *server, afs_int32 *part,
75 afs_int32 *voltype, struct nvldbentry *rentry);
87 #define COMMONPARMS cmd_Seek(ts, 12);\
88 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
89 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
90 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
91 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
92 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
93 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
95 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
98 struct rx_connection *tconn;
100 extern struct ubik_client *cstruct;
103 static struct tqHead busyHead, notokHead;
106 qInit(struct tqHead *ahead)
108 memset(ahead, 0, sizeof(struct tqHead));
114 qPut(struct tqHead *ahead, afs_uint32 volid)
118 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
119 elem->next = ahead->next;
127 qGet(struct tqHead *ahead, afs_uint32 *volid)
131 if (ahead->count <= 0)
133 *volid = ahead->next->volid;
135 ahead->next = tmp->next;
141 /* returns 1 if <filename> exists else 0 */
143 FileExists(char *filename)
149 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
153 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
161 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
163 VolNameOK(char *name)
168 total = strlen(name);
169 if (!strcmp(&name[total - 9], ".readonly")) {
171 } else if (!strcmp(&name[total - 7], ".backup")) {
178 /* return 1 if name is a number else 0 */
180 IsNumeric(char *name)
188 for (i = 0; i < len; i++) {
189 if (*ptr < '0' || *ptr > '9') {
201 * Parse a server name/address and return the address in HOST BYTE order
204 GetServer(char *aname)
206 register struct hostent *th;
209 register afs_int32 code;
210 char hostname[MAXHOSTCHARS];
212 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
214 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
215 addr = ntohl(addr); /* convert to host order */
217 th = gethostbyname(aname);
220 memcpy(&addr, th->h_addr, sizeof(addr));
223 if (addr == htonl(0x7f000001)) { /* local host */
224 code = gethostname(hostname, MAXHOSTCHARS);
227 th = gethostbyname(hostname); /* returns host byte order */
230 memcpy(&addr, th->h_addr, sizeof(addr));
237 GetVolumeType(char *aname)
240 if (!strcmp(aname, "ro"))
242 else if (!strcmp(aname, "rw"))
244 else if (!strcmp(aname, "bk"))
251 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
253 struct partList dummyPartList;
259 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
262 for (i = 0; i < cnt; i++) {
263 if (dummyPartList.partFlags[i] & PARTVALID)
264 if (dummyPartList.partId[i] == partId)
272 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
273 * associated with <call> */
275 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
277 char *buffer = (char *)0;
282 buffer = (char *)malloc(blksize);
284 fprintf(STDERR, "malloc failed\n");
288 while (!error && !done) {
289 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
292 FD_SET((intptr_t)(ufd->handle), &in);
293 /* don't timeout if read blocks */
294 #if defined(AFS_PTHREAD_ENV)
295 select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
297 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
300 error = USD_READ(ufd, buffer, blksize, &nbytes);
302 fprintf(STDERR, "File system read failed: %s\n",
303 afs_error_message(error));
310 if (rx_Write(call, buffer, nbytes) != nbytes) {
320 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
321 * writes it out to the volume. */
323 WriteData(struct rx_call *call, void *rock)
325 char *filename = (char *) rock;
328 afs_int32 error, code;
330 afs_hyper_t filesize, currOffset;
336 if (!filename || !*filename) {
337 usd_StandardInput(&ufd);
341 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
344 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
347 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
348 afs_error_message(code));
352 /* test if we have a valid dump */
353 hset64(filesize, 0, 0);
354 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
355 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
356 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
357 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
358 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
359 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
363 /* rewind, we are done */
364 hset64(filesize, 0, 0);
365 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
367 code = SendFile(ufd, call, blksize);
374 code = USD_CLOSE(ufd);
376 fprintf(STDERR, "Could not close dump file %s\n",
377 (filename && *filename) ? filename : "STDOUT");
385 /* Receive data from <call> stream into file associated
386 * with <fd> <blksize>
389 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
393 afs_uint32 bytesleft, w;
396 buffer = (char *)malloc(blksize);
398 fprintf(STDERR, "memory allocation failed\n");
402 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
403 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
404 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
407 FD_SET((intptr_t)(ufd->handle), &out);
408 /* don't timeout if write blocks */
409 #if defined(AFS_PTHREAD_ENV)
410 select(((int)(ufd->handle)) + 1, &out, 0, 0, 0);
412 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
416 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
418 fprintf(STDERR, "File system write failed: %s\n",
419 afs_error_message(error));
432 DumpFunction(struct rx_call *call, void *rock)
434 char *filename = (char *)rock;
435 usd_handle_t ufd; /* default is to stdout */
436 afs_int32 error = 0, code;
441 /* Open the output file */
442 if (!filename || !*filename) {
443 usd_StandardOutput(&ufd);
448 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
452 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
455 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
458 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
459 afs_error_message(code));
460 ERROR_EXIT(VOLSERBADOP);
464 code = ReceiveFile(ufd, call, blksize);
469 /* Close the output file */
471 code = USD_CLOSE(ufd);
473 fprintf(STDERR, "Could not close dump file %s\n",
474 (filename && *filename) ? filename : "STDIN");
484 DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
485 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
486 int longlist, int disp)
492 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
493 } else if (longlist) {
494 if (pntr->status == VOK) {
495 fprintf(STDOUT, "%-32s ", pntr->name);
496 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
498 fprintf(STDOUT, "RW ");
500 fprintf(STDOUT, "RO ");
502 fprintf(STDOUT, "BK ");
503 fprintf(STDOUT, "%10d K ", pntr->size);
504 if (pntr->inUse == 1) {
505 fprintf(STDOUT, "On-line");
508 fprintf(STDOUT, "Off-line");
511 if (pntr->needsSalvaged == 1)
512 fprintf(STDOUT, "**needs salvage**");
513 fprintf(STDOUT, "\n");
514 MapPartIdIntoName(part, pname);
515 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
517 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
518 (unsigned long)pntr->parentID,
519 (unsigned long)pntr->cloneID,
520 (unsigned long)pntr->backupID);
521 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
522 t = pntr->creationDate;
523 fprintf(STDOUT, " Creation %s",
525 #ifdef FULL_LISTVOL_SWITCH
527 fprintf(STDOUT, " Copy %s",
530 t = pntr->backupDate;
532 fprintf(STDOUT, " Backup Never\n");
534 fprintf(STDOUT, " Backup %s",
537 t = pntr->accessDate;
539 fprintf(STDOUT, " Last Access %s",
542 t = pntr->updateDate;
544 fprintf(STDOUT, " Last Update Never\n");
546 fprintf(STDOUT, " Last Update %s",
549 " %d accesses in the past day (i.e., vnode references)\n",
551 } else if (pntr->status == VBUSY) {
553 qPut(&busyHead, pntr->volid);
555 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
556 (unsigned long)pntr->volid);
559 qPut(¬okHead, pntr->volid);
561 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
562 (unsigned long)pntr->volid);
564 fprintf(STDOUT, "\n");
565 } else { /* default listing */
566 if (pntr->status == VOK) {
567 fprintf(STDOUT, "%-32s ", pntr->name);
568 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
570 fprintf(STDOUT, "RW ");
572 fprintf(STDOUT, "RO ");
574 fprintf(STDOUT, "BK ");
575 fprintf(STDOUT, "%10d K ", pntr->size);
576 if (pntr->inUse == 1) {
577 fprintf(STDOUT, "On-line");
580 fprintf(STDOUT, "Off-line");
583 if (pntr->needsSalvaged == 1)
584 fprintf(STDOUT, "**needs salvage**");
585 fprintf(STDOUT, "\n");
586 } else if (pntr->status == VBUSY) {
588 qPut(&busyHead, pntr->volid);
590 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
591 (unsigned long)pntr->volid);
594 qPut(¬okHead, pntr->volid);
596 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
597 (unsigned long)pntr->volid);
602 /*------------------------------------------------------------------------
603 * PRIVATE XDisplayFormat
606 * Display the contents of one extended volume info structure.
609 * a_xInfoP : Ptr to extended volume info struct to print.
610 * a_servID : Server ID to print.
611 * a_partID : Partition ID to print.
612 * a_totalOKP : Ptr to total-OK counter.
613 * a_totalNotOKP : Ptr to total-screwed counter.
614 * a_totalBusyP : Ptr to total-busy counter.
615 * a_fast : Fast listing?
616 * a_int32 : Int32 listing?
617 * a_showProblems : Show volume problems?
623 * Nothing interesting.
627 *------------------------------------------------------------------------*/
630 XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
631 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
632 int a_fast, int a_int32, int a_showProblems)
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);
677 t = a_xInfoP->creationDate;
678 fprintf(STDOUT, " Creation %s",
680 #ifdef FULL_LISTVOL_SWITCH
681 t = a_xInfoP->copyDate;
682 fprintf(STDOUT, " Copy %s",
685 t = a_xInfoP->backupDate;
687 fprintf(STDOUT, " Backup Never\n");
689 fprintf(STDOUT, " Backup %s",
692 t = a_xInfoP->accessDate;
694 fprintf(STDOUT, " Last Access %s",
697 t = a_xInfoP->updateDate;
699 fprintf(STDOUT, " Last Update Never\n");
701 fprintf(STDOUT, " Last Update %s",
704 " %d accesses in the past day (i.e., vnode references)\n",
708 * Print all the read/write and authorship stats.
710 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
712 " |-------------------------------------------|\n");
714 " | Same Network | Diff Network |\n");
716 " |----------|----------|----------|----------|\n");
718 " | Total | Auth | Total | Auth |\n");
720 " |----------|----------|----------|----------|\n");
721 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
722 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
723 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
724 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
725 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
726 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
727 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
728 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
729 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
730 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
732 " |-------------------------------------------|\n\n");
735 " Writes Affecting Authorship\n");
737 " |-------------------------------------------|\n");
739 " | File Authorship | Directory Authorship|\n");
741 " |----------|----------|----------|----------|\n");
743 " | Same | Diff | Same | Diff |\n");
745 " |----------|----------|----------|----------|\n");
746 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
747 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
749 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
750 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
751 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
752 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
754 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
755 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
756 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
757 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
759 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
760 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
761 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
762 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
764 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
765 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
766 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
771 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
777 " |-------------------------------------------|\n");
778 } /*Volume status OK */
779 else if (a_xInfoP->status == VBUSY) {
781 qPut(&busyHead, a_xInfoP->volid);
783 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
784 (unsigned long)a_xInfoP->volid);
788 qPut(¬okHead, a_xInfoP->volid);
790 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
791 (unsigned long)a_xInfoP->volid);
792 } /*Screwed volume */
793 fprintf(STDOUT, "\n");
799 if (a_xInfoP->status == VOK) {
800 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
801 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
802 if (a_xInfoP->type == 0)
803 fprintf(STDOUT, "RW ");
804 if (a_xInfoP->type == 1)
805 fprintf(STDOUT, "RO ");
806 if (a_xInfoP->type == 2)
807 fprintf(STDOUT, "BK ");
808 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
809 if (a_xInfoP->inUse == 1) {
810 fprintf(STDOUT, "On-line");
813 fprintf(STDOUT, "Off-line");
816 fprintf(STDOUT, "\n");
818 else if (a_xInfoP->status == VBUSY) {
820 qPut(&busyHead, a_xInfoP->volid);
822 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
823 (unsigned long)a_xInfoP->volid);
827 qPut(¬okHead, a_xInfoP->volid);
829 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
830 (unsigned long)a_xInfoP->volid);
831 } /*Screwed volume */
832 } /*Default listing */
833 } /*XDisplayFormat */
835 #ifdef FULL_LISTVOL_SWITCH
836 /*------------------------------------------------------------------------
837 * PRIVATE XDisplayFormat2
840 * Display the formated contents of one extended volume info structure.
843 * a_xInfoP : Ptr to extended volume info struct to print.
844 * a_servID : Server ID to print.
845 * a_partID : Partition ID to print.
846 * a_totalOKP : Ptr to total-OK counter.
847 * a_totalNotOKP : Ptr to total-screwed counter.
848 * a_totalBusyP : Ptr to total-busy counter.
849 * a_fast : Fast listing?
850 * a_int32 : Int32 listing?
851 * a_showProblems : Show volume problems?
857 * Nothing interesting.
861 *------------------------------------------------------------------------*/
864 XDisplayFormat2(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
865 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
866 int a_fast, int a_int32, int a_showProblems)
867 { /*XDisplayFormat */
873 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
874 } else if (a_int32) {
876 * Fully-detailed listing.
878 if (a_xInfoP->status == VOK) {
880 * Volume's status is OK - all the fields are valid.
883 static long server_cache = -1, partition_cache = -1;
884 static char hostname[256], address[32], pname[16];
885 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
886 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
888 if (a_servID != server_cache) {
892 strcpy(hostname, hostutil_GetNameByINet(a_servID));
893 strcpy(address, inet_ntoa(s));
894 server_cache = a_servID;
896 if (a_partID != partition_cache) {
897 MapPartIdIntoName(a_partID, pname);
898 partition_cache = a_partID;
901 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
902 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
903 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
904 fprintf(STDOUT, "part\t\t%s\n", pname);
905 fprintf(STDOUT, "status\t\tOK\n");
906 fprintf(STDOUT, "backupID\t%lu\n",
907 afs_printable_uint32_lu(a_xInfoP->backupID));
908 fprintf(STDOUT, "parentID\t%lu\n",
909 afs_printable_uint32_lu(a_xInfoP->parentID));
910 fprintf(STDOUT, "cloneID\t\t%lu\n",
911 afs_printable_uint32_lu(a_xInfoP->cloneID));
912 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
913 switch (a_xInfoP->type) {
915 fprintf(STDOUT, "type\t\tRW\n");
918 fprintf(STDOUT, "type\t\tRO\n");
921 fprintf(STDOUT, "type\t\tBK\n");
924 fprintf(STDOUT, "type\t\t?\n");
927 t = a_xInfoP->creationDate;
928 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
929 afs_printable_uint32_lu(a_xInfoP->creationDate),
932 t = a_xInfoP->accessDate;
933 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
934 afs_printable_uint32_lu(a_xInfoP->accessDate),
937 t = a_xInfoP->updateDate;
938 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
939 afs_printable_uint32_lu(a_xInfoP->updateDate),
942 t = a_xInfoP->backupDate;
943 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
944 afs_printable_uint32_lu(a_xInfoP->backupDate),
947 t = a_xInfoP->copyDate;
948 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
949 afs_printable_uint32_lu(a_xInfoP->copyDate),
952 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
953 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
955 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
956 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
960 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
961 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
962 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
963 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
965 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
966 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
967 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
968 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
972 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
973 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
974 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
975 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
978 } /*Volume status OK */
979 else if (a_xInfoP->status == VBUSY) {
981 qPut(&busyHead, a_xInfoP->volid);
983 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
984 (unsigned long)a_xInfoP->volid);
988 qPut(¬okHead, a_xInfoP->volid);
990 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
991 (unsigned long)a_xInfoP->volid);
992 } /*Screwed volume */
998 if (a_xInfoP->status == VOK) {
999 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1000 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1001 if (a_xInfoP->type == 0)
1002 fprintf(STDOUT, "type\tRW\n");
1003 if (a_xInfoP->type == 1)
1004 fprintf(STDOUT, "type\tRO\n");
1005 if (a_xInfoP->type == 2)
1006 fprintf(STDOUT, "type\tBK\n");
1007 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1009 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1010 if (a_xInfoP->inUse == 1)
1016 else if (a_xInfoP->status == VBUSY) {
1018 qPut(&busyHead, a_xInfoP->volid);
1020 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1021 (unsigned long)a_xInfoP->volid);
1025 qPut(¬okHead, a_xInfoP->volid);
1027 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1028 (unsigned long)a_xInfoP->volid);
1029 } /*Screwed volume */
1030 } /*Default listing */
1031 } /*XDisplayFormat */
1032 #endif /*FULL_LISTVOL_SWITCH*/
1034 #ifdef FULL_LISTVOL_SWITCH
1036 DisplayFormat2(long server, long partition, volintInfo *pntr)
1038 static long server_cache = -1, partition_cache = -1;
1039 static char hostname[256], address[32], pname[16];
1042 if (server != server_cache) {
1046 strcpy(hostname, hostutil_GetNameByINet(server));
1047 strcpy(address, inet_ntoa(s));
1048 server_cache = server;
1050 if (partition != partition_cache) {
1051 MapPartIdIntoName(partition, pname);
1052 partition_cache = partition;
1055 if (pntr->status == VOK)
1056 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1058 fprintf(STDOUT, "id\t\t%lu\n",
1059 afs_printable_uint32_lu(pntr->volid));
1060 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1061 fprintf(STDOUT, "part\t\t%s\n", pname);
1062 switch (pntr->status) {
1064 fprintf(STDOUT, "status\t\tOK\n");
1067 fprintf(STDOUT, "status\t\tBUSY\n");
1070 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1073 fprintf(STDOUT, "backupID\t%lu\n",
1074 afs_printable_uint32_lu(pntr->backupID));
1075 fprintf(STDOUT, "parentID\t%lu\n",
1076 afs_printable_uint32_lu(pntr->parentID));
1077 fprintf(STDOUT, "cloneID\t\t%lu\n",
1078 afs_printable_uint32_lu(pntr->cloneID));
1079 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1080 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1081 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1082 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1083 switch (pntr->type) {
1085 fprintf(STDOUT, "type\t\tRW\n");
1088 fprintf(STDOUT, "type\t\tRO\n");
1091 fprintf(STDOUT, "type\t\tBK\n");
1094 fprintf(STDOUT, "type\t\t?\n");
1097 t = pntr->creationDate;
1098 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1099 afs_printable_uint32_lu(pntr->creationDate),
1102 t = pntr->accessDate;
1103 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1104 afs_printable_uint32_lu(pntr->accessDate),
1107 t = pntr->updateDate;
1108 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1109 afs_printable_uint32_lu(pntr->updateDate),
1112 t = pntr->backupDate;
1113 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1114 afs_printable_uint32_lu(pntr->backupDate),
1118 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1119 afs_printable_uint32_lu(pntr->copyDate),
1122 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1123 afs_printable_uint32_lu(pntr->flags));
1124 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1125 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1126 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1127 afs_printable_uint32_lu(pntr->spare0));
1128 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1129 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1130 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1131 afs_printable_uint32_lu(pntr->spare1));
1132 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1133 afs_printable_uint32_lu(pntr->spare2));
1134 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1135 afs_printable_uint32_lu(pntr->spare3));
1140 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1144 for (i = 0; i < count; i++) {
1145 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1146 DisplayFormat2(server, partition, pntr);
1147 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1152 #endif /* FULL_LISTVOL_SWITCH */
1155 DisplayVolumes(afs_int32 server, afs_int32 part, volintInfo *pntr,
1156 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1159 int totalOK, totalNotOK, totalBusy, i;
1160 afs_uint32 volid = 0;
1167 for (i = 0; i < count; i++) {
1168 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1173 while (busyHead.count) {
1174 qGet(&busyHead, &volid);
1175 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1176 (unsigned long)volid);
1180 while (notokHead.count) {
1181 qGet(¬okHead, &volid);
1182 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1183 (unsigned long)volid);
1187 fprintf(STDOUT, "\n");
1190 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1191 totalOK, totalNotOK, totalBusy);
1195 /*------------------------------------------------------------------------
1196 * PRIVATE XDisplayVolumes
1199 * Display extended volume information.
1202 * a_servID : Pointer to the Rx call we're performing.
1203 * a_partID : Partition for which we want the extended list.
1204 * a_xInfoP : Ptr to extended volume info.
1205 * a_count : Number of volume records contained above.
1206 * a_int32 : Int32 listing generated?
1207 * a_fast : Fast listing generated?
1208 * a_quiet : Quiet listing generated?
1214 * Nothing interesting.
1218 *------------------------------------------------------------------------*/
1221 XDisplayVolumes(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1222 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1224 { /*XDisplayVolumes */
1226 int totalOK; /*Total OK volumes */
1227 int totalNotOK; /*Total screwed volumes */
1228 int totalBusy; /*Total busy volumes */
1229 int i; /*Loop variable */
1230 afs_uint32 volid = 0; /*Current volume ID */
1233 * Initialize counters and (global!!) queues.
1242 * Display each volume in the list.
1244 for (i = 0; i < a_count; i++) {
1245 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1246 &totalBusy, a_fast, a_int32, 0);
1251 * If any volumes were found to be busy or screwed, display them.
1254 while (busyHead.count) {
1255 qGet(&busyHead, &volid);
1256 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1257 (unsigned long)volid);
1261 while (notokHead.count) {
1262 qGet(¬okHead, &volid);
1263 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1264 (unsigned long)volid);
1269 fprintf(STDOUT, "\n");
1272 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1273 totalOK, totalNotOK, totalBusy);
1277 } /*XDisplayVolumes */
1278 #ifdef FULL_LISTVOL_SWITCH
1279 /*------------------------------------------------------------------------
1280 * PRIVATE XDisplayVolumes2
1283 * Display extended formated volume information.
1286 * a_servID : Pointer to the Rx call we're performing.
1287 * a_partID : Partition for which we want the extended list.
1288 * a_xInfoP : Ptr to extended volume info.
1289 * a_count : Number of volume records contained above.
1290 * a_int32 : Int32 listing generated?
1291 * a_fast : Fast listing generated?
1292 * a_quiet : Quiet listing generated?
1298 * Nothing interesting.
1302 *------------------------------------------------------------------------*/
1305 XDisplayVolumes2(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1306 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1308 { /*XDisplayVolumes */
1310 int totalOK; /*Total OK volumes */
1311 int totalNotOK; /*Total screwed volumes */
1312 int totalBusy; /*Total busy volumes */
1313 int i; /*Loop variable */
1314 afs_uint32 volid = 0; /*Current volume ID */
1317 * Initialize counters and (global!!) queues.
1326 * Display each volume in the list.
1328 for (i = 0; i < a_count; i++) {
1329 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1330 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1331 &totalBusy, a_fast, a_int32, 0);
1332 fprintf(STDOUT, "END_OF_ENTRY\n");
1337 * If any volumes were found to be busy or screwed, display them.
1340 while (busyHead.count) {
1341 qGet(&busyHead, &volid);
1342 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1343 (unsigned long)volid);
1347 while (notokHead.count) {
1348 qGet(¬okHead, &volid);
1349 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1350 (unsigned long)volid);
1355 fprintf(STDOUT, "\n");
1358 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1359 totalOK, totalNotOK, totalBusy);
1363 } /*XDisplayVolumes2 */
1364 #endif /* FULL_LISTVOL_SWITCH */
1367 /* set <server> and <part> to the correct values depending on
1368 * <voltype> and <entry> */
1370 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_int32 *server,
1371 afs_int32 *part, int *previdx)
1373 int i, istart, vtype;
1378 /* Doesn't check for non-existance of backup volume */
1379 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1381 istart = 0; /* seach the entire entry */
1384 /* Seach from beginning of entry or pick up where we left off */
1385 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1388 for (i = istart; i < entry->nServers; i++) {
1389 if (entry->serverFlags[i] & vtype) {
1390 *server = entry->serverNumber[i];
1391 *part = entry->serverPartition[i];
1397 /* Didn't find any, return -1 */
1403 PostVolumeStats(struct nvldbentry *entry)
1405 SubEnumerateEntry(entry);
1406 /* Check for VLOP_ALLOPERS */
1407 if (entry->flags & VLOP_ALLOPERS)
1408 fprintf(STDOUT, " Volume is currently LOCKED \n");
1412 /*------------------------------------------------------------------------
1413 * PRIVATE XVolumeStats
1416 * Display extended volume information.
1419 * a_xInfoP : Ptr to extended volume info.
1420 * a_entryP : Ptr to the volume's VLDB entry.
1421 * a_srvID : Server ID.
1422 * a_partID : Partition ID.
1423 * a_volType : Type of volume to print.
1429 * Nothing interesting.
1433 *------------------------------------------------------------------------*/
1436 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1437 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1440 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1442 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1443 a_srvID, /*Server ID to print */
1444 a_partID, /*Partition ID to print */
1445 &totalOK, /*Ptr to total-OK counter */
1446 &totalNotOK, /*Ptr to total-screwed counter */
1447 &totalBusy, /*Ptr to total-busy counter */
1448 0, /*Don't do a fast listing */
1449 1, /*Do a long listing */
1450 1); /*Show volume problems */
1456 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_int32 server,
1457 afs_int32 part, int voltype)
1459 int totalOK, totalNotOK, totalBusy;
1461 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1466 /* command to forcibly remove a volume */
1468 NukeVolume(register struct cmd_syndesc *as)
1470 register afs_int32 code;
1477 server = GetServer(tp = as->parms[0].items->data);
1479 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1483 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1485 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1489 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1492 PrintError("", err);
1495 "vos: could not parse '%s' as a numeric volume ID", tp);
1500 "vos: forcibly removing all traces of volume %d, please wait...",
1503 code = UV_NukeVolume(server, partID, volID);
1505 fprintf(STDOUT, "done.\n");
1507 fprintf(STDOUT, "failed with code %d.\n", code);
1512 /*------------------------------------------------------------------------
1513 * PRIVATE ExamineVolume
1516 * Routine used to examine a single volume, contacting the VLDB as
1517 * well as the Volume Server.
1520 * as : Ptr to parsed command line arguments.
1523 * 0 for a successful operation,
1524 * Otherwise, one of the ubik or VolServer error values.
1527 * Nothing interesting.
1531 *------------------------------------------------------------------------
1534 ExamineVolume(register struct cmd_syndesc *as, void *arock)
1536 struct nvldbentry entry;
1537 afs_int32 vcode = 0;
1538 volintInfo *pntr = (volintInfo *) 0;
1539 volintXInfo *xInfoP = (volintXInfo *) 0;
1541 afs_int32 code, err, error = 0;
1542 int voltype, foundserv = 0, foundentry = 0;
1543 afs_int32 aserver, apart;
1545 int wantExtendedInfo; /*Do we want extended vol info? */
1547 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1549 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1552 PrintError("", err);
1554 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1555 as->parms[0].items->data);
1560 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1561 (unsigned long)volid);
1564 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1567 "Could not fetch the entry for volume number %lu from VLDB \n",
1568 (unsigned long)volid);
1572 fprintf(STDOUT, "done\n");
1573 MapHostToNetwork(&entry);
1575 if (entry.volumeId[RWVOL] == volid)
1577 else if (entry.volumeId[BACKVOL] == volid)
1579 else /* (entry.volumeId[ROVOL] == volid) */
1582 do { /* do {...} while (voltype == ROVOL) */
1583 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1584 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1585 * If its a RO vol, get the next RO entry.
1587 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1588 &aserver, &apart, &previdx);
1589 if (previdx == -1) { /* searched all entries */
1591 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1592 as->parms[0].items->data);
1599 /* Get information about the volume from the server */
1601 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1602 hostutil_GetNameByINet(aserver));
1605 if (wantExtendedInfo)
1606 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1608 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1610 fprintf(STDOUT, "done\n");
1614 if (code == ENODEV) {
1615 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1616 /* The VLDB says there is no backup volume and its not on disk */
1617 fprintf(STDERR, "Volume %s does not exist\n",
1618 as->parms[0].items->data);
1622 "Volume does not exist on server %s as indicated by the VLDB\n",
1623 hostutil_GetNameByINet(aserver));
1626 PrintDiagnostics("examine", code);
1628 fprintf(STDOUT, "\n");
1631 if (wantExtendedInfo)
1632 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1634 #ifdef FULL_LISTVOL_SWITCH
1635 if (as->parms[2].items) {
1636 DisplayFormat2(aserver, apart, pntr);
1637 EnumerateEntry(&entry);
1639 #endif /* FULL_LISTVOL_SWITCH */
1640 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1642 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1643 /* The VLDB says there is no backup volume yet we found one on disk */
1644 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1645 as->parms[0].items->data);
1654 } while (voltype == ROVOL);
1657 fprintf(STDERR, "Dump only information from VLDB\n\n");
1658 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1660 PostVolumeStats(&entry);
1665 /*------------------------------------------------------------------------
1669 * Routine used to change the status of a single volume.
1672 * as : Ptr to parsed command line arguments.
1675 * 0 for a successful operation,
1676 * Otherwise, one of the ubik or VolServer error values.
1679 * Nothing interesting.
1683 *------------------------------------------------------------------------
1686 SetFields(register struct cmd_syndesc *as, void *arock)
1688 struct nvldbentry entry;
1691 afs_int32 code, err;
1692 afs_int32 aserver, apart;
1695 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1698 PrintError("", err);
1700 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1701 as->parms[0].items->data);
1705 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1708 "Could not fetch the entry for volume number %lu from VLDB \n",
1709 (unsigned long)volid);
1712 MapHostToNetwork(&entry);
1714 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1715 if (previdx == -1) {
1716 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1717 as->parms[0].items->data);
1721 init_volintInfo(&info);
1725 if (as->parms[1].items) {
1727 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1729 fprintf(STDERR, "invalid quota value\n");
1733 if (as->parms[2].items) {
1737 if (as->parms[3].items) {
1738 /* -clearVolUpCounter */
1741 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1744 "Could not update volume info fields for volume number %lu\n",
1745 (unsigned long)volid);
1749 /*------------------------------------------------------------------------
1753 * Brings a volume online.
1756 * as : Ptr to parsed command line arguments.
1759 * 0 for a successful operation,
1762 * Nothing interesting.
1766 *------------------------------------------------------------------------
1769 volOnline(register struct cmd_syndesc *as, void *arock)
1771 afs_int32 server, partition;
1773 afs_int32 code, err = 0;
1775 server = GetServer(as->parms[0].items->data);
1777 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1778 as->parms[0].items->data);
1782 partition = volutil_GetPartitionID(as->parms[1].items->data);
1783 if (partition < 0) {
1784 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1785 as->parms[1].items->data);
1789 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1792 PrintError("", err);
1794 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1795 as->parms[0].items->data);
1799 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1802 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1809 /*------------------------------------------------------------------------
1810 * PRIVATE volOffline
1813 * Brings a volume offline.
1816 * as : Ptr to parsed command line arguments.
1819 * 0 for a successful operation,
1822 * Nothing interesting.
1826 *------------------------------------------------------------------------
1829 volOffline(register struct cmd_syndesc *as, void *arock)
1831 afs_int32 server, partition;
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, void *arock)
1884 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1885 afs_uint32 *arovolid;
1887 struct nvldbentry entry;
1891 arovolid = &rovolid;
1894 tserver = GetServer(as->parms[0].items->data);
1896 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1897 as->parms[0].items->data);
1900 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1902 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1903 as->parms[1].items->data);
1906 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1908 PrintError("", code);
1911 "vos : partition %s does not exist on the server\n",
1912 as->parms[1].items->data);
1915 if (!ISNAMEVALID(as->parms[2].items->data)) {
1917 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1918 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1921 if (!VolNameOK(as->parms[2].items->data)) {
1923 "Illegal volume name %s, should not end in .readonly or .backup\n",
1924 as->parms[2].items->data);
1927 if (IsNumeric(as->parms[2].items->data)) {
1928 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1929 as->parms[2].items->data);
1932 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1934 fprintf(STDERR, "Volume %s already exists\n",
1935 as->parms[2].items->data);
1936 PrintDiagnostics("create", code);
1940 if (as->parms[3].items) {
1941 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1943 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1948 if (as->parms[4].items) {
1949 if (!IsNumeric(as->parms[4].items->data)) {
1950 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1951 as->parms[4].items->data);
1955 code = util_GetUInt32(as->parms[4].items->data, &volid);
1957 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1962 if (as->parms[5].items) {
1963 if (!IsNumeric(as->parms[5].items->data)) {
1964 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1965 as->parms[5].items->data);
1969 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1971 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1981 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
1982 0, 0, 0, &volid, arovolid, &bkvolid);
1984 PrintDiagnostics("create", code);
1987 MapPartIdIntoName(pnum, part);
1988 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1989 (unsigned long)volid, part, as->parms[0].items->data);
1996 DeleteAll(struct nvldbentry *entry)
1999 afs_int32 error, code, curserver, curpart;
2002 MapHostToNetwork(entry);
2004 for (i = 0; i < entry->nServers; i++) {
2005 curserver = entry->serverNumber[i];
2006 curpart = entry->serverPartition[i];
2007 if (entry->serverFlags[i] & ITSROVOL) {
2008 volid = entry->volumeId[ROVOL];
2010 volid = entry->volumeId[RWVOL];
2012 code = UV_DeleteVolume(curserver, curpart, volid);
2021 DeleteVolume(struct cmd_syndesc *as, void *arock)
2023 afs_int32 err, code = 0;
2024 afs_int32 server = 0, partition = -1;
2029 if (as->parms[0].items) {
2030 server = GetServer(as->parms[0].items->data);
2032 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2033 as->parms[0].items->data);
2038 if (as->parms[1].items) {
2039 partition = volutil_GetPartitionID(as->parms[1].items->data);
2040 if (partition < 0) {
2041 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2042 as->parms[1].items->data);
2046 /* Check for validity of the partition */
2047 if (!IsPartValid(partition, server, &code)) {
2049 PrintError("", code);
2052 "vos : partition %s does not exist on the server\n",
2053 as->parms[1].items->data);
2059 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2061 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2062 as->parms[2].items->data);
2064 PrintError("", err);
2068 /* If the server or partition option are not complete, try to fill
2069 * them in from the VLDB entry.
2071 if ((partition == -1) || !server) {
2072 struct nvldbentry entry;
2074 code = VLDB_GetEntryByID(volid, -1, &entry);
2077 "Could not fetch the entry for volume %lu from VLDB\n",
2078 (unsigned long)volid);
2079 PrintError("", code);
2083 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2084 || ((volid == entry.volumeId[BACKVOL])
2085 && (entry.flags & BACK_EXISTS))) {
2086 idx = Lp_GetRwIndex(&entry);
2087 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2088 || ((partition != -1)
2089 && (partition != entry.serverPartition[idx]))) {
2090 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2091 as->parms[2].items->data);
2094 } else if ((volid == entry.volumeId[ROVOL])
2095 && (entry.flags & RO_EXISTS)) {
2096 for (idx = -1, j = 0; j < entry.nServers; j++) {
2097 if (entry.serverFlags[j] != ITSROVOL)
2100 if (((server == 0) || (server == entry.serverNumber[j]))
2101 && ((partition == -1)
2102 || (partition == entry.serverPartition[j]))) {
2105 "VLDB: Volume '%s' matches more than one RO\n",
2106 as->parms[2].items->data);
2113 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2114 as->parms[2].items->data);
2118 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2119 as->parms[2].items->data);
2123 server = htonl(entry.serverNumber[idx]);
2124 partition = entry.serverPartition[idx];
2128 code = UV_DeleteVolume(server, partition, volid);
2130 PrintDiagnostics("remove", code);
2134 MapPartIdIntoName(partition, pname);
2135 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2136 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2140 #define TESTM 0 /* set for move space tests, clear for production */
2142 MoveVolume(register struct cmd_syndesc *as, void *arock)
2146 afs_int32 fromserver, toserver, frompart, topart;
2147 afs_int32 flags, code, err;
2148 char fromPartName[10], toPartName[10];
2150 struct diskPartition64 partition; /* for space check */
2153 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2156 PrintError("", err);
2158 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2159 as->parms[0].items->data);
2162 fromserver = GetServer(as->parms[1].items->data);
2163 if (fromserver == 0) {
2164 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2165 as->parms[1].items->data);
2168 toserver = GetServer(as->parms[3].items->data);
2169 if (toserver == 0) {
2170 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2171 as->parms[3].items->data);
2174 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2176 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2177 as->parms[2].items->data);
2180 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2182 PrintError("", code);
2185 "vos : partition %s does not exist on the server\n",
2186 as->parms[2].items->data);
2189 topart = volutil_GetPartitionID(as->parms[4].items->data);
2191 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2192 as->parms[4].items->data);
2195 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2197 PrintError("", code);
2200 "vos : partition %s does not exist on the server\n",
2201 as->parms[4].items->data);
2206 if (as->parms[5].items) flags |= RV_NOCLONE;
2209 * check source partition for space to clone volume
2212 MapPartIdIntoName(topart, toPartName);
2213 MapPartIdIntoName(frompart, fromPartName);
2216 * check target partition for space to move volume
2219 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2221 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2225 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2228 p = (volintInfo *) 0;
2229 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2231 fprintf(STDERR, "vos:cannot access volume %lu\n",
2232 (unsigned long)volid);
2236 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2238 if (partition.free <= p->size) {
2240 "vos: no space on target partition %s to move volume %lu\n",
2241 toPartName, (unsigned long)volid);
2248 fprintf(STDOUT, "size test - don't do move\n");
2252 /* successful move still not guaranteed but shoot for it */
2255 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2257 PrintDiagnostics("move", code);
2260 MapPartIdIntoName(topart, toPartName);
2261 MapPartIdIntoName(frompart, fromPartName);
2262 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2263 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2264 as->parms[3].items->data, toPartName);
2270 CopyVolume(register struct cmd_syndesc *as, void *arock)
2273 afs_int32 fromserver, toserver, frompart, topart, code, err, flags;
2274 char fromPartName[10], toPartName[10], *tovolume;
2275 struct nvldbentry entry;
2276 struct diskPartition64 partition; /* for space check */
2279 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2282 PrintError("", err);
2284 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2285 as->parms[0].items->data);
2288 fromserver = GetServer(as->parms[1].items->data);
2289 if (fromserver == 0) {
2290 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2291 as->parms[1].items->data);
2295 toserver = GetServer(as->parms[4].items->data);
2296 if (toserver == 0) {
2297 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2298 as->parms[4].items->data);
2302 tovolume = as->parms[3].items->data;
2303 if (!ISNAMEVALID(tovolume)) {
2305 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2306 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2309 if (!VolNameOK(tovolume)) {
2311 "Illegal volume name %s, should not end in .readonly or .backup\n",
2315 if (IsNumeric(tovolume)) {
2316 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2320 code = VLDB_GetEntryByName(tovolume, &entry);
2322 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2323 PrintDiagnostics("copy", code);
2327 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2329 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2330 as->parms[2].items->data);
2333 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2335 PrintError("", code);
2338 "vos : partition %s does not exist on the server\n",
2339 as->parms[2].items->data);
2343 topart = volutil_GetPartitionID(as->parms[5].items->data);
2345 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2346 as->parms[5].items->data);
2349 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2351 PrintError("", code);
2354 "vos : partition %s does not exist on the server\n",
2355 as->parms[5].items->data);
2360 if (as->parms[6].items) flags |= RV_OFFLINE;
2361 if (as->parms[7].items) flags |= RV_RDONLY;
2362 if (as->parms[8].items) flags |= RV_NOCLONE;
2364 MapPartIdIntoName(topart, toPartName);
2365 MapPartIdIntoName(frompart, fromPartName);
2368 * check target partition for space to move volume
2371 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2373 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2377 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2380 p = (volintInfo *) 0;
2381 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2383 fprintf(STDERR, "vos:cannot access volume %lu\n",
2384 (unsigned long)volid);
2388 if (partition.free <= p->size) {
2390 "vos: no space on target partition %s to copy volume %lu\n",
2391 toPartName, (unsigned long)volid);
2397 /* successful copy still not guaranteed but shoot for it */
2400 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2403 PrintDiagnostics("copy", code);
2406 MapPartIdIntoName(topart, toPartName);
2407 MapPartIdIntoName(frompart, fromPartName);
2408 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2409 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2410 tovolume, as->parms[4].items->data, toPartName);
2417 ShadowVolume(register struct cmd_syndesc *as, void *arock)
2419 afs_uint32 volid, tovolid;
2420 afs_int32 fromserver, toserver, frompart, topart;
2421 afs_int32 code, err, flags;
2422 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2423 struct diskPartition64 partition; /* for space check */
2426 p = (volintInfo *) 0;
2427 q = (volintInfo *) 0;
2429 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2432 PrintError("", err);
2434 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2435 as->parms[0].items->data);
2438 fromserver = GetServer(as->parms[1].items->data);
2439 if (fromserver == 0) {
2440 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2441 as->parms[1].items->data);
2445 toserver = GetServer(as->parms[3].items->data);
2446 if (toserver == 0) {
2447 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2448 as->parms[3].items->data);
2452 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2454 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2455 as->parms[2].items->data);
2458 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2460 PrintError("", code);
2463 "vos : partition %s does not exist on the server\n",
2464 as->parms[2].items->data);
2468 topart = volutil_GetPartitionID(as->parms[4].items->data);
2470 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2471 as->parms[4].items->data);
2474 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2476 PrintError("", code);
2479 "vos : partition %s does not exist on the server\n",
2480 as->parms[4].items->data);
2484 if (as->parms[5].items) {
2485 tovolume = as->parms[5].items->data;
2486 if (!ISNAMEVALID(tovolume)) {
2488 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2489 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2492 if (!VolNameOK(tovolume)) {
2494 "Illegal volume name %s, should not end in .readonly or .backup\n",
2498 if (IsNumeric(tovolume)) {
2500 "Illegal volume name %s, should not be a number\n",
2505 /* use actual name of source volume */
2506 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2508 fprintf(STDERR, "vos:cannot access volume %lu\n",
2509 (unsigned long)volid);
2512 strcpy(toVolName, p->name);
2513 tovolume = toVolName;
2514 /* save p for size checks later */
2517 if (as->parms[6].items) {
2518 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2521 PrintError("", err);
2523 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2524 as->parms[6].items->data);
2530 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2533 PrintError("", err);
2535 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2544 if (as->parms[7].items) flags |= RV_OFFLINE;
2545 if (as->parms[8].items) flags |= RV_RDONLY;
2546 if (as->parms[9].items) flags |= RV_NOCLONE;
2547 if (as->parms[10].items) flags |= RV_CPINCR;
2549 MapPartIdIntoName(topart, toPartName);
2550 MapPartIdIntoName(frompart, fromPartName);
2553 * check target partition for space to move volume
2556 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2558 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2562 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2565 /* Don't do this again if we did it above */
2567 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2569 fprintf(STDERR, "vos:cannot access volume %lu\n",
2570 (unsigned long)volid);
2575 /* OK if this fails */
2576 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2578 /* Treat existing volume size as "free" */
2580 p->size = (q->size < p->size) ? p->size - q->size : 0;
2582 if (partition.free <= p->size) {
2584 "vos: no space on target partition %s to copy volume %lu\n",
2585 toPartName, (unsigned long)volid);
2593 /* successful copy still not guaranteed but shoot for it */
2596 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2597 topart, tovolid, flags);
2599 PrintDiagnostics("shadow", code);
2602 MapPartIdIntoName(topart, toPartName);
2603 MapPartIdIntoName(frompart, fromPartName);
2604 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2605 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2606 as->parms[3].items->data, toPartName);
2613 CloneVolume(register struct cmd_syndesc *as, void *arock)
2615 afs_uint32 volid, cloneid;
2616 afs_int32 server, part, voltype;
2617 char partName[10], *volname;
2618 afs_int32 code, err, flags;
2619 struct nvldbentry entry;
2621 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2624 PrintError("", err);
2626 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2627 as->parms[0].items->data);
2631 if (as->parms[1].items || as->parms[2].items) {
2632 if (!as->parms[1].items || !as->parms[2].items) {
2634 "Must specify both -server and -partition options\n");
2637 server = GetServer(as->parms[1].items->data);
2639 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2640 as->parms[1].items->data);
2643 part = volutil_GetPartitionID(as->parms[2].items->data);
2645 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2646 as->parms[2].items->data);
2649 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2651 PrintError("", code);
2654 "vos : partition %s does not exist on the server\n",
2655 as->parms[2].items->data);
2659 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2665 if (as->parms[3].items) {
2666 volname = as->parms[3].items->data;
2667 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2669 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2670 volname, VOLSER_OLDMAXVOLNAME - 1);
2675 * In order that you be able to make clones of RO or BK, this
2676 * check must be omitted.
2678 if (!VolNameOK(volname)) {
2680 "Illegal volume name %s, should not end in .readonly or .backup\n",
2685 if (IsNumeric(volname)) {
2687 "Illegal volume name %s, should not be a number\n",
2694 if (as->parms[4].items) {
2695 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2698 PrintError("", err);
2700 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2701 as->parms[4].items->data);
2707 if (as->parms[5].items) flags |= RV_OFFLINE;
2708 if (as->parms[6].items) flags |= RV_RDONLY;
2712 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2715 PrintDiagnostics("clone", code);
2718 MapPartIdIntoName(part, partName);
2719 fprintf(STDOUT, "Created clone for volume %s\n",
2720 as->parms[0].items->data);
2727 BackupVolume(register struct cmd_syndesc *as, void *arock)
2730 afs_int32 aserver, apart, vtype, code, err;
2731 struct nvldbentry entry;
2734 afs_int32 buserver, bupart, butype;
2735 struct nvldbentry buentry;
2737 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2740 PrintError("", err);
2742 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2743 as->parms[0].items->data);
2746 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2750 /* verify this is a readwrite volume */
2752 if (vtype != RWVOL) {
2753 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2757 /* is there a backup volume already? */
2759 if (entry.flags & BACK_EXISTS) {
2760 /* yep, where is it? */
2762 buvolid = entry.volumeId[BACKVOL];
2763 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2768 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2771 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2777 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2778 (unsigned long)buvolid, (unsigned long)buserver);
2783 /* nope, carry on */
2785 code = UV_BackupVolume(aserver, apart, avolid);
2788 PrintDiagnostics("backup", code);
2791 fprintf(STDOUT, "Created backup volume for %s \n",
2792 as->parms[0].items->data);
2797 ReleaseVolume(register struct cmd_syndesc *as, void *arock)
2800 struct nvldbentry entry;
2802 afs_int32 aserver, apart, vtype, code, err;
2805 if (as->parms[1].items)
2807 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2810 PrintError("", err);
2812 fprintf(STDERR, "vos: can't find volume '%s'\n",
2813 as->parms[0].items->data);
2816 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2820 if (vtype != RWVOL) {
2821 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2825 if (!ISNAMEVALID(entry.name)) {
2827 "Volume name %s is too long, rename before releasing\n",
2832 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2834 PrintDiagnostics("release", code);
2837 fprintf(STDOUT, "Released volume %s successfully\n",
2838 as->parms[0].items->data);
2843 DumpVolumeCmd(register struct cmd_syndesc *as, void *arock)
2846 afs_int32 aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2847 char filename[MAXPATHLEN];
2848 struct nvldbentry entry;
2850 rx_SetRxDeadTime(60 * 10);
2851 for (i = 0; i < MAXSERVERS; i++) {
2852 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2855 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2856 if (rxConn->service)
2857 rxConn->service->connDeadTime = rx_connDeadTime;
2860 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2863 PrintError("", err);
2865 fprintf(STDERR, "vos: can't find volume '%s'\n",
2866 as->parms[0].items->data);
2870 if (as->parms[3].items || as->parms[4].items) {
2871 if (!as->parms[3].items || !as->parms[4].items) {
2873 "Must specify both -server and -partition options\n");
2876 aserver = GetServer(as->parms[3].items->data);
2878 fprintf(STDERR, "Invalid server name\n");
2881 apart = volutil_GetPartitionID(as->parms[4].items->data);
2883 fprintf(STDERR, "Invalid partition name\n");
2887 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2892 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2893 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2895 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2896 as->parms[1].items->data, code);
2900 if (as->parms[2].items) {
2901 strcpy(filename, as->parms[2].items->data);
2903 strcpy(filename, "");
2906 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2908 if (as->parms[5].items) {
2910 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2911 DumpFunction, filename, flags);
2914 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2917 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2918 flags &= ~VOLDUMPV2_OMITDIRS;
2922 PrintDiagnostics("dump", code);
2925 if (strcmp(filename, ""))
2926 fprintf(STDERR, "Dumped volume %s in file %s\n",
2927 as->parms[0].items->data, filename);
2929 fprintf(STDERR, "Dumped volume %s in stdout \n",
2930 as->parms[0].items->data);
2944 RestoreVolumeCmd(register struct cmd_syndesc *as, void *arock)
2946 afs_uint32 avolid, aparentid;
2947 afs_int32 aserver, apart, code, vcode, err;
2948 afs_int32 aoverwrite = ASK;
2949 afs_int32 acreation = 0, alastupdate = 0;
2950 int restoreflags = 0;
2951 int readonly = 0, offline = 0, voltype = RWVOL;
2953 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2954 char volname[VOLSER_MAXVOLNAME + 1];
2955 struct nvldbentry entry;
2960 if (as->parms[4].items) {
2961 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2964 PrintError("", err);
2966 fprintf(STDERR, "vos: can't find volume '%s'\n",
2967 as->parms[4].items->data);
2973 if (as->parms[5].items) {
2974 if ((strcmp(as->parms[5].items->data, "a") == 0)
2975 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2977 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2978 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2980 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2981 || (strcmp(as->parms[5].items->data, "inc") == 0)
2982 || (strcmp(as->parms[5].items->data, "increment") == 0)
2983 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2986 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2987 as->parms[5].items->data);
2991 if (as->parms[6].items)
2993 if (as->parms[7].items) {
2998 if (as->parms[8].items) {
2999 if ((strcmp(as->parms[8].items->data, "d") == 0)
3000 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3001 acreation = TS_DUMP;
3002 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3003 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3004 acreation = TS_KEEP;
3005 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3006 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3009 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3010 as->parms[8].items->data);
3015 if (as->parms[9].items) {
3016 if ((strcmp(as->parms[9].items->data, "d") == 0)
3017 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3018 alastupdate = TS_DUMP;
3019 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3020 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3021 alastupdate = TS_KEEP;
3022 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3023 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3024 alastupdate = TS_NEW;
3026 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3027 as->parms[9].items->data);
3032 aserver = GetServer(as->parms[0].items->data);
3034 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3035 as->parms[0].items->data);
3038 apart = volutil_GetPartitionID(as->parms[1].items->data);
3040 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3041 as->parms[1].items->data);
3044 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3046 PrintError("", code);
3049 "vos : partition %s does not exist on the server\n",
3050 as->parms[1].items->data);
3053 strcpy(avolname, as->parms[2].items->data);
3054 if (!ISNAMEVALID(avolname)) {
3056 "vos: the name of the volume %s exceeds the size limit\n",
3060 if (!VolNameOK(avolname)) {
3062 "Illegal volume name %s, should not end in .readonly or .backup\n",
3066 if (as->parms[3].items) {
3067 strcpy(afilename, as->parms[3].items->data);
3068 if (!FileExists(afilename)) {
3069 fprintf(STDERR, "Can't access file %s\n", afilename);
3073 strcpy(afilename, "");
3076 /* Check if volume exists or not */
3078 vsu_ExtractName(volname, avolname);
3079 vcode = VLDB_GetEntryByName(volname, &entry);
3080 if (vcode) { /* no volume - do a full restore */
3081 restoreflags = RV_FULLRST;
3082 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3084 "Volume does not exist; Will perform a full restore\n");
3087 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3088 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3089 restoreflags = RV_FULLRST;
3090 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3092 "%s Volume does not exist; Will perform a full restore\n",
3093 readonly ? "RO" : "RW");
3096 avolid = entry.volumeId[voltype];
3097 } else if (entry.volumeId[voltype] != 0
3098 && entry.volumeId[voltype] != avolid) {
3099 avolid = entry.volumeId[voltype];
3101 aparentid = entry.volumeId[RWVOL];
3104 else { /* volume exists - do we do a full incremental or abort */
3105 int Oserver, Opart, Otype, vol_elsewhere = 0;
3106 struct nvldbentry Oentry;
3110 avolid = entry.volumeId[voltype];
3111 } else if (entry.volumeId[voltype] != 0
3112 && entry.volumeId[voltype] != avolid) {
3113 avolid = entry.volumeId[voltype];
3115 aparentid = entry.volumeId[RWVOL];
3117 /* A file name was specified - check if volume is on another partition */
3118 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3122 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3125 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3129 if (!vcode || (Opart != apart))
3132 if (aoverwrite == ASK) {
3133 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3135 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3139 /* Ask what to do */
3140 if (vol_elsewhere) {
3142 "The volume %s %u already exists on a different server/part\n",
3143 volname, entry.volumeId[voltype]);
3145 "Do you want to do a full restore or abort? [fa](a): ");
3148 "The volume %s %u already exists in the VLDB\n",
3149 volname, entry.volumeId[voltype]);
3151 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3154 while (!(dc == EOF || dc == '\n'))
3155 dc = getchar(); /* goto end of line */
3156 if ((c == 'f') || (c == 'F'))
3158 else if ((c == 'i') || (c == 'I'))
3164 if (aoverwrite == ABORT) {
3165 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3167 } else if (aoverwrite == FULL) {
3168 restoreflags = RV_FULLRST;
3170 "Volume exists; Will delete and perform full restore\n");
3171 } else if (aoverwrite == INC) {
3173 if (vol_elsewhere) {
3175 "%s volume %lu already exists on a different server/part; not allowed\n",
3176 readonly ? "RO" : "RW", (unsigned long)avolid);
3182 restoreflags |= RV_OFFLINE;
3184 restoreflags |= RV_RDONLY;
3186 switch (acreation) {
3188 restoreflags |= RV_CRDUMP;
3191 restoreflags |= RV_CRKEEP;
3194 restoreflags |= RV_CRNEW;
3197 if (aoverwrite == FULL)
3198 restoreflags |= RV_CRNEW;
3200 restoreflags |= RV_CRKEEP;
3203 switch (alastupdate) {
3205 restoreflags |= RV_LUDUMP;
3208 restoreflags |= RV_LUKEEP;
3211 restoreflags |= RV_LUNEW;
3214 restoreflags |= RV_LUDUMP;
3216 if (as->parms[10].items) {
3217 restoreflags |= RV_NODEL;
3222 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3223 avolname, restoreflags, WriteData, afilename);
3225 PrintDiagnostics("restore", code);
3228 MapPartIdIntoName(apart, apartName);
3231 * patch typo here - originally "parms[1]", should be "parms[0]"
3234 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3235 as->parms[0].items->data, apartName);
3240 LockReleaseCmd(register struct cmd_syndesc *as, void *arock)
3243 afs_int32 code, err;
3245 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3248 PrintError("", err);
3250 fprintf(STDERR, "vos: can't find volume '%s'\n",
3251 as->parms[0].items->data);
3255 code = UV_LockRelease(avolid);
3257 PrintDiagnostics("unlock", code);
3260 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3261 as->parms[0].items->data);
3266 AddSite(register struct cmd_syndesc *as, void *arock)
3269 afs_int32 aserver, apart, code, err, arovolid, valid = 0;
3270 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3272 vsu_ExtractName(avolname, as->parms[2].items->data);;
3273 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3276 PrintError("", err);
3278 fprintf(STDERR, "vos: can't find volume '%s'\n",
3279 as->parms[2].items->data);
3283 if (as->parms[3].items) {
3284 vsu_ExtractName(avolname, as->parms[3].items->data);
3285 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3287 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3288 as->parms[3].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);
3304 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3306 PrintError("", code);
3309 "vos : partition %s does not exist on the server\n",
3310 as->parms[1].items->data);
3313 if (as->parms[4].items) {
3316 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3318 PrintDiagnostics("addsite", code);
3321 MapPartIdIntoName(apart, apartName);
3322 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3323 as->parms[0].items->data, apartName, as->parms[2].items->data);
3328 RemoveSite(register struct cmd_syndesc *as, void *arock)
3332 afs_int32 aserver, apart, code, err;
3333 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3335 vsu_ExtractName(avolname, as->parms[2].items->data);
3336 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3339 PrintError("", err);
3341 fprintf(STDERR, "vos: can't find volume '%s'\n",
3342 as->parms[2].items->data);
3345 aserver = GetServer(as->parms[0].items->data);
3347 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3348 as->parms[0].items->data);
3351 apart = volutil_GetPartitionID(as->parms[1].items->data);
3353 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3354 as->parms[1].items->data);
3358 *skip the partition validity check, since it is possible that the partition
3359 *has since been decomissioned.
3362 if (!IsPartValid(apart,aserver,&code)){
3363 if(code) PrintError("",code);
3364 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3368 code = UV_RemoveSite(aserver, apart, avolid);
3370 PrintDiagnostics("remsite", code);
3373 MapPartIdIntoName(apart, apartName);
3374 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3375 as->parms[0].items->data, apartName, as->parms[2].items->data);
3380 ChangeLocation(register struct cmd_syndesc *as, void *arock)
3383 afs_int32 aserver, apart, code, err;
3386 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3389 PrintError("", err);
3391 fprintf(STDERR, "vos: can't find volume '%s'\n",
3392 as->parms[2].items->data);
3395 aserver = GetServer(as->parms[0].items->data);
3397 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3398 as->parms[0].items->data);
3401 apart = volutil_GetPartitionID(as->parms[1].items->data);
3403 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3404 as->parms[1].items->data);
3407 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3409 PrintError("", code);
3412 "vos : partition %s does not exist on the server\n",
3413 as->parms[1].items->data);
3416 code = UV_ChangeLocation(aserver, apart, avolid);
3418 PrintDiagnostics("addsite", code);
3421 MapPartIdIntoName(apart, apartName);
3422 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3423 as->parms[0].items->data, apartName, as->parms[2].items->data);
3428 ListPartitions(register struct cmd_syndesc *as, void *arock)
3430 afs_int32 aserver, code;
3431 struct partList dummyPartList;
3436 aserver = GetServer(as->parms[0].items->data);
3438 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3439 as->parms[0].items->data);
3444 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3446 PrintDiagnostics("listpart", code);
3450 fprintf(STDOUT, "The partitions on the server are:\n");
3451 for (i = 0; i < cnt; i++) {
3452 if (dummyPartList.partFlags[i] & PARTVALID) {
3453 memset(pname, 0, sizeof(pname));
3454 MapPartIdIntoName(dummyPartList.partId[i], pname);
3455 fprintf(STDOUT, " %10s ", pname);
3457 if ((i % 5) == 0 && (i != 0))
3458 fprintf(STDOUT, "\n");
3461 fprintf(STDOUT, "\n");
3462 fprintf(STDOUT, "Total: %d\n", total);
3468 CompareVolName(const void *p1, const void *p2)
3470 volintInfo *arg1, *arg2;
3472 arg1 = (volintInfo *) p1;
3473 arg2 = (volintInfo *) p2;
3474 return (strcmp(arg1->name, arg2->name));
3478 /*------------------------------------------------------------------------
3479 * PRIVATE XCompareVolName
3482 * Comparison routine for volume names 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 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3502 { /*XCompareVolName */
3505 (((struct volintXInfo *)(a_obj1P))->name,
3506 ((struct volintXInfo *)(a_obj2P))->name));
3508 } /*XCompareVolName */
3511 CompareVolID(const void *p1, const void *p2)
3513 volintInfo *arg1, *arg2;
3515 arg1 = (volintInfo *) p1;
3516 arg2 = (volintInfo *) p2;
3517 if (arg1->volid == arg2->volid)
3519 if (arg1->volid > arg2->volid)
3526 /*------------------------------------------------------------------------
3527 * PRIVATE XCompareVolID
3530 * Comparison routine for volume IDs coming from an extended
3534 * a_obj1P : Char ptr to first extended vol info object
3535 * a_obj1P : Char ptr to second extended vol info object
3538 * The value of strcmp() on the volume names within the passed
3539 * objects (i,e., -1, 0, or 1).
3542 * Passed to qsort() as the designated comparison routine.
3546 *------------------------------------------------------------------------*/
3549 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3550 { /*XCompareVolID */
3552 afs_int32 id1, id2; /*Volume IDs we're comparing */
3554 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3555 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3563 } /*XCompareVolID */
3565 /*------------------------------------------------------------------------
3566 * PRIVATE ListVolumes
3569 * Routine used to list volumes, contacting the Volume Server
3570 * directly, bypassing the VLDB.
3573 * as : Ptr to parsed command line arguments.
3576 * 0 Successful operation
3579 * Nothing interesting.
3583 *------------------------------------------------------------------------*/
3586 ListVolumes(register struct cmd_syndesc *as, void *arock)
3588 afs_int32 apart, int32list, fast;
3589 afs_int32 aserver, code;
3591 volintInfo *oldpntr = NULL;
3595 volintXInfo *xInfoP;
3596 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3597 int wantExtendedInfo; /*Do we want extended vol info? */
3600 struct partList dummyPartList;
3608 if (as->parms[3].items)
3610 if (as->parms[4].items)
3614 if (as->parms[2].items)
3620 if (as->parms[5].items) {
3622 * We can't coexist with the fast flag.
3626 "vos: Can't use the -fast and -extended flags together\n");
3631 * We need to turn on ``long'' listings to get the full effect.
3633 wantExtendedInfo = 1;
3636 wantExtendedInfo = 0;
3637 if (as->parms[1].items) {
3638 apart = volutil_GetPartitionID(as->parms[1].items->data);
3640 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3641 as->parms[1].items->data);
3644 dummyPartList.partId[0] = apart;
3645 dummyPartList.partFlags[0] = PARTVALID;
3648 aserver = GetServer(as->parms[0].items->data);
3650 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3651 as->parms[0].items->data);
3656 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3658 PrintError("", code);
3661 "vos : partition %s does not exist on the server\n",
3662 as->parms[1].items->data);
3666 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3668 PrintDiagnostics("listvol", code);
3672 for (i = 0; i < cnt; i++) {
3673 if (dummyPartList.partFlags[i] & PARTVALID) {
3674 if (wantExtendedInfo)
3676 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3680 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3683 PrintDiagnostics("listvol", code);
3688 if (wantExtendedInfo) {
3689 origxInfoP = xInfoP;
3690 base = (char *)xInfoP;
3693 base = (char *)pntr;
3697 if (wantExtendedInfo)
3698 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3700 qsort(base, count, sizeof(volintInfo), CompareVolName);
3702 if (wantExtendedInfo)
3703 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3705 qsort(base, count, sizeof(volintInfo), CompareVolID);
3707 MapPartIdIntoName(dummyPartList.partId[i], pname);
3710 "Total number of volumes on server %s partition %s: %lu \n",
3711 as->parms[0].items->data, pname,
3712 (unsigned long)count);
3713 if (wantExtendedInfo) {
3714 #ifdef FULL_LISTVOL_SWITCH
3715 if (as->parms[6].items)
3716 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3717 count, int32list, fast, quiet);
3719 #endif /* FULL_LISTVOL_SWITCH */
3720 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3721 count, int32list, fast, quiet);
3724 xInfoP = (volintXInfo *) 0;
3726 #ifdef FULL_LISTVOL_SWITCH
3727 if (as->parms[6].items)
3728 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3731 #endif /* FULL_LISTVOL_SWITCH */
3732 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3733 count, int32list, fast, quiet);
3736 pntr = (volintInfo *) 0;
3744 SyncVldb(register struct cmd_syndesc *as, void *arock)
3746 afs_int32 pnum = 0, code; /* part name */
3752 if (as->parms[0].items) {
3753 tserver = GetServer(as->parms[0].items->data);
3755 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3756 as->parms[0].items->data);
3761 if (as->parms[1].items) {
3762 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3764 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3765 as->parms[1].items->data);
3768 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3770 PrintError("", code);
3773 "vos: partition %s does not exist on the server\n",
3774 as->parms[1].items->data);
3781 "The -partition option requires a -server option\n");
3786 if (as->parms[3].items) {
3787 flags |= 2; /* don't update */
3790 if (as->parms[2].items) {
3791 /* Synchronize an individual volume */
3792 volname = as->parms[2].items->data;
3793 code = UV_SyncVolume(tserver, pnum, volname, flags);
3797 "Without a -volume option, the -server option is required\n");
3800 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3804 PrintDiagnostics("syncvldb", code);
3808 /* Print a summary of what we did */
3810 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3812 fprintf(STDOUT, "VLDB synchronized");
3814 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3817 MapPartIdIntoName(pnum, part);
3818 fprintf(STDOUT, " partition %s\n", part);
3820 fprintf(STDOUT, "\n");
3826 SyncServer(register struct cmd_syndesc *as, void *arock)
3828 afs_int32 pnum, code; /* part name */
3833 tserver = GetServer(as->parms[0].items->data);
3835 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3836 as->parms[0].items->data);
3839 if (as->parms[1].items) {
3840 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3842 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3843 as->parms[1].items->data);
3846 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3848 PrintError("", code);
3851 "vos : partition %s does not exist on the server\n",
3852 as->parms[1].items->data);
3860 if (as->parms[2].items) {
3861 flags |= 2; /* don't update */
3863 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3865 PrintDiagnostics("syncserv", code);
3869 MapPartIdIntoName(pnum, part);
3870 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3871 as->parms[0].items->data, part);
3873 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3874 as->parms[0].items->data);
3880 VolumeInfoCmd(char *name)
3882 struct nvldbentry entry;
3885 /* The vlserver will handle names with the .readonly
3886 * and .backup extension as well as volume ids.
3888 vcode = VLDB_GetEntryByName(name, &entry);
3890 PrintError("", vcode);
3893 MapHostToNetwork(&entry);
3894 EnumerateEntry(&entry);
3896 /* Defect #3027: grubby check to handle locked volume.
3897 * If VLOP_ALLOPERS is set, the entry is locked.
3898 * Leave this routine as is, but put in correct check.
3900 if (entry.flags & VLOP_ALLOPERS)
3901 fprintf(STDOUT, " Volume is currently LOCKED \n");
3907 VolumeZap(register struct cmd_syndesc *as, void *arock)
3909 struct nvldbentry entry;
3910 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3911 afs_int32 code, server, part, err;
3913 if (as->parms[3].items) {
3914 /* force flag is on, use the other version */
3915 return NukeVolume(as);
3918 if (as->parms[4].items) {
3922 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3925 PrintError("", err);
3927 fprintf(STDERR, "vos: can't find volume '%s'\n",
3928 as->parms[2].items->data);
3931 part = volutil_GetPartitionID(as->parms[1].items->data);
3933 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3934 as->parms[1].items->data);
3937 server = GetServer(as->parms[0].items->data);
3939 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3940 as->parms[0].items->data);
3943 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3945 PrintError("", code);
3948 "vos : partition %s does not exist on the server\n",
3949 as->parms[1].items->data);
3952 code = VLDB_GetEntryByID(volid, -1, &entry);
3954 if (volid == entry.volumeId[RWVOL])
3955 backupid = entry.volumeId[BACKVOL];
3957 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3958 (unsigned long)volid);
3961 volintInfo *pntr = (volintInfo *) 0;
3964 code = UV_ListOneVolume(server, part, volid, &pntr);
3966 if (volid == pntr->parentID)
3967 backupid = pntr->backupID;
3973 code = UV_VolumeZap(server, part, backupid);
3975 PrintDiagnostics("zap", code);
3978 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3979 (unsigned long)backupid);
3982 code = UV_VolumeZap(server, part, volid);
3984 PrintDiagnostics("zap", code);
3987 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3993 VolserStatus(register struct cmd_syndesc *as, void *arock)
3995 afs_int32 server, code;
3996 transDebugInfo *pntr, *oldpntr;
4002 server = GetServer(as->parms[0].items->data);
4004 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4005 as->parms[0].items->data);
4008 code = UV_VolserStatus(server, &pntr, &count);
4010 PrintDiagnostics("status", code);
4015 fprintf(STDOUT, "No active transactions on %s\n",
4016 as->parms[0].items->data);
4018 fprintf(STDOUT, "Total transactions: %d\n", count);
4020 for (i = 0; i < count; i++) {
4021 /*print out the relevant info */
4022 fprintf(STDOUT, "--------------------------------------\n");
4024 fprintf(STDOUT, "transaction: %lu created: %s",
4025 (unsigned long)pntr->tid, ctime(&t));
4026 if (pntr->returnCode) {
4027 fprintf(STDOUT, "returnCode: %lu\n",
4028 (unsigned long)pntr->returnCode);
4031 fprintf(STDOUT, "attachFlags: ");
4032 switch (pntr->iflags) {
4034 fprintf(STDOUT, "offline ");
4037 fprintf(STDOUT, "busy ");
4040 fprintf(STDOUT, "readonly ");
4043 fprintf(STDOUT, "create ");
4046 fprintf(STDOUT, "create volid ");
4049 fprintf(STDOUT, "\n");
4052 fprintf(STDOUT, "volumeStatus: ");
4053 switch (pntr->vflags) {
4054 case VTDeleteOnSalvage:
4055 fprintf(STDOUT, "deleteOnSalvage ");
4056 case VTOutOfService:
4057 fprintf(STDOUT, "outOfService ");
4059 fprintf(STDOUT, "deleted ");
4061 fprintf(STDOUT, "\n");
4064 fprintf(STDOUT, "transactionFlags: ");
4065 fprintf(STDOUT, "delete\n");
4067 MapPartIdIntoName(pntr->partition, pname);
4068 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4069 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4070 if (pntr->callValid) {
4072 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
4073 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4074 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4077 fprintf(STDOUT, "--------------------------------------\n");
4078 fprintf(STDOUT, "\n");
4086 RenameVolume(register struct cmd_syndesc *as, void *arock)
4088 afs_int32 code1, code2, code;
4089 struct nvldbentry entry;
4091 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4093 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4094 as->parms[0].items->data);
4097 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4098 if ((!code1) && (!code2)) { /*the newname already exists */
4099 fprintf(STDERR, "vos: volume %s already exists\n",
4100 as->parms[1].items->data);
4104 if (code1 && code2) {
4105 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4106 as->parms[0].items->data, as->parms[1].items->data);
4109 if (!VolNameOK(as->parms[0].items->data)) {
4111 "Illegal volume name %s, should not end in .readonly or .backup\n",
4112 as->parms[0].items->data);
4115 if (!ISNAMEVALID(as->parms[1].items->data)) {
4117 "vos: the new volume name %s exceeds the size limit of %d\n",
4118 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4121 if (!VolNameOK(as->parms[1].items->data)) {
4123 "Illegal volume name %s, should not end in .readonly or .backup\n",
4124 as->parms[1].items->data);
4127 if (IsNumeric(as->parms[1].items->data)) {
4128 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4129 as->parms[1].items->data);
4132 MapHostToNetwork(&entry);
4134 UV_RenameVolume(&entry, as->parms[0].items->data,
4135 as->parms[1].items->data);
4137 PrintDiagnostics("rename", code);
4140 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4141 as->parms[1].items->data);
4146 GetVolumeInfo(afs_uint32 volid, afs_int32 *server, afs_int32 *part, afs_int32 *voltype,
4147 struct nvldbentry *rentry)
4152 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4155 "Could not fetch the entry for volume %lu from VLDB \n",
4156 (unsigned long)volid);
4157 PrintError("", vcode);
4160 MapHostToNetwork(rentry);
4161 if (volid == rentry->volumeId[ROVOL]) {
4163 for (i = 0; i < rentry->nServers; i++) {
4164 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4165 && !(rentry->serverFlags[i] & RO_DONTUSE))
4170 "RO volume is not found in VLDB entry for volume %lu\n",
4171 (unsigned long)volid);
4175 *server = rentry->serverNumber[index];
4176 *part = rentry->serverPartition[index];
4180 index = Lp_GetRwIndex(rentry);
4183 "RW Volume is not found in VLDB entry for volume %lu\n",
4184 (unsigned long)volid);
4187 if (volid == rentry->volumeId[RWVOL]) {
4189 *server = rentry->serverNumber[index];
4190 *part = rentry->serverPartition[index];
4193 if (volid == rentry->volumeId[BACKVOL]) {
4195 *server = rentry->serverNumber[index];
4196 *part = rentry->serverPartition[index];
4200 "unexpected volume type for volume %lu\n",
4201 (unsigned long)volid);
4206 DeleteEntry(register struct cmd_syndesc *as, void *arock)
4208 afs_int32 apart = 0;
4211 struct VldbListByAttributes attributes;
4212 nbulkentries arrayEntries;
4213 register struct nvldbentry *vllist;
4214 struct cmd_item *itp;
4217 char prefix[VOLSER_MAXVOLNAME + 1];
4219 afs_int32 totalBack = 0, totalFail = 0, err;
4221 if (as->parms[0].items) { /* -id */
4222 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4224 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4227 for (itp = as->parms[0].items; itp; itp = itp->next) {
4228 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4231 PrintError("", err);
4233 fprintf(STDERR, "vos: can't find volume '%s'\n",
4237 if (as->parms[4].items) { /* -noexecute */
4238 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4243 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4245 fprintf(STDERR, "Could not delete entry for volume %s\n",
4248 "You must specify a RW volume name or ID "
4249 "(the entire VLDB entry will be deleted)\n");
4250 PrintError("", vcode);
4256 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4260 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4261 fprintf(STDERR, "You must specify an option\n");
4265 /* Zero out search attributes */
4266 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4268 if (as->parms[1].items) { /* -prefix */
4269 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4271 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4273 "You must provide -server with the -prefix argument\n");
4278 if (as->parms[2].items) { /* -server */
4280 aserver = GetServer(as->parms[2].items->data);
4282 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4283 as->parms[2].items->data);
4286 attributes.server = ntohl(aserver);
4287 attributes.Mask |= VLLIST_SERVER;
4290 if (as->parms[3].items) { /* -partition */
4291 if (!as->parms[2].items) {
4293 "You must provide -server with the -partition argument\n");
4296 apart = volutil_GetPartitionID(as->parms[3].items->data);
4298 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4299 as->parms[3].items->data);
4302 attributes.partition = apart;
4303 attributes.Mask |= VLLIST_PARTITION;
4306 /* Print status line of what we are doing */
4307 fprintf(STDOUT, "Deleting VLDB entries for ");
4308 if (as->parms[2].items) {
4309 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4311 if (as->parms[3].items) {
4313 MapPartIdIntoName(apart, pname);
4314 fprintf(STDOUT, "partition %s ", pname);
4317 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4319 fprintf(STDOUT, "\n");
4322 /* Get all the VLDB entries on a server and/or partition */
4323 memset(&arrayEntries, 0, sizeof(arrayEntries));
4324 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4326 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4327 PrintError("", vcode);
4331 /* Process each entry */
4332 for (j = 0; j < nentries; j++) {
4333 vllist = &arrayEntries.nbulkentries_val[j];
4335 /* It only deletes the RW volumes */
4336 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4339 "Omitting to delete %s due to prefix %s mismatch\n",
4340 vllist->name, prefix);
4347 if (as->parms[4].items) { /* -noexecute */
4348 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4354 /* Only matches the RW volume name */
4355 avolid = vllist->volumeId[RWVOL];
4356 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4358 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4361 PrintError("", vcode);
4366 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4371 fprintf(STDOUT, "----------------------\n");
4373 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4374 (unsigned long)totalBack, (unsigned long)totalFail);
4375 if (arrayEntries.nbulkentries_val)
4376 free(arrayEntries.nbulkentries_val);
4382 CompareVldbEntryByName(const void *p1, const void *p2)
4384 struct nvldbentry *arg1, *arg2;
4386 arg1 = (struct nvldbentry *)p1;
4387 arg2 = (struct nvldbentry *)p2;
4388 return (strcmp(arg1->name, arg2->name));
4392 static int CompareVldbEntry(char *p1, char *p2)
4394 struct nvldbentry *arg1,*arg2;
4397 char comp1[100],comp2[100];
4398 char temp1[20],temp2[20];
4400 arg1 = (struct nvldbentry *)p1;
4401 arg2 = (struct nvldbentry *)p2;
4405 for(i = 0; i < arg1->nServers; i++)
4406 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4407 for(i = 0; i < arg2->nServers; i++)
4408 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4409 if(pos1 == -1 || pos2 == -1){
4413 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4414 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4415 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4416 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4417 strcat(comp1,temp1);
4418 strcat(comp2,temp2);
4419 strcat(comp1,arg1->name);
4420 strcat(comp1,arg2->name);
4421 return(strcmp(comp1,comp2));
4427 ListVLDB(struct cmd_syndesc *as, void *arock)
4430 afs_int32 aserver, code;
4432 struct VldbListByAttributes attributes;
4433 nbulkentries arrayEntries;
4434 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4435 afs_int32 centries, nentries = 0;
4436 afs_int32 tarraysize = 0;
4437 afs_int32 parraysize;
4440 int quiet, sort, lock;
4441 afs_int32 thisindex, nextindex;
4446 attributes.Mask = 0;
4447 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4448 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4449 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4451 /* If the volume name is given, Use VolumeInfoCmd to look it up
4452 * and not ListAttributes.
4454 if (as->parms[0].items) {
4457 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4460 code = VolumeInfoCmd(as->parms[0].items->data);
4462 PrintError("", code);
4468 /* Server specified */
4469 if (as->parms[1].items) {
4470 aserver = GetServer(as->parms[1].items->data);
4472 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4473 as->parms[1].items->data);
4476 attributes.server = ntohl(aserver);
4477 attributes.Mask |= VLLIST_SERVER;
4480 /* Partition specified */
4481 if (as->parms[2].items) {
4482 apart = volutil_GetPartitionID(as->parms[2].items->data);
4484 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4485 as->parms[2].items->data);
4488 attributes.partition = apart;
4489 attributes.Mask |= VLLIST_PARTITION;
4493 attributes.Mask |= VLLIST_FLAG;
4494 attributes.flag = VLOP_ALLOPERS;
4497 /* Print header information */
4499 MapPartIdIntoName(apart, pname);
4500 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4501 (as->parms[1].items ? "server" : "all"),
4502 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4503 (as->parms[2].items ? " partition " : ""),
4504 (as->parms[2].items ? pname : ""),
4505 (lock ? "which are locked:" : ""));
4508 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4509 memset(&arrayEntries, 0, sizeof(arrayEntries));
4514 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4515 &arrayEntries, &nextindex);
4516 if (vcode == RXGEN_OPCODE) {
4517 /* Vlserver not running with ListAttributesN2. Fall back */
4519 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4523 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4524 PrintError("", vcode);
4527 nentries += centries;
4529 /* We don't sort, so just print the entries now */
4531 for (j = 0; j < centries; j++) { /* process each entry */
4532 vllist = &arrayEntries.nbulkentries_val[j];
4533 MapHostToNetwork(vllist);
4534 EnumerateEntry(vllist);
4536 if (vllist->flags & VLOP_ALLOPERS)
4537 fprintf(STDOUT, " Volume is currently LOCKED \n");
4541 /* So we sort. First we must collect all the entries and keep
4544 else if (centries > 0) {
4546 /* steal away the first bulk entries array */
4547 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4548 tarraysize = centries * sizeof(struct nvldbentry);
4549 arrayEntries.nbulkentries_val = 0;
4551 /* Grow the tarray to keep the extra entries */
4552 parraysize = (centries * sizeof(struct nvldbentry));
4554 (struct nvldbentry *)realloc(tarray,
4555 tarraysize + parraysize);
4558 "Could not allocate enough space for the VLDB entries\n");
4564 memcpy(((char *)tarray) + tarraysize,
4565 (char *)arrayEntries.nbulkentries_val, parraysize);
4566 tarraysize += parraysize;
4570 /* Free the bulk array */
4571 if (arrayEntries.nbulkentries_val) {
4572 free(arrayEntries.nbulkentries_val);
4573 arrayEntries.nbulkentries_val = 0;
4577 /* Here is where we now sort all the entries and print them */
4578 if (sort && (nentries > 0)) {
4579 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4580 CompareVldbEntryByName);
4581 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4582 MapHostToNetwork(vllist);
4583 EnumerateEntry(vllist);
4585 if (vllist->flags & VLOP_ALLOPERS)
4586 fprintf(STDOUT, " Volume is currently LOCKED \n");
4592 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4599 BackSys(register struct cmd_syndesc *as, void *arock)
4602 afs_int32 apart = 0;
4603 afs_int32 aserver = 0, code, aserver1, apart1;
4605 struct VldbListByAttributes attributes;
4606 nbulkentries arrayEntries;
4607 register struct nvldbentry *vllist;
4611 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4612 afs_int32 totalBack = 0;
4613 afs_int32 totalFail = 0;
4617 struct cmd_item *ti;
4619 #ifndef HAVE_POSIX_REGEX
4623 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4624 attributes.Mask = 0;
4626 seenprefix = (as->parms[0].items ? 1 : 0);
4627 exclude = (as->parms[3].items ? 1 : 0);
4628 seenxprefix = (as->parms[4].items ? 1 : 0);
4629 noaction = (as->parms[5].items ? 1 : 0);
4631 if (as->parms[1].items) { /* -server */
4632 aserver = GetServer(as->parms[1].items->data);
4634 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4635 as->parms[1].items->data);
4638 attributes.server = ntohl(aserver);
4639 attributes.Mask |= VLLIST_SERVER;
4642 if (as->parms[2].items) { /* -partition */
4643 apart = volutil_GetPartitionID(as->parms[2].items->data);
4645 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4646 as->parms[2].items->data);
4649 attributes.partition = apart;
4650 attributes.Mask |= VLLIST_PARTITION;
4653 /* Check to make sure the prefix and xprefix expressions compile ok */
4655 for (ti = as->parms[0].items; ti; ti = ti->next) {
4656 if (strncmp(ti->data, "^", 1) == 0) {
4657 #ifdef HAVE_POSIX_REGEX
4661 code = regcomp(&re, ti->data, REG_NOSUB);
4663 regerror(code, &re, errbuf, sizeof errbuf);
4665 "Unrecognizable -prefix regular expression: '%s': %s\n",
4671 ccode = (char *)re_comp(ti->data);
4674 "Unrecognizable -prefix regular expression: '%s': %s\n",
4683 for (ti = as->parms[4].items; ti; ti = ti->next) {
4684 if (strncmp(ti->data, "^", 1) == 0) {
4685 #ifdef HAVE_POSIX_REGEX
4689 code = regcomp(&re, ti->data, REG_NOSUB);
4691 regerror(code, &re, errbuf, sizeof errbuf);
4693 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4699 ccode = (char *)re_comp(ti->data);
4702 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4711 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4712 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4714 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4715 PrintError("", vcode);
4719 if (as->parms[1].items || as->parms[2].items || verbose) {
4720 fprintf(STDOUT, "%s up volumes",
4721 (noaction ? "Would have backed" : "Backing"));
4723 if (as->parms[1].items) {
4724 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4725 } else if (as->parms[2].items) {
4726 fprintf(STDOUT, " for all servers");
4729 if (as->parms[2].items) {
4730 MapPartIdIntoName(apart, pname);
4731 fprintf(STDOUT, " partition %s", pname);
4734 if (seenprefix || (!seenprefix && seenxprefix)) {
4735 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4736 ex = (seenprefix ? exclude : !exclude);
4737 exp = (strncmp(ti->data, "^", 1) == 0);
4738 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4739 (exp ? "expression" : "prefix"), ti->data);
4740 for (ti = ti->next; ti; ti = ti->next) {
4741 exp = (strncmp(ti->data, "^", 1) == 0);
4742 printf(" %sor %s '%s'", (ex ? "n" : ""),
4743 (exp ? "expression" : "prefix"), ti->data);
4747 if (seenprefix && seenxprefix) {
4748 ti = as->parms[4].items;
4749 exp = (strncmp(ti->data, "^", 1) == 0);
4750 fprintf(STDOUT, " %swhich match %s '%s'",
4751 (exclude ? "adding those " : "removing those "),
4752 (exp ? "expression" : "prefix"), ti->data);
4753 for (ti = ti->next; ti; ti = ti->next) {
4754 exp = (strncmp(ti->data, "^", 1) == 0);
4755 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4759 fprintf(STDOUT, " .. ");
4761 fprintf(STDOUT, "\n");
4765 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4766 vllist = &arrayEntries.nbulkentries_val[j];
4769 for (ti = as->parms[0].items; ti; ti = ti->next) {
4770 if (strncmp(ti->data, "^", 1) == 0) {
4771 #ifdef HAVE_POSIX_REGEX
4775 /* XXX -- should just do the compile once! */
4776 code = regcomp(&re, ti->data, REG_NOSUB);
4778 regerror(code, &re, errbuf, sizeof errbuf);
4780 "Error in -prefix regular expression: '%s': %s\n",
4784 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4787 ccode = (char *)re_comp(ti->data);
4790 "Error in -prefix regular expression: '%s': %s\n",
4794 match = (re_exec(vllist->name) == 1);
4798 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4808 /* Without the -exclude flag: If it matches the prefix, then
4809 * check if we want to exclude any from xprefix.
4810 * With the -exclude flag: If it matches the prefix, then
4811 * check if we want to add any from xprefix.
4813 if (match && seenxprefix) {
4814 for (ti = as->parms[4].items; ti; ti = ti->next) {
4815 if (strncmp(ti->data, "^", 1) == 0) {
4816 #ifdef HAVE_POSIX_REGEX
4820 /* XXX -- should just do the compile once! */
4821 code = regcomp(&re, ti->data, REG_NOSUB);
4823 regerror(code, &re, errbuf, sizeof errbuf);
4825 "Error in -xprefix regular expression: '%s': %s\n",
4829 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4833 ccode = (char *)re_comp(ti->data);
4836 "Error in -xprefix regular expression: '%s': %s\n",
4840 if (re_exec(vllist->name) == 1) {
4846 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4856 match = !match; /* -exclude will reverse the match */
4858 continue; /* Skip if no match */
4860 /* Print list of volumes to backup */
4862 fprintf(STDOUT, " %s\n", vllist->name);
4866 if (!(vllist->flags & RW_EXISTS)) {
4869 "Omitting to backup %s since RW volume does not exist \n",
4871 fprintf(STDOUT, "\n");
4877 avolid = vllist->volumeId[RWVOL];
4878 MapHostToNetwork(vllist);
4879 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4880 if (aserver1 == -1 || apart1 == -1) {
4881 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4887 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4890 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4896 if ((aserver && !same) || (apart && (apart != apart1))) {
4899 "Omitting to backup %s since the RW is in a different location\n",
4905 time_t now = time(0);
4906 fprintf(STDOUT, "Creating backup volume for %s on %s",
4907 vllist->name, ctime(&now));
4911 code = UV_BackupVolume(aserver1, apart1, avolid);
4913 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4919 fprintf(STDOUT, "\n");
4921 } /* process each vldb entry */
4922 fprintf(STDOUT, "done\n");
4923 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4924 (unsigned long)totalBack, (unsigned long)totalFail);
4926 if (arrayEntries.nbulkentries_val)
4927 free(arrayEntries.nbulkentries_val);
4932 UnlockVLDB(register struct cmd_syndesc *as, void *arock)
4935 afs_int32 aserver = 0;
4938 struct VldbListByAttributes attributes;
4939 nbulkentries arrayEntries;
4940 register struct nvldbentry *vllist;
4949 attributes.Mask = 0;
4951 if (as->parms[0].items) { /* server specified */
4952 aserver = GetServer(as->parms[0].items->data);
4954 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4955 as->parms[0].items->data);
4958 attributes.server = ntohl(aserver);
4959 attributes.Mask |= VLLIST_SERVER;
4961 if (as->parms[1].items) { /* partition specified */
4962 apart = volutil_GetPartitionID(as->parms[1].items->data);
4964 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4965 as->parms[1].items->data);
4968 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4970 PrintError("", code);
4973 "vos : partition %s does not exist on the server\n",
4974 as->parms[1].items->data);
4977 attributes.partition = apart;
4978 attributes.Mask |= VLLIST_PARTITION;
4980 attributes.flag = VLOP_ALLOPERS;
4981 attributes.Mask |= VLLIST_FLAG;
4982 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4983 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4985 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4986 PrintError("", vcode);
4989 for (j = 0; j < nentries; j++) { /* process each entry */
4990 vllist = &arrayEntries.nbulkentries_val[j];
4991 volid = vllist->volumeId[RWVOL];
4993 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4994 LOCKREL_OPCODE | LOCKREL_AFSID |
4997 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4999 PrintError("", vcode);
5004 MapPartIdIntoName(apart, pname);
5007 "Could not lock %lu VLDB entries of %lu locked entries\n",
5008 (unsigned long)totalE, (unsigned long)nentries);
5010 if (as->parms[0].items) {
5012 "Unlocked all the VLDB entries for volumes on server %s ",
5013 as->parms[0].items->data);
5014 if (as->parms[1].items) {
5015 MapPartIdIntoName(apart, pname);
5016 fprintf(STDOUT, "partition %s\n", pname);
5018 fprintf(STDOUT, "\n");
5020 } else if (as->parms[1].items) {
5021 MapPartIdIntoName(apart, pname);
5023 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5028 if (arrayEntries.nbulkentries_val)
5029 free(arrayEntries.nbulkentries_val);
5034 PrintInt64Size(afs_uint64 in)
5036 register afs_uint32 hi, lo;
5037 register char * units;
5038 static char output[16];
5040 SplitInt64(in,hi,lo);
5044 } else if (!(hi & 0xFFFFFC00)) {
5046 lo = (hi << 22) | (lo >> 10);
5047 } else if (!(hi & 0xFFF00000)) {
5049 lo = (hi << 12) | (lo >> 20);
5050 } else if (!(hi & 0xC0000000)) {
5052 lo = (hi << 2) | (lo >> 30);
5057 sprintf(output,"%u %s", lo, units);
5062 PartitionInfo(register struct cmd_syndesc *as, void *arock)
5065 afs_int32 aserver, code;
5067 struct diskPartition64 partition;
5068 struct partList dummyPartList;
5070 int printSummary=0, sumPartitions=0;
5071 afs_uint64 sumFree, sumStorage;
5074 ZeroInt64(sumStorage);
5076 aserver = GetServer(as->parms[0].items->data);
5078 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5079 as->parms[0].items->data);
5082 if (as->parms[1].items) {
5083 apart = volutil_GetPartitionID(as->parms[1].items->data);
5085 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5086 as->parms[1].items->data);
5089 dummyPartList.partId[0] = apart;
5090 dummyPartList.partFlags[0] = PARTVALID;
5093 if (as->parms[2].items) {
5097 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5099 PrintError("", code);
5102 "vos : partition %s does not exist on the server\n",
5103 as->parms[1].items->data);
5107 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5109 PrintDiagnostics("listpart", code);
5113 for (i = 0; i < cnt; i++) {
5114 if (dummyPartList.partFlags[i] & PARTVALID) {
5115 MapPartIdIntoName(dummyPartList.partId[i], pname);
5116 code = UV_PartitionInfo64(aserver, pname, &partition);
5118 fprintf(STDERR, "Could not get information on partition %s\n",
5120 PrintError("", code);
5124 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5125 pname, partition.free, partition.minFree);
5127 AddUInt64(sumFree,partition.free,&sumFree);
5128 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5133 "Summary: %s free out of ",
5134 PrintInt64Size(sumFree));
5136 "%s on %d partitions\n",
5137 PrintInt64Size(sumStorage),
5144 ChangeAddr(register struct cmd_syndesc *as, void *arock)
5146 afs_int32 ip1, ip2, vcode;
5149 ip1 = GetServer(as->parms[0].items->data);
5151 fprintf(STDERR, "vos: invalid host address\n");
5155 if ((as->parms[1].items && as->parms[2].items)
5156 || (!as->parms[1].items && !as->parms[2].items)) {
5158 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5162 if (as->parms[1].items) {
5163 ip2 = GetServer(as->parms[1].items->data);
5165 fprintf(STDERR, "vos: invalid host address\n");
5169 /* Play a trick here. If we are removing an address, ip1 will be -1
5170 * and ip2 will be the original address. This switch prevents an
5171 * older revision vlserver from removing the IP address.
5178 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5181 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5182 as->parms[0].items->data);
5183 if (vcode == VL_NOENT) {
5185 "vlserver does not support the remove flag or ");
5188 fprintf(STDERR, "Could not change server %s to server %s\n",
5189 as->parms[0].items->data, as->parms[1].items->data);
5191 PrintError("", vcode);
5196 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5197 as->parms[0].items->data);
5199 fprintf(STDOUT, "Changed server %s to server %s\n",
5200 as->parms[0].items->data, as->parms[1].items->data);
5206 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5211 struct VLCallBack vlcb;
5214 ListAddrByAttributes m_attrs;
5215 afs_int32 m_nentries, *m_addrp;
5216 afs_int32 base, index;
5220 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5221 printf("UUID: %s\n", buf);
5224 /* print out the list of all the server */
5225 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5226 for (i = 0; i < nentries; i++, addrp++) {
5227 /* If it is a multihomed address, then we will need to
5228 * get the addresses for this multihomed server from
5229 * the vlserver and print them.
5231 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5232 /* Get the list of multihomed fileservers */
5233 base = (*addrp >> 16) & 0xff;
5234 index = (*addrp) & 0xffff;
5236 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5237 && (index <= VL_MHSRV_PERBLK)) {
5238 m_attrs.Mask = VLADDR_INDEX;
5239 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5241 m_addrs.bulkaddrs_val = 0;
5242 m_addrs.bulkaddrs_len = 0;
5244 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
5245 (afs_int32 *)&vlcb, &m_nentries,
5249 "vos: could not list the multi-homed server addresses\n");
5250 PrintError("", vcode);
5253 /* Print the list */
5254 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5255 for (j = 0; j < m_nentries; j++, m_addrp++) {
5256 *m_addrp = htonl(*m_addrp);
5259 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5261 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5265 printf("<unknown>\n");
5274 /* Otherwise, it is a non-multihomed entry and contains
5275 * the IP address of the server - print it.
5277 *addrp = htonl(*addrp);
5280 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5282 printf("%s\n", hostutil_GetNameByINet(*addrp));
5293 ListAddrs(register struct cmd_syndesc *as, void *arock)
5295 afs_int32 vcode, m_uniq=0;
5296 afs_int32 i, printuuid = 0;
5297 struct VLCallBack vlcb;
5300 ListAddrByAttributes m_attrs;
5301 afsUUID m_uuid, askuuid;
5302 afs_int32 m_nentries;
5304 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5305 m_attrs.Mask = VLADDR_INDEX;
5307 memset(&m_addrs, 0, sizeof(bulkaddrs));
5308 memset(&askuuid, 0, sizeof(afsUUID));
5309 if (as->parms[0].items) {
5311 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5312 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5313 as->parms[0].items->data);
5316 m_attrs.Mask = VLADDR_UUID;
5317 m_attrs.uuid = askuuid;
5319 if (as->parms[1].items) {
5323 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5325 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5326 as->parms[1].items->data);
5329 memcpy(&saddr, he->h_addr, 4);
5330 m_attrs.Mask = VLADDR_IPADDR;
5331 m_attrs.ipaddr = ntohl(saddr);
5333 if (as->parms[2].items) {
5337 m_addrs.bulkaddrs_val = 0;
5338 m_addrs.bulkaddrs_len = 0;
5341 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5344 fprintf(STDERR, "vos: could not list the server addresses\n");
5345 PrintError("", vcode);
5350 m_addrs.bulkaddrs_val = 0;
5351 m_addrs.bulkaddrs_len = 0;
5357 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5358 &m_uniq, &m_nentries, &m_addrs);
5360 if (vcode == VL_NOENT) {
5361 if (m_attrs.Mask == VLADDR_UUID) {
5362 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5363 as->parms[0].items->data);
5365 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5366 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5367 as->parms[1].items->data, m_attrs.ipaddr);
5376 if (vcode == VL_INDEXERANGE) {
5381 fprintf(STDERR, "vos: could not list the server addresses\n");
5382 PrintError("", vcode);
5386 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5389 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5397 LockEntry(register struct cmd_syndesc *as, void *arock)
5400 afs_int32 vcode, err;
5402 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5405 PrintError("", err);
5407 fprintf(STDERR, "vos: can't find volume '%s'\n",
5408 as->parms[0].items->data);
5411 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5413 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5414 as->parms[0].items->data);
5415 PrintError("", vcode);
5418 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5419 as->parms[0].items->data);
5424 ConvertRO(register struct cmd_syndesc *as, void *arock)
5426 afs_int32 partition = -1;
5428 afs_int32 server, code, i, same;
5429 struct nvldbentry entry, storeEntry;
5431 afs_int32 rwindex = 0;
5432 afs_int32 rwserver = 0;
5433 afs_int32 rwpartition = 0;
5434 afs_int32 roindex = 0;
5435 afs_int32 roserver = 0;
5436 afs_int32 ropartition = 0;
5438 struct rx_connection *aconn;
5441 server = GetServer(as->parms[0].items->data);
5443 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5444 as->parms[0].items->data);
5447 partition = volutil_GetPartitionID(as->parms[1].items->data);
5448 if (partition < 0) {
5449 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5450 as->parms[1].items->data);
5453 if (!IsPartValid(partition, server, &code)) {
5455 PrintError("", code);
5458 "vos : partition %s does not exist on the server\n",
5459 as->parms[1].items->data);
5462 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5465 PrintError("", code);
5467 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5468 as->parms[0].items->data);
5471 if (as->parms[3].items)
5474 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5477 "Could not fetch the entry for volume %lu from VLDB\n",
5478 (unsigned long)volid);
5479 PrintError("convertROtoRW", code);
5483 /* use RO volid even if user specified RW or BK volid */
5485 if (volid != entry.volumeId[ROVOL])
5486 volid = entry.volumeId[ROVOL];
5488 MapHostToNetwork(&entry);
5489 for (i = 0; i < entry.nServers; i++) {
5490 if (entry.serverFlags[i] & ITSRWVOL) {
5492 rwserver = entry.serverNumber[i];
5493 rwpartition = entry.serverPartition[i];
5495 if (entry.serverFlags[i] & ITSROVOL) {
5496 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5499 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5505 roserver = entry.serverNumber[i];
5506 ropartition = entry.serverPartition[i];
5512 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5514 if (ropartition != partition) {
5516 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5517 ropartition, partition);
5522 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5523 hostutil_GetNameByINet(rwserver),
5524 volutil_PartitionName(rwpartition));
5526 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5528 while (!(dc == EOF || dc == '\n'))
5529 dc = getchar(); /* goto end of line */
5530 if ((c != 'y') && (c != 'Y')) {
5531 fprintf(STDERR, "aborted.\n");
5538 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5540 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5541 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5544 "Converting RO volume %lu to RW volume failed with code %d\n",
5545 (unsigned long)volid, code);
5546 PrintError("convertROtoRW ", code);
5549 entry.serverFlags[roindex] = ITSRWVOL;
5550 entry.flags |= RW_EXISTS;
5551 entry.flags &= ~BACK_EXISTS;
5554 if (rwindex != entry.nServers) {
5555 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5556 entry.serverPartition[rwindex] =
5557 entry.serverPartition[entry.nServers];
5558 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5559 entry.serverNumber[entry.nServers] = 0;
5560 entry.serverPartition[entry.nServers] = 0;
5561 entry.serverFlags[entry.nServers] = 0;
5564 entry.flags &= ~RO_EXISTS;
5565 for (i = 0; i < entry.nServers; i++) {
5566 if (entry.serverFlags[i] & ITSROVOL) {
5567 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5568 entry.flags |= RO_EXISTS;
5571 MapNetworkToHost(&entry, &storeEntry);
5573 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5574 (LOCKREL_OPCODE | LOCKREL_AFSID |
5575 LOCKREL_TIMESTAMP));
5578 "Warning: volume converted, but vldb update failed with code %d!\n",
5581 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5583 PrintDiagnostics("unlock", vcode);
5589 Sizes(register struct cmd_syndesc *as, void *arock)
5592 afs_int32 aserver, apart, voltype, fromdate = 0, code, err, i;
5593 struct nvldbentry entry;
5594 volintSize vol_size;
5596 rx_SetRxDeadTime(60 * 10);
5597 for (i = 0; i < MAXSERVERS; i++) {
5598 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5601 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5602 if (rxConn->service)
5603 rxConn->service->connDeadTime = rx_connDeadTime;
5606 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5609 PrintError("", err);
5611 fprintf(STDERR, "vos: can't find volume '%s'\n",
5612 as->parms[0].items->data);
5616 if (as->parms[1].items || as->parms[2].items) {
5617 if (!as->parms[1].items || !as->parms[2].items) {
5619 "Must specify both -server and -partition options\n");
5622 aserver = GetServer(as->parms[2].items->data);
5624 fprintf(STDERR, "Invalid server name\n");
5627 apart = volutil_GetPartitionID(as->parms[1].items->data);
5629 fprintf(STDERR, "Invalid partition name\n");
5633 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5640 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5641 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5643 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5644 as->parms[4].items->data, code);
5649 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5651 if (as->parms[3].items) { /* do the dump estimate */
5652 #ifdef AFS_64BIT_ENV
5653 vol_size.dump_size = 0;
5655 FillInt64(vol_size.dump_size,0, 1);
5657 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5659 PrintDiagnostics("size", code);
5662 /* presumably the size info is now gathered in pntr */
5663 /* now we display it */
5665 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5674 PrintDiagnostics(char *astring, afs_int32 acode)
5676 if (acode == EACCES) {
5678 "You are not authorized to perform the 'vos %s' command (%d)\n",
5681 fprintf(STDERR, "Error in vos %s command.\n", astring);
5682 PrintError("", acode);
5690 win32_enableCrypt(void)
5697 /* Look up configuration parameters in Registry */
5698 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5699 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5700 if (code != ERROR_SUCCESS) {
5701 dummyLen = sizeof(cryptall);
5702 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5703 (BYTE *) &cryptall, &dummyLen);
5705 RegCloseKey (parmKey);
5709 #endif /* AFS_NT40_ENV */
5712 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5714 register char *tcell;
5715 register afs_int32 code;
5716 register afs_int32 sauth;
5718 /* Initialize the ubik_client connection */
5719 rx_SetRxDeadTime(90);
5720 cstruct = (struct ubik_client *)0;
5724 if (as->parms[12].items) /* if -cell specified */
5725 tcell = as->parms[12].items->data;
5726 if (as->parms[14].items) /* -serverauth specified */
5728 if (as->parms[16].items /* -encrypt specified */
5730 || win32_enableCrypt()
5731 #endif /* AFS_NT40_ENV */
5735 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5736 &cstruct, UV_SetSecurity))) {
5737 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5738 (unsigned long)code);
5742 if (as->parms[15].items) /* -verbose flag set */
5746 if (as->parms[17].items) /* -noresolve flag set */
5756 /* this sucks but it works for now.
5761 #include "AFS_component_version_number.c"
5764 main(int argc, char **argv)
5766 register afs_int32 code;
5768 register struct cmd_syndesc *ts;
5770 #ifdef AFS_AIX32_ENV
5772 * The following signal action for AIX is necessary so that in case of a
5773 * crash (i.e. core is generated) we can include the user's data section
5774 * in the core dump. Unfortunately, by default, only a partial core is
5775 * generated which, in many cases, isn't too useful.
5777 struct sigaction nsa;
5779 sigemptyset(&nsa.sa_mask);
5780 nsa.sa_handler = SIG_DFL;
5781 nsa.sa_flags = SA_FULLDUMP;
5782 sigaction(SIGSEGV, &nsa, NULL);
5785 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5787 cmd_SetBeforeProc(MyBeforeProc, NULL);
5789 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5790 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5791 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5792 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5793 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5794 "initial quota (KB)");
5795 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5796 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5798 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5802 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5803 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5804 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5805 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5809 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5810 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5811 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5812 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5813 "partition name on source");
5814 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5815 "machine name on destination");
5816 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5817 "partition name on destination");
5818 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5819 "copy live volume without cloning");
5822 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5823 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5824 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5825 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5826 "partition name on source");
5827 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5828 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5829 "machine name on destination");
5830 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5831 "partition name on destination");
5832 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5833 "leave new volume offline");
5834 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5835 "make new volume read-only");
5836 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5837 "copy live volume without cloning");
5840 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5841 "make or update a shadow volume");
5842 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5843 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5844 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5845 "partition name on source");
5846 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5847 "machine name on destination");
5848 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5849 "partition name on destination");
5850 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5851 "volume name on destination");
5852 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5853 "volume ID on destination");
5854 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5855 "leave shadow volume offline");
5856 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5857 "make shadow volume read-only");
5858 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5859 "copy live volume without cloning");
5860 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5861 "do incremental update if target exists");
5864 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
5865 "make backup of a volume");
5866 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5869 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
5870 "make clone of a volume");
5871 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5872 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5873 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5874 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5875 "volume name on destination");
5876 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5877 "volume ID on destination");
5878 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5879 "leave clone volume offline");
5880 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5881 "make clone volume read-only, not readwrite");
5884 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
5885 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5886 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5887 "force a complete release");
5890 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
5891 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5892 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5893 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5894 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5895 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5896 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5897 "dump a clone of the volume");
5898 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5899 "omit unchanged directories from an incremental dump");
5902 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
5903 "restore a volume");
5904 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5905 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5906 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
5907 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5908 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5909 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
5910 "abort | full | incremental");
5911 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5912 "leave restored volume offline");
5913 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5914 "make restored volume read-only");
5915 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
5916 "dump | keep | new");
5917 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
5918 "dump | keep | new");
5919 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
5920 "do not delete old site when restoring to a new site");
5923 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
5924 "release lock on VLDB entry for a volume");
5925 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5928 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
5929 "change an RW volume's location in the VLDB");
5930 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
5931 "machine name for new location");
5932 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5933 "partition name for new location");
5934 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5937 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
5938 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5939 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5940 "partition name for new site");
5941 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5942 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
5943 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
5946 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
5947 "remove a replication site");
5948 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5949 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5950 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5953 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
5954 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5957 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
5958 "list volumes on server (bypass VLDB)");
5959 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5960 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5961 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5962 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5963 "list all normal volume fields");
5964 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5965 "generate minimal information");
5966 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5967 "list extended volume fields");
5968 #ifdef FULL_LISTVOL_SWITCH
5969 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5970 "machine readable format");
5971 #endif /* FULL_LISTVOL_SWITCH */
5974 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
5975 "synchronize VLDB with server");
5976 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5977 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5978 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5979 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
5982 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
5983 "synchronize server with VLDB");
5984 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5985 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5986 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
5989 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
5990 "everything about the volume");
5991 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5992 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5993 "list extended volume fields");
5994 #ifdef FULL_LISTVOL_SWITCH
5995 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5996 "machine readable format");
5997 #endif /* FULL_LISTVOL_SWITCH */
5999 cmd_CreateAlias(ts, "volinfo");
6001 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6002 "change volume info fields");
6003 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6004 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6005 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6006 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6009 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6010 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6011 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6012 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6013 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6014 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6017 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6018 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6019 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6020 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6023 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6024 "delete the volume, don't bother with VLDB");
6025 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6026 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6027 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6028 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6029 "force deletion of bad volumes");
6030 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6031 "also delete backup volume if one is found");
6034 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6035 "report on volser status");
6036 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6039 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6040 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6041 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6044 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6045 "list volumes in the VLDB");
6046 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6047 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6048 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6049 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6050 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6051 "generate minimal information");
6052 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6053 "do not alphabetically sort the volume names");
6056 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6057 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6058 "common prefix on volume(s)");
6059 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6060 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6061 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6062 "exclude common prefix volumes");
6063 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6064 "negative prefix on volume(s)");
6065 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
6068 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6069 "delete VLDB entry for a volume");
6070 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6071 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6072 "prefix of the volume whose VLDB entry is to be deleted");
6073 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6074 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6075 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
6079 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6080 "list partition information");
6081 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6082 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6083 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6084 "print storage summary");
6087 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6088 "unlock all the locked entries in the VLDB");
6089 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6090 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6093 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6094 "lock VLDB entry for a volume");
6095 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6098 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6099 "change the IP address of a file server");
6100 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6101 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6102 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6103 "remove the IP address from the VLDB");
6106 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6107 "list the IP address of all file servers registered in the VLDB");
6108 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6109 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6110 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6111 "print uuid of hosts");
6114 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6115 "convert a RO volume into a RW volume (after loss of old RW volume)");
6116 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6117 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6118 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6119 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6122 ts = cmd_CreateSyntax("size", Sizes, NULL,
6123 "obtain various sizes of the volume.");
6124 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6125 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6126 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6127 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6128 "Obtain the size of the dump");
6129 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6132 code = cmd_Dispatch(argc, argv);
6134 /* Shut down the ubik_client and rx connections */
6136 (void)ubik_ClientDestroy(cstruct);
6142 exit((code ? -1 : 0));