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>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
20 #include <WINNT/afsreg.h>
24 #include <sys/statfs.h>
29 #include <rx/rx_queue.h>
32 #include <rx/rx_globals.h>
34 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
37 #include <afs/afsutil.h>
39 #include <afs/afsint.h>
44 #include <afs/ihandle.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/com_err.h>
51 #include "volser_internal.h"
52 #include "volser_prototypes.h"
53 #include "vsutils_prototypes.h"
54 #include "lockprocs_prototypes.h"
56 #ifdef HAVE_POSIX_REGEX
60 /* Local Prototypes */
61 int PrintDiagnostics(char *astring, afs_int32 acode);
62 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
63 afs_int32 *voltype, struct nvldbentry *rentry);
75 #define COMMONPARMS cmd_Seek(ts, 12);\
76 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
77 cmd_AddParmAlias(ts, 12, "-c"); /* original -cell option */ \
78 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
79 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
80 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
81 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
82 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
83 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
85 #define ERROR_EXIT(code) do { \
91 extern struct ubik_client *cstruct;
94 static struct tqHead busyHead, notokHead;
97 qInit(struct tqHead *ahead)
99 memset(ahead, 0, sizeof(struct tqHead));
105 qPut(struct tqHead *ahead, afs_uint32 volid)
109 elem = malloc(sizeof(struct tqElem));
110 elem->next = ahead->next;
118 qGet(struct tqHead *ahead, afs_uint32 *volid)
122 if (ahead->count <= 0)
124 *volid = ahead->next->volid;
126 ahead->next = tmp->next;
132 /* returns 1 if <filename> exists else 0 */
134 FileExists(char *filename)
140 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
144 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
152 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
154 VolNameOK(char *name)
159 total = strlen(name);
160 if (!strcmp(&name[total - 9], ".readonly")) {
162 } else if (!strcmp(&name[total - 7], ".backup")) {
169 /* return 1 if name is a number else 0 */
171 IsNumeric(char *name)
180 for (i = 0; i < len; i++) {
181 if (*ptr < '0' || *ptr > '9') {
193 * Parse a server dotted address and return the address in network byte order
196 GetServerNoresolve(char *aname)
202 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
204 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
205 addr = htonl(addr); /* convert to network byte order */
211 * Parse a server name/address and return the address in network byte order
214 GetServer(char *aname)
217 afs_uint32 addr; /* in network byte order */
219 char hostname[MAXHOSTCHARS];
221 if ((addr = GetServerNoresolve(aname)) == 0) {
222 th = gethostbyname(aname);
225 memcpy(&addr, th->h_addr, sizeof(addr));
228 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
229 code = gethostname(hostname, MAXHOSTCHARS);
232 th = gethostbyname(hostname);
235 memcpy(&addr, th->h_addr, sizeof(addr));
242 GetVolumeType(char *aname)
245 if (!strcmp(aname, "ro"))
247 else if (!strcmp(aname, "rw"))
249 else if (!strcmp(aname, "bk"))
256 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
258 struct partList dummyPartList;
264 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
267 for (i = 0; i < cnt; i++) {
268 if (dummyPartList.partFlags[i] & PARTVALID)
269 if (dummyPartList.partId[i] == partId)
277 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
278 * associated with <call> */
280 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
282 char *buffer = (char *)0;
286 buffer = malloc(blksize);
288 fprintf(STDERR, "malloc failed\n");
293 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
294 /* Only for this for non-NT, non-pthread. For NT, we can't select on
295 * non-socket FDs. For pthread environments, we don't need to select at
296 * all, since the following read() will block. */
299 FD_SET((intptr_t)(ufd->handle), &in);
300 /* don't timeout if read blocks */
301 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
303 error = USD_READ(ufd, buffer, blksize, &nbytes);
305 fprintf(STDERR, "File system read failed: %s\n",
306 afs_error_message(error));
313 if (rx_Write(call, buffer, nbytes) != nbytes) {
323 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
324 * writes it out to the volume. */
326 WriteData(struct rx_call *call, void *rock)
328 char *filename = (char *) rock;
331 afs_int32 error, code;
333 afs_int64 currOffset;
339 if (!filename || !*filename) {
340 usd_StandardInput(&ufd);
344 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
347 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
350 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
351 afs_error_message(code));
355 /* test if we have a valid dump */
356 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
357 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
358 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
359 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
360 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
364 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
366 code = SendFile(ufd, call, blksize);
373 code = USD_CLOSE(ufd);
375 fprintf(STDERR, "Could not close dump file %s\n",
376 (filename && *filename) ? filename : "STDOUT");
384 /* Receive data from <call> stream into file associated
385 * with <fd> <blksize>
388 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
392 afs_uint32 bytesleft, w;
395 buffer = malloc(blksize);
397 fprintf(STDERR, "memory allocation failed\n");
401 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
402 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
403 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
404 /* Only for this for non-NT, non-pthread. For NT, we can't select
405 * on non-socket FDs. For pthread environments, we don't need to
406 * select at all, since the following write() will block. */
409 FD_SET((intptr_t)(ufd->handle), &out);
410 /* don't timeout if write blocks */
411 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
414 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
416 fprintf(STDERR, "File system write failed: %s\n",
417 afs_error_message(error));
430 DumpFunction(struct rx_call *call, void *rock)
432 char *filename = (char *)rock;
433 usd_handle_t ufd; /* default is to stdout */
434 afs_int32 error = 0, code;
439 /* Open the output file */
440 if (!filename || !*filename) {
441 usd_StandardOutput(&ufd);
446 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
450 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
453 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
456 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
457 afs_error_message(code));
458 ERROR_EXIT(VOLSERBADOP);
462 code = ReceiveFile(ufd, call, blksize);
467 /* Close the output file */
469 code = USD_CLOSE(ufd);
471 fprintf(STDERR, "Could not close dump file %s\n",
472 (filename && *filename) ? filename : "STDIN");
482 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
483 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
484 int longlist, int disp)
490 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
491 } else if (longlist) {
492 if (pntr->status == VOK) {
493 fprintf(STDOUT, "%-32s ", pntr->name);
494 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
496 fprintf(STDOUT, "RW ");
498 fprintf(STDOUT, "RO ");
500 fprintf(STDOUT, "BK ");
501 fprintf(STDOUT, "%10d K ", pntr->size);
502 if (pntr->inUse == 1) {
503 fprintf(STDOUT, "On-line");
506 fprintf(STDOUT, "Off-line");
509 if (pntr->needsSalvaged == 1)
510 fprintf(STDOUT, "**needs salvage**");
511 fprintf(STDOUT, "\n");
512 MapPartIdIntoName(part, pname);
513 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
515 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
516 (unsigned long)pntr->parentID,
517 (unsigned long)pntr->cloneID,
518 (unsigned long)pntr->backupID);
519 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
520 t = pntr->creationDate;
521 fprintf(STDOUT, " Creation %s",
524 fprintf(STDOUT, " Copy %s",
527 t = pntr->backupDate;
529 fprintf(STDOUT, " Backup Never\n");
531 fprintf(STDOUT, " Backup %s",
534 t = pntr->accessDate;
536 fprintf(STDOUT, " Last Access %s",
539 t = pntr->updateDate;
541 fprintf(STDOUT, " Last Update Never\n");
543 fprintf(STDOUT, " Last Update %s",
546 " %d accesses in the past day (i.e., vnode references)\n",
548 } else if (pntr->status == VBUSY) {
550 qPut(&busyHead, pntr->volid);
552 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
553 (unsigned long)pntr->volid);
556 qPut(¬okHead, pntr->volid);
558 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
559 (unsigned long)pntr->volid);
561 fprintf(STDOUT, "\n");
562 } else { /* default listing */
563 if (pntr->status == VOK) {
564 fprintf(STDOUT, "%-32s ", pntr->name);
565 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
567 fprintf(STDOUT, "RW ");
569 fprintf(STDOUT, "RO ");
571 fprintf(STDOUT, "BK ");
572 fprintf(STDOUT, "%10d K ", pntr->size);
573 if (pntr->inUse == 1) {
574 fprintf(STDOUT, "On-line");
577 fprintf(STDOUT, "Off-line");
580 if (pntr->needsSalvaged == 1)
581 fprintf(STDOUT, "**needs salvage**");
582 fprintf(STDOUT, "\n");
583 } else if (pntr->status == VBUSY) {
585 qPut(&busyHead, pntr->volid);
587 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
588 (unsigned long)pntr->volid);
591 qPut(¬okHead, pntr->volid);
593 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
594 (unsigned long)pntr->volid);
599 /*------------------------------------------------------------------------
600 * PRIVATE XDisplayFormat
603 * Display the contents of one extended volume info structure.
606 * a_xInfoP : Ptr to extended volume info struct to print.
607 * a_servID : Server ID to print.
608 * a_partID : Partition ID to print.
609 * a_totalOKP : Ptr to total-OK counter.
610 * a_totalNotOKP : Ptr to total-screwed counter.
611 * a_totalBusyP : Ptr to total-busy counter.
612 * a_fast : Fast listing?
613 * a_int32 : Int32 listing?
614 * a_showProblems : Show volume problems?
620 * Nothing interesting.
624 *------------------------------------------------------------------------*/
627 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
628 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
629 int a_fast, int a_int32, int a_showProblems)
630 { /*XDisplayFormat */
638 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
639 } else if (a_int32) {
641 * Fully-detailed listing.
643 if (a_xInfoP->status == VOK) {
645 * Volume's status is OK - all the fields are valid.
647 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
648 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
649 if (a_xInfoP->type == 0)
650 fprintf(STDOUT, "RW ");
651 if (a_xInfoP->type == 1)
652 fprintf(STDOUT, "RO ");
653 if (a_xInfoP->type == 2)
654 fprintf(STDOUT, "BK ");
655 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
656 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
657 if (a_xInfoP->inUse == 1) {
658 fprintf(STDOUT, "On-line");
661 fprintf(STDOUT, "Off-line");
664 fprintf(STDOUT, "\n");
665 MapPartIdIntoName(a_partID, pname);
666 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
668 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
669 (unsigned long)a_xInfoP->parentID,
670 (unsigned long)a_xInfoP->cloneID,
671 (unsigned long)a_xInfoP->backupID);
672 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
674 t = a_xInfoP->creationDate;
675 fprintf(STDOUT, " Creation %s",
678 t = a_xInfoP->copyDate;
679 fprintf(STDOUT, " Copy %s",
682 t = a_xInfoP->backupDate;
684 fprintf(STDOUT, " Backup Never\n");
686 fprintf(STDOUT, " Backup %s",
689 t = a_xInfoP->accessDate;
691 fprintf(STDOUT, " Last Access %s",
694 t = a_xInfoP->updateDate;
696 fprintf(STDOUT, " Last Update Never\n");
698 fprintf(STDOUT, " Last Update %s",
701 " %d accesses in the past day (i.e., vnode references)\n",
705 * Print all the read/write and authorship stats.
707 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
709 " |-------------------------------------------|\n");
711 " | Same Network | Diff Network |\n");
713 " |----------|----------|----------|----------|\n");
715 " | Total | Auth | Total | Auth |\n");
717 " |----------|----------|----------|----------|\n");
718 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
719 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
720 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
721 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
722 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
723 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
724 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
725 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
726 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
727 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
729 " |-------------------------------------------|\n\n");
732 " Writes Affecting Authorship\n");
734 " |-------------------------------------------|\n");
736 " | File Authorship | Directory Authorship|\n");
738 " |----------|----------|----------|----------|\n");
740 " | Same | Diff | Same | Diff |\n");
742 " |----------|----------|----------|----------|\n");
743 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
744 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
745 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
746 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
747 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
748 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
749 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
750 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
751 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
752 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
753 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
754 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
755 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
756 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
757 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
758 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
759 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
760 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
761 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
762 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
763 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
764 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
765 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
766 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
767 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
768 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
769 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
770 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
771 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
772 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
774 " |-------------------------------------------|\n");
775 } /*Volume status OK */
776 else if (a_xInfoP->status == VBUSY) {
778 qPut(&busyHead, a_xInfoP->volid);
780 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
781 (unsigned long)a_xInfoP->volid);
785 qPut(¬okHead, a_xInfoP->volid);
787 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
788 (unsigned long)a_xInfoP->volid);
789 } /*Screwed volume */
790 fprintf(STDOUT, "\n");
796 if (a_xInfoP->status == VOK) {
797 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
798 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
799 if (a_xInfoP->type == 0)
800 fprintf(STDOUT, "RW ");
801 if (a_xInfoP->type == 1)
802 fprintf(STDOUT, "RO ");
803 if (a_xInfoP->type == 2)
804 fprintf(STDOUT, "BK ");
805 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
806 if (a_xInfoP->inUse == 1) {
807 fprintf(STDOUT, "On-line");
810 fprintf(STDOUT, "Off-line");
813 fprintf(STDOUT, "\n");
815 else if (a_xInfoP->status == VBUSY) {
817 qPut(&busyHead, a_xInfoP->volid);
819 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
820 (unsigned long)a_xInfoP->volid);
824 qPut(¬okHead, a_xInfoP->volid);
826 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
827 (unsigned long)a_xInfoP->volid);
828 } /*Screwed volume */
829 } /*Default listing */
830 } /*XDisplayFormat */
832 /*------------------------------------------------------------------------
833 * PRIVATE XDisplayFormat2
836 * Display the formated contents of one extended volume info structure.
839 * a_xInfoP : Ptr to extended volume info struct to print.
840 * a_servID : Server ID to print.
841 * a_partID : Partition ID to print.
842 * a_totalOKP : Ptr to total-OK counter.
843 * a_totalNotOKP : Ptr to total-screwed counter.
844 * a_totalBusyP : Ptr to total-busy counter.
845 * a_fast : Fast listing?
846 * a_int32 : Int32 listing?
847 * a_showProblems : Show volume problems?
853 * Nothing interesting.
857 *------------------------------------------------------------------------*/
860 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
861 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
862 int a_fast, int a_int32, int a_showProblems)
863 { /*XDisplayFormat */
869 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
870 } else if (a_int32) {
872 * Fully-detailed listing.
874 if (a_xInfoP->status == VOK) {
876 * Volume's status is OK - all the fields are valid.
879 static long server_cache = -1, partition_cache = -1;
880 static char hostname[256], address[32], pname[16];
881 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
882 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
884 if (a_servID != server_cache) {
888 strcpy(hostname, hostutil_GetNameByINet(a_servID));
889 strcpy(address, inet_ntoa(s));
890 server_cache = a_servID;
892 if (a_partID != partition_cache) {
893 MapPartIdIntoName(a_partID, pname);
894 partition_cache = a_partID;
897 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
898 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
899 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
900 fprintf(STDOUT, "part\t\t%s\n", pname);
901 fprintf(STDOUT, "status\t\tOK\n");
902 fprintf(STDOUT, "backupID\t%lu\n",
903 afs_printable_uint32_lu(a_xInfoP->backupID));
904 fprintf(STDOUT, "parentID\t%lu\n",
905 afs_printable_uint32_lu(a_xInfoP->parentID));
906 fprintf(STDOUT, "cloneID\t\t%lu\n",
907 afs_printable_uint32_lu(a_xInfoP->cloneID));
908 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
909 switch (a_xInfoP->type) {
911 fprintf(STDOUT, "type\t\tRW\n");
914 fprintf(STDOUT, "type\t\tRO\n");
917 fprintf(STDOUT, "type\t\tBK\n");
920 fprintf(STDOUT, "type\t\t?\n");
923 t = a_xInfoP->creationDate;
924 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
925 afs_printable_uint32_lu(a_xInfoP->creationDate),
928 t = a_xInfoP->accessDate;
929 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
930 afs_printable_uint32_lu(a_xInfoP->accessDate),
933 t = a_xInfoP->updateDate;
934 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
935 afs_printable_uint32_lu(a_xInfoP->updateDate),
938 t = a_xInfoP->backupDate;
939 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
940 afs_printable_uint32_lu(a_xInfoP->backupDate),
943 t = a_xInfoP->copyDate;
944 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
945 afs_printable_uint32_lu(a_xInfoP->copyDate),
948 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
949 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
951 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
952 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
956 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
957 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
958 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
959 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
961 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
962 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
963 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
964 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
968 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
969 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
970 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
971 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
974 } /*Volume status OK */
975 else if (a_xInfoP->status == VBUSY) {
977 qPut(&busyHead, a_xInfoP->volid);
979 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
980 (unsigned long)a_xInfoP->volid);
984 qPut(¬okHead, a_xInfoP->volid);
986 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
987 (unsigned long)a_xInfoP->volid);
988 } /*Screwed volume */
994 if (a_xInfoP->status == VOK) {
995 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
996 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
997 if (a_xInfoP->type == 0)
998 fprintf(STDOUT, "type\tRW\n");
999 if (a_xInfoP->type == 1)
1000 fprintf(STDOUT, "type\tRO\n");
1001 if (a_xInfoP->type == 2)
1002 fprintf(STDOUT, "type\tBK\n");
1003 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1005 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1006 if (a_xInfoP->inUse == 1)
1012 else if (a_xInfoP->status == VBUSY) {
1014 qPut(&busyHead, a_xInfoP->volid);
1016 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1017 (unsigned long)a_xInfoP->volid);
1021 qPut(¬okHead, a_xInfoP->volid);
1023 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1024 (unsigned long)a_xInfoP->volid);
1025 } /*Screwed volume */
1026 } /*Default listing */
1027 } /*XDisplayFormat */
1030 DisplayFormat2(long server, long partition, volintInfo *pntr)
1032 static long server_cache = -1, partition_cache = -1;
1033 static char hostname[256], address[32], pname[16];
1036 if (server != server_cache) {
1040 strcpy(hostname, hostutil_GetNameByINet(server));
1041 strcpy(address, inet_ntoa(s));
1042 server_cache = server;
1044 if (partition != partition_cache) {
1045 MapPartIdIntoName(partition, pname);
1046 partition_cache = partition;
1049 if (pntr->status == VOK)
1050 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1052 fprintf(STDOUT, "id\t\t%lu\n",
1053 afs_printable_uint32_lu(pntr->volid));
1054 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1055 fprintf(STDOUT, "part\t\t%s\n", pname);
1056 switch (pntr->status) {
1058 fprintf(STDOUT, "status\t\tOK\n");
1061 fprintf(STDOUT, "status\t\tBUSY\n");
1064 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1067 fprintf(STDOUT, "backupID\t%lu\n",
1068 afs_printable_uint32_lu(pntr->backupID));
1069 fprintf(STDOUT, "parentID\t%lu\n",
1070 afs_printable_uint32_lu(pntr->parentID));
1071 fprintf(STDOUT, "cloneID\t\t%lu\n",
1072 afs_printable_uint32_lu(pntr->cloneID));
1073 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1074 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1075 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1076 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1077 switch (pntr->type) {
1079 fprintf(STDOUT, "type\t\tRW\n");
1082 fprintf(STDOUT, "type\t\tRO\n");
1085 fprintf(STDOUT, "type\t\tBK\n");
1088 fprintf(STDOUT, "type\t\t?\n");
1091 t = pntr->creationDate;
1092 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1093 afs_printable_uint32_lu(pntr->creationDate),
1096 t = pntr->accessDate;
1097 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1098 afs_printable_uint32_lu(pntr->accessDate),
1101 t = pntr->updateDate;
1102 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1103 afs_printable_uint32_lu(pntr->updateDate),
1106 t = pntr->backupDate;
1107 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1108 afs_printable_uint32_lu(pntr->backupDate),
1112 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1113 afs_printable_uint32_lu(pntr->copyDate),
1116 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1117 afs_printable_uint32_lu(pntr->flags));
1118 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1119 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1120 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1121 afs_printable_uint32_lu(pntr->spare0));
1122 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1123 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1124 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1125 afs_printable_uint32_lu(pntr->spare1));
1126 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1127 afs_printable_uint32_lu(pntr->spare2));
1128 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1129 afs_printable_uint32_lu(pntr->spare3));
1134 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1138 for (i = 0; i < count; i++) {
1139 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1140 DisplayFormat2(server, partition, pntr);
1141 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1148 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1149 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1152 int totalOK, totalNotOK, totalBusy, i;
1153 afs_uint32 volid = 0;
1160 for (i = 0; i < count; i++) {
1161 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1166 while (busyHead.count) {
1167 qGet(&busyHead, &volid);
1168 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1169 (unsigned long)volid);
1173 while (notokHead.count) {
1174 qGet(¬okHead, &volid);
1175 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1176 (unsigned long)volid);
1180 fprintf(STDOUT, "\n");
1183 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1184 totalOK, totalNotOK, totalBusy);
1188 /*------------------------------------------------------------------------
1189 * PRIVATE XDisplayVolumes
1192 * Display extended volume information.
1195 * a_servID : Pointer to the Rx call we're performing.
1196 * a_partID : Partition for which we want the extended list.
1197 * a_xInfoP : Ptr to extended volume info.
1198 * a_count : Number of volume records contained above.
1199 * a_int32 : Int32 listing generated?
1200 * a_fast : Fast listing generated?
1201 * a_quiet : Quiet listing generated?
1207 * Nothing interesting.
1211 *------------------------------------------------------------------------*/
1214 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1215 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1217 { /*XDisplayVolumes */
1219 int totalOK; /*Total OK volumes */
1220 int totalNotOK; /*Total screwed volumes */
1221 int totalBusy; /*Total busy volumes */
1222 int i; /*Loop variable */
1223 afs_uint32 volid = 0; /*Current volume ID */
1226 * Initialize counters and (global!!) queues.
1235 * Display each volume in the list.
1237 for (i = 0; i < a_count; i++) {
1238 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1239 &totalBusy, a_fast, a_int32, 0);
1244 * If any volumes were found to be busy or screwed, display them.
1247 while (busyHead.count) {
1248 qGet(&busyHead, &volid);
1249 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1250 (unsigned long)volid);
1254 while (notokHead.count) {
1255 qGet(¬okHead, &volid);
1256 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1257 (unsigned long)volid);
1262 fprintf(STDOUT, "\n");
1265 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1266 totalOK, totalNotOK, totalBusy);
1270 } /*XDisplayVolumes */
1272 /*------------------------------------------------------------------------
1273 * PRIVATE XDisplayVolumes2
1276 * Display extended formated volume information.
1279 * a_servID : Pointer to the Rx call we're performing.
1280 * a_partID : Partition for which we want the extended list.
1281 * a_xInfoP : Ptr to extended volume info.
1282 * a_count : Number of volume records contained above.
1283 * a_int32 : Int32 listing generated?
1284 * a_fast : Fast listing generated?
1285 * a_quiet : Quiet listing generated?
1291 * Nothing interesting.
1295 *------------------------------------------------------------------------*/
1298 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1299 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1301 { /*XDisplayVolumes */
1303 int totalOK; /*Total OK volumes */
1304 int totalNotOK; /*Total screwed volumes */
1305 int totalBusy; /*Total busy volumes */
1306 int i; /*Loop variable */
1307 afs_uint32 volid = 0; /*Current volume ID */
1310 * Initialize counters and (global!!) queues.
1319 * Display each volume in the list.
1321 for (i = 0; i < a_count; i++) {
1322 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1323 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1324 &totalBusy, a_fast, a_int32, 0);
1325 fprintf(STDOUT, "END_OF_ENTRY\n");
1330 * If any volumes were found to be busy or screwed, display them.
1333 while (busyHead.count) {
1334 qGet(&busyHead, &volid);
1335 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1336 (unsigned long)volid);
1340 while (notokHead.count) {
1341 qGet(¬okHead, &volid);
1342 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1343 (unsigned long)volid);
1348 fprintf(STDOUT, "\n");
1351 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1352 totalOK, totalNotOK, totalBusy);
1356 } /*XDisplayVolumes2 */
1359 /* set <server> and <part> to the correct values depending on
1360 * <voltype> and <entry> */
1362 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1363 afs_int32 *part, int *previdx)
1365 int i, istart, vtype;
1370 /* Doesn't check for non-existance of backup volume */
1371 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1373 istart = 0; /* seach the entire entry */
1376 /* Seach from beginning of entry or pick up where we left off */
1377 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1380 for (i = istart; i < entry->nServers; i++) {
1381 if (entry->serverFlags[i] & vtype) {
1382 *server = entry->serverNumber[i];
1383 *part = entry->serverPartition[i];
1389 /* Didn't find any, return -1 */
1395 PrintLocked(afs_int32 aflags)
1397 afs_int32 flags = aflags & VLOP_ALLOPERS;
1400 fprintf(STDOUT, " Volume is currently LOCKED \n");
1402 if (flags & VLOP_MOVE) {
1403 fprintf(STDOUT, " Volume is locked for a move operation\n");
1405 if (flags & VLOP_RELEASE) {
1406 fprintf(STDOUT, " Volume is locked for a release operation\n");
1408 if (flags & VLOP_BACKUP) {
1409 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1411 if (flags & VLOP_DELETE) {
1412 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1414 if (flags & VLOP_DUMP) {
1415 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1421 PostVolumeStats(struct nvldbentry *entry)
1423 SubEnumerateEntry(entry);
1424 /* Check for VLOP_ALLOPERS */
1425 PrintLocked(entry->flags);
1429 /*------------------------------------------------------------------------
1430 * PRIVATE XVolumeStats
1433 * Display extended volume information.
1436 * a_xInfoP : Ptr to extended volume info.
1437 * a_entryP : Ptr to the volume's VLDB entry.
1438 * a_srvID : Server ID.
1439 * a_partID : Partition ID.
1440 * a_volType : Type of volume to print.
1446 * Nothing interesting.
1450 *------------------------------------------------------------------------*/
1453 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1454 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1457 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1459 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1460 a_srvID, /*Server ID to print */
1461 a_partID, /*Partition ID to print */
1462 &totalOK, /*Ptr to total-OK counter */
1463 &totalNotOK, /*Ptr to total-screwed counter */
1464 &totalBusy, /*Ptr to total-busy counter */
1465 0, /*Don't do a fast listing */
1466 1, /*Do a long listing */
1467 1); /*Show volume problems */
1473 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1474 afs_int32 part, int voltype)
1480 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1485 /* command to forcibly remove a volume */
1487 NukeVolume(struct cmd_syndesc *as)
1496 server = GetServer(tp = as->parms[0].items->data);
1498 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1502 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1504 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1508 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1511 PrintError("", err);
1514 "vos: could not parse '%s' as a numeric volume ID", tp);
1519 "vos: forcibly removing all traces of volume %d, please wait...",
1522 code = UV_NukeVolume(server, partID, volID);
1524 fprintf(STDOUT, "done.\n");
1526 fprintf(STDOUT, "failed with code %d.\n", code);
1531 /*------------------------------------------------------------------------
1532 * PRIVATE ExamineVolume
1535 * Routine used to examine a single volume, contacting the VLDB as
1536 * well as the Volume Server.
1539 * as : Ptr to parsed command line arguments.
1542 * 0 for a successful operation,
1543 * Otherwise, one of the ubik or VolServer error values.
1546 * Nothing interesting.
1550 *------------------------------------------------------------------------
1553 ExamineVolume(struct cmd_syndesc *as, void *arock)
1555 struct nvldbentry entry;
1556 afs_int32 vcode = 0;
1557 volintInfo *pntr = (volintInfo *) 0;
1558 volintXInfo *xInfoP = (volintXInfo *) 0;
1560 afs_int32 code, err, error = 0;
1561 int voltype, foundserv = 0, foundentry = 0;
1565 int wantExtendedInfo; /*Do we want extended vol info? */
1566 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1567 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1569 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1572 PrintError("", err);
1574 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1575 as->parms[0].items->data);
1580 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1581 (unsigned long)volid);
1584 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1587 "Could not fetch the entry for volume number %lu from VLDB \n",
1588 (unsigned long)volid);
1592 fprintf(STDOUT, "done\n");
1593 MapHostToNetwork(&entry);
1595 if (entry.volumeId[RWVOL] == volid)
1597 else if (entry.volumeId[BACKVOL] == volid)
1599 else /* (entry.volumeId[ROVOL] == volid) */
1602 do { /* do {...} while (voltype == ROVOL) */
1603 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1604 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1605 * If its a RO vol, get the next RO entry.
1607 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1608 &aserver, &apart, &previdx);
1609 if (previdx == -1) { /* searched all entries */
1611 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1612 as->parms[0].items->data);
1619 /* Get information about the volume from the server */
1621 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1622 hostutil_GetNameByINet(aserver));
1625 if (wantExtendedInfo)
1626 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1628 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1630 fprintf(STDOUT, "done\n");
1634 if (code == ENODEV) {
1635 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1636 /* The VLDB says there is no backup volume and its not on disk */
1637 fprintf(STDERR, "Volume %s does not exist\n",
1638 as->parms[0].items->data);
1642 "Volume does not exist on server %s as indicated by the VLDB\n",
1643 hostutil_GetNameByINet(aserver));
1646 PrintDiagnostics("examine", code);
1648 fprintf(STDOUT, "\n");
1651 if (wantExtendedInfo)
1652 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1653 else if (as->parms[2].items) {
1654 DisplayFormat2(aserver, apart, pntr);
1655 EnumerateEntry(&entry);
1658 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1660 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1661 /* The VLDB says there is no backup volume yet we found one on disk */
1662 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1663 as->parms[0].items->data);
1672 } while (voltype == ROVOL);
1675 fprintf(STDERR, "Dump only information from VLDB\n\n");
1676 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1680 PostVolumeStats(&entry);
1685 /*------------------------------------------------------------------------
1689 * Routine used to change the status of a single volume.
1692 * as : Ptr to parsed command line arguments.
1695 * 0 for a successful operation,
1696 * Otherwise, one of the ubik or VolServer error values.
1699 * Nothing interesting.
1703 *------------------------------------------------------------------------
1706 SetFields(struct cmd_syndesc *as, void *arock)
1708 struct nvldbentry entry;
1711 afs_int32 code, err;
1717 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1720 PrintError("", err);
1722 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1723 as->parms[0].items->data);
1727 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1730 "Could not fetch the entry for volume number %lu from VLDB \n",
1731 (unsigned long)volid);
1734 MapHostToNetwork(&entry);
1736 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1737 if (previdx == -1) {
1738 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1739 as->parms[0].items->data);
1743 init_volintInfo(&info);
1747 if (as->parms[1].items) {
1750 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1752 fprintf(STDERR, "invalid quota value\n");
1756 if (as->parms[2].items) {
1761 if (as->parms[3].items) {
1762 /* -clearVolUpCounter */
1767 fprintf(STDERR,"Nothing to set.\n");
1770 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1773 "Could not update volume info fields for volume number %lu\n",
1774 (unsigned long)volid);
1778 /*------------------------------------------------------------------------
1782 * Brings a volume online.
1785 * as : Ptr to parsed command line arguments.
1788 * 0 for a successful operation,
1791 * Nothing interesting.
1795 *------------------------------------------------------------------------
1798 volOnline(struct cmd_syndesc *as, void *arock)
1801 afs_int32 partition;
1803 afs_int32 code, err = 0;
1805 server = GetServer(as->parms[0].items->data);
1807 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1808 as->parms[0].items->data);
1812 partition = volutil_GetPartitionID(as->parms[1].items->data);
1813 if (partition < 0) {
1814 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1815 as->parms[1].items->data);
1819 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1822 PrintError("", err);
1824 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1825 as->parms[0].items->data);
1829 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1832 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1839 /*------------------------------------------------------------------------
1840 * PRIVATE volOffline
1843 * Brings a volume offline.
1846 * as : Ptr to parsed command line arguments.
1849 * 0 for a successful operation,
1852 * Nothing interesting.
1856 *------------------------------------------------------------------------
1859 volOffline(struct cmd_syndesc *as, void *arock)
1862 afs_int32 partition;
1864 afs_int32 code, err = 0;
1865 afs_int32 transflag, sleeptime, transdone;
1867 server = GetServer(as->parms[0].items->data);
1869 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1870 as->parms[0].items->data);
1874 partition = volutil_GetPartitionID(as->parms[1].items->data);
1875 if (partition < 0) {
1876 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1877 as->parms[1].items->data);
1881 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1884 PrintError("", err);
1886 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1887 as->parms[0].items->data);
1891 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1892 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1893 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1894 if (as->parms[4].items && !as->parms[3].items) {
1895 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1900 UV_SetVolume(server, partition, volid, transflag, transdone,
1903 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1911 CreateVolume(struct cmd_syndesc *as, void *arock)
1915 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1916 afs_uint32 *arovolid;
1918 struct nvldbentry entry;
1923 arovolid = &rovolid;
1926 tserver = GetServer(as->parms[0].items->data);
1928 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1929 as->parms[0].items->data);
1932 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1934 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1935 as->parms[1].items->data);
1938 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1940 PrintError("", code);
1943 "vos : partition %s does not exist on the server\n",
1944 as->parms[1].items->data);
1947 if (!ISNAMEVALID(as->parms[2].items->data)) {
1949 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1950 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1953 if (!VolNameOK(as->parms[2].items->data)) {
1955 "Illegal volume name %s, should not end in .readonly or .backup\n",
1956 as->parms[2].items->data);
1959 if (IsNumeric(as->parms[2].items->data)) {
1960 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1961 as->parms[2].items->data);
1964 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1966 fprintf(STDERR, "Volume %s already exists\n",
1967 as->parms[2].items->data);
1968 PrintDiagnostics("create", code);
1972 if (as->parms[3].items) {
1973 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1975 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1980 if (as->parms[4].items) {
1981 if (!IsNumeric(as->parms[4].items->data)) {
1982 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1983 as->parms[4].items->data);
1987 code = util_GetUInt32(as->parms[4].items->data, &volid);
1989 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1994 if (as->parms[5].items) {
1995 if (!IsNumeric(as->parms[5].items->data)) {
1996 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1997 as->parms[5].items->data);
2001 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2003 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2013 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2014 0, 0, 0, &volid, arovolid, &bkvolid);
2016 PrintDiagnostics("create", code);
2019 MapPartIdIntoName(pnum, part);
2020 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2021 (unsigned long)volid, part, as->parms[0].items->data);
2028 DeleteAll(struct nvldbentry *entry)
2031 afs_int32 error, code, curserver, curpart;
2034 MapHostToNetwork(entry);
2036 for (i = 0; i < entry->nServers; i++) {
2037 curserver = entry->serverNumber[i];
2038 curpart = entry->serverPartition[i];
2039 if (entry->serverFlags[i] & ITSROVOL) {
2040 volid = entry->volumeId[ROVOL];
2042 volid = entry->volumeId[RWVOL];
2044 code = UV_DeleteVolume(curserver, curpart, volid);
2053 DeleteVolume(struct cmd_syndesc *as, void *arock)
2055 afs_int32 err, code = 0;
2056 afs_uint32 server = 0;
2057 afs_int32 partition = -1;
2062 if (as->parms[0].items) {
2063 server = GetServer(as->parms[0].items->data);
2065 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2066 as->parms[0].items->data);
2071 if (as->parms[1].items) {
2072 partition = volutil_GetPartitionID(as->parms[1].items->data);
2073 if (partition < 0) {
2074 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2075 as->parms[1].items->data);
2079 /* Check for validity of the partition */
2080 if (!IsPartValid(partition, server, &code)) {
2082 PrintError("", code);
2085 "vos : partition %s does not exist on the server\n",
2086 as->parms[1].items->data);
2092 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2094 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2095 as->parms[2].items->data);
2097 PrintError("", err);
2101 /* If the server or partition option are not complete, try to fill
2102 * them in from the VLDB entry.
2104 if ((partition == -1) || !server) {
2105 struct nvldbentry entry;
2107 code = VLDB_GetEntryByID(volid, -1, &entry);
2110 "Could not fetch the entry for volume %lu from VLDB\n",
2111 (unsigned long)volid);
2112 PrintError("", code);
2116 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2117 || ((volid == entry.volumeId[BACKVOL])
2118 && (entry.flags & BACK_EXISTS))) {
2119 idx = Lp_GetRwIndex(&entry);
2120 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2121 || ((partition != -1)
2122 && (partition != entry.serverPartition[idx]))) {
2123 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2124 as->parms[2].items->data);
2127 } else if ((volid == entry.volumeId[ROVOL])
2128 && (entry.flags & RO_EXISTS)) {
2129 for (idx = -1, j = 0; j < entry.nServers; j++) {
2130 if (entry.serverFlags[j] != ITSROVOL)
2133 if (((server == 0) || (server == entry.serverNumber[j]))
2134 && ((partition == -1)
2135 || (partition == entry.serverPartition[j]))) {
2138 "VLDB: Volume '%s' matches more than one RO\n",
2139 as->parms[2].items->data);
2146 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2147 as->parms[2].items->data);
2151 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2152 as->parms[2].items->data);
2156 server = htonl(entry.serverNumber[idx]);
2157 partition = entry.serverPartition[idx];
2161 code = UV_DeleteVolume(server, partition, volid);
2163 PrintDiagnostics("remove", code);
2167 MapPartIdIntoName(partition, pname);
2168 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2169 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2173 #define TESTM 0 /* set for move space tests, clear for production */
2175 MoveVolume(struct cmd_syndesc *as, void *arock)
2179 afs_uint32 fromserver, toserver;
2180 afs_int32 frompart, topart;
2181 afs_int32 flags, code, err;
2182 char fromPartName[10], toPartName[10];
2184 struct diskPartition64 partition; /* for space check */
2187 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2190 PrintError("", err);
2192 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2193 as->parms[0].items->data);
2196 fromserver = GetServer(as->parms[1].items->data);
2197 if (fromserver == 0) {
2198 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2199 as->parms[1].items->data);
2202 toserver = GetServer(as->parms[3].items->data);
2203 if (toserver == 0) {
2204 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2205 as->parms[3].items->data);
2208 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2210 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2211 as->parms[2].items->data);
2214 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2216 PrintError("", code);
2219 "vos : partition %s does not exist on the server\n",
2220 as->parms[2].items->data);
2223 topart = volutil_GetPartitionID(as->parms[4].items->data);
2225 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2226 as->parms[4].items->data);
2229 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2231 PrintError("", code);
2234 "vos : partition %s does not exist on the server\n",
2235 as->parms[4].items->data);
2240 if (as->parms[5].items) flags |= RV_NOCLONE;
2243 * check source partition for space to clone volume
2246 MapPartIdIntoName(topart, toPartName);
2247 MapPartIdIntoName(frompart, fromPartName);
2250 * check target partition for space to move volume
2253 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2255 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2259 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2262 p = (volintInfo *) 0;
2263 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2265 fprintf(STDERR, "vos:cannot access volume %lu\n",
2266 (unsigned long)volid);
2270 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2272 if (partition.free <= p->size) {
2274 "vos: no space on target partition %s to move volume %lu\n",
2275 toPartName, (unsigned long)volid);
2282 fprintf(STDOUT, "size test - don't do move\n");
2286 /* successful move still not guaranteed but shoot for it */
2289 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2291 PrintDiagnostics("move", code);
2294 MapPartIdIntoName(topart, toPartName);
2295 MapPartIdIntoName(frompart, fromPartName);
2296 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2297 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2298 as->parms[3].items->data, toPartName);
2304 CopyVolume(struct cmd_syndesc *as, void *arock)
2307 afs_uint32 fromserver, toserver;
2308 afs_int32 frompart, topart, code, err, flags;
2309 char fromPartName[10], toPartName[10], *tovolume;
2310 struct nvldbentry entry;
2311 struct diskPartition64 partition; /* for space check */
2314 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2317 PrintError("", err);
2319 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2320 as->parms[0].items->data);
2323 fromserver = GetServer(as->parms[1].items->data);
2324 if (fromserver == 0) {
2325 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2326 as->parms[1].items->data);
2330 toserver = GetServer(as->parms[4].items->data);
2331 if (toserver == 0) {
2332 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2333 as->parms[4].items->data);
2337 tovolume = as->parms[3].items->data;
2338 if (!ISNAMEVALID(tovolume)) {
2340 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2341 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2344 if (!VolNameOK(tovolume)) {
2346 "Illegal volume name %s, should not end in .readonly or .backup\n",
2350 if (IsNumeric(tovolume)) {
2351 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2355 code = VLDB_GetEntryByName(tovolume, &entry);
2357 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2358 PrintDiagnostics("copy", code);
2362 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2364 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2365 as->parms[2].items->data);
2368 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2370 PrintError("", code);
2373 "vos : partition %s does not exist on the server\n",
2374 as->parms[2].items->data);
2378 topart = volutil_GetPartitionID(as->parms[5].items->data);
2380 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2381 as->parms[5].items->data);
2384 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2386 PrintError("", code);
2389 "vos : partition %s does not exist on the server\n",
2390 as->parms[5].items->data);
2395 if (as->parms[6].items) flags |= RV_OFFLINE;
2396 if (as->parms[7].items) flags |= RV_RDONLY;
2397 if (as->parms[8].items) flags |= RV_NOCLONE;
2399 MapPartIdIntoName(topart, toPartName);
2400 MapPartIdIntoName(frompart, fromPartName);
2403 * check target partition for space to move volume
2406 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2408 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2412 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2415 p = (volintInfo *) 0;
2416 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2418 fprintf(STDERR, "vos:cannot access volume %lu\n",
2419 (unsigned long)volid);
2423 if (partition.free <= p->size) {
2425 "vos: no space on target partition %s to copy volume %lu\n",
2426 toPartName, (unsigned long)volid);
2432 /* successful copy still not guaranteed but shoot for it */
2435 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2438 PrintDiagnostics("copy", code);
2441 MapPartIdIntoName(topart, toPartName);
2442 MapPartIdIntoName(frompart, fromPartName);
2443 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2444 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2445 tovolume, as->parms[4].items->data, toPartName);
2452 ShadowVolume(struct cmd_syndesc *as, void *arock)
2454 afs_uint32 volid, tovolid;
2455 afs_uint32 fromserver, toserver;
2456 afs_int32 frompart, topart;
2457 afs_int32 code, err, flags;
2458 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2459 struct diskPartition64 partition; /* for space check */
2462 p = (volintInfo *) 0;
2463 q = (volintInfo *) 0;
2465 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2468 PrintError("", err);
2470 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2471 as->parms[0].items->data);
2474 fromserver = GetServer(as->parms[1].items->data);
2475 if (fromserver == 0) {
2476 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2477 as->parms[1].items->data);
2481 toserver = GetServer(as->parms[3].items->data);
2482 if (toserver == 0) {
2483 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2484 as->parms[3].items->data);
2488 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2490 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2491 as->parms[2].items->data);
2494 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2496 PrintError("", code);
2499 "vos : partition %s does not exist on the server\n",
2500 as->parms[2].items->data);
2504 topart = volutil_GetPartitionID(as->parms[4].items->data);
2506 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2507 as->parms[4].items->data);
2510 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2512 PrintError("", code);
2515 "vos : partition %s does not exist on the server\n",
2516 as->parms[4].items->data);
2520 if (as->parms[5].items) {
2521 tovolume = as->parms[5].items->data;
2522 if (!ISNAMEVALID(tovolume)) {
2524 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2525 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2528 if (!VolNameOK(tovolume)) {
2530 "Illegal volume name %s, should not end in .readonly or .backup\n",
2534 if (IsNumeric(tovolume)) {
2536 "Illegal volume name %s, should not be a number\n",
2541 /* use actual name of source volume */
2542 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2544 fprintf(STDERR, "vos:cannot access volume %lu\n",
2545 (unsigned long)volid);
2548 strcpy(toVolName, p->name);
2549 tovolume = toVolName;
2550 /* save p for size checks later */
2553 if (as->parms[6].items) {
2554 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2557 PrintError("", err);
2559 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2560 as->parms[6].items->data);
2566 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2569 PrintError("", err);
2571 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2580 if (as->parms[7].items) flags |= RV_OFFLINE;
2581 if (as->parms[8].items) flags |= RV_RDONLY;
2582 if (as->parms[9].items) flags |= RV_NOCLONE;
2583 if (as->parms[10].items) flags |= RV_CPINCR;
2585 MapPartIdIntoName(topart, toPartName);
2586 MapPartIdIntoName(frompart, fromPartName);
2589 * check target partition for space to move volume
2592 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2594 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2598 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2601 /* Don't do this again if we did it above */
2603 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2605 fprintf(STDERR, "vos:cannot access volume %lu\n",
2606 (unsigned long)volid);
2611 /* OK if this fails */
2612 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2614 /* Treat existing volume size as "free" */
2616 p->size = (q->size < p->size) ? p->size - q->size : 0;
2618 if (partition.free <= p->size) {
2620 "vos: no space on target partition %s to copy volume %lu\n",
2621 toPartName, (unsigned long)volid);
2629 /* successful copy still not guaranteed but shoot for it */
2632 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2633 topart, tovolid, flags);
2635 PrintDiagnostics("shadow", code);
2638 MapPartIdIntoName(topart, toPartName);
2639 MapPartIdIntoName(frompart, fromPartName);
2640 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2641 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2642 as->parms[3].items->data, toPartName);
2649 CloneVolume(struct cmd_syndesc *as, void *arock)
2651 afs_uint32 volid, cloneid;
2653 afs_int32 part, voltype;
2654 char partName[10], *volname;
2655 afs_int32 code, err, flags;
2656 struct nvldbentry entry;
2658 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2661 PrintError("", err);
2663 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2664 as->parms[0].items->data);
2668 if (as->parms[1].items || as->parms[2].items) {
2669 if (!as->parms[1].items || !as->parms[2].items) {
2671 "Must specify both -server and -partition options\n");
2674 server = GetServer(as->parms[1].items->data);
2676 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2677 as->parms[1].items->data);
2680 part = volutil_GetPartitionID(as->parms[2].items->data);
2682 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2683 as->parms[2].items->data);
2686 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2688 PrintError("", code);
2691 "vos : partition %s does not exist on the server\n",
2692 as->parms[2].items->data);
2696 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2702 if (as->parms[3].items) {
2703 volname = as->parms[3].items->data;
2704 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2706 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2707 volname, VOLSER_OLDMAXVOLNAME - 1);
2712 * In order that you be able to make clones of RO or BK, this
2713 * check must be omitted.
2715 if (!VolNameOK(volname)) {
2717 "Illegal volume name %s, should not end in .readonly or .backup\n",
2722 if (IsNumeric(volname)) {
2724 "Illegal volume name %s, should not be a number\n",
2731 if (as->parms[4].items) {
2732 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2735 PrintError("", err);
2737 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2738 as->parms[4].items->data);
2744 if (as->parms[5].items) flags |= RV_OFFLINE;
2745 if (as->parms[6].items && as->parms[7].items) {
2746 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2749 if (as->parms[6].items) flags |= RV_RDONLY;
2750 if (as->parms[7].items) flags |= RV_RWONLY;
2754 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2757 PrintDiagnostics("clone", code);
2760 MapPartIdIntoName(part, partName);
2761 fprintf(STDOUT, "Created clone for volume %s\n",
2762 as->parms[0].items->data);
2769 BackupVolume(struct cmd_syndesc *as, void *arock)
2773 afs_int32 apart, vtype, code, err;
2774 struct nvldbentry entry;
2777 afs_uint32 buserver;
2778 afs_int32 bupart, butype;
2779 struct nvldbentry buentry;
2781 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2784 PrintError("", err);
2786 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2787 as->parms[0].items->data);
2790 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2794 /* verify this is a readwrite volume */
2796 if (vtype != RWVOL) {
2797 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2801 /* is there a backup volume already? */
2803 if (entry.flags & BACK_EXISTS) {
2804 /* yep, where is it? */
2806 buvolid = entry.volumeId[BACKVOL];
2807 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2812 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2815 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2821 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2822 (unsigned long)buvolid, (unsigned long)buserver);
2827 /* nope, carry on */
2829 code = UV_BackupVolume(aserver, apart, avolid);
2832 PrintDiagnostics("backup", code);
2835 fprintf(STDOUT, "Created backup volume for %s \n",
2836 as->parms[0].items->data);
2841 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2844 struct nvldbentry entry;
2847 afs_int32 apart, vtype, code, err;
2851 if (as->parms[1].items)
2853 if (as->parms[2].items)
2855 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2858 PrintError("", err);
2860 fprintf(STDERR, "vos: can't find volume '%s'\n",
2861 as->parms[0].items->data);
2864 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2868 if (vtype != RWVOL) {
2869 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2873 if (!ISNAMEVALID(entry.name)) {
2875 "Volume name %s is too long, rename before releasing\n",
2880 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2883 PrintDiagnostics("release", code);
2886 fprintf(STDOUT, "Released volume %s successfully\n",
2887 as->parms[0].items->data);
2892 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2896 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2897 char filename[MAXPATHLEN];
2898 struct nvldbentry entry;
2900 rx_SetRxDeadTime(60 * 10);
2901 for (i = 0; i < MAXSERVERS; i++) {
2902 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2905 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2906 if (rx_ServiceOf(rxConn))
2907 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2910 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2913 PrintError("", err);
2915 fprintf(STDERR, "vos: can't find volume '%s'\n",
2916 as->parms[0].items->data);
2920 if (as->parms[3].items || as->parms[4].items) {
2921 if (!as->parms[3].items || !as->parms[4].items) {
2923 "Must specify both -server and -partition options\n");
2926 aserver = GetServer(as->parms[3].items->data);
2928 fprintf(STDERR, "Invalid server name\n");
2931 apart = volutil_GetPartitionID(as->parms[4].items->data);
2933 fprintf(STDERR, "Invalid partition name\n");
2937 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2942 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2943 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2945 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2946 as->parms[1].items->data, code);
2950 if (as->parms[2].items) {
2951 strcpy(filename, as->parms[2].items->data);
2953 strcpy(filename, "");
2956 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2958 if (as->parms[5].items) {
2960 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2961 DumpFunction, filename, flags);
2964 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2967 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2968 flags &= ~VOLDUMPV2_OMITDIRS;
2972 PrintDiagnostics("dump", code);
2975 if (strcmp(filename, ""))
2976 fprintf(STDERR, "Dumped volume %s in file %s\n",
2977 as->parms[0].items->data, filename);
2979 fprintf(STDERR, "Dumped volume %s in stdout \n",
2980 as->parms[0].items->data);
2994 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2996 afs_uint32 avolid, aparentid;
2998 afs_int32 apart, code, vcode, err;
2999 afs_int32 aoverwrite = ASK;
3000 afs_int32 acreation = 0, alastupdate = 0;
3001 int restoreflags = 0;
3002 int readonly = 0, offline = 0, voltype = RWVOL;
3003 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3004 char volname[VOLSER_MAXVOLNAME + 1];
3005 struct nvldbentry entry;
3008 if (as->parms[4].items) {
3009 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3012 PrintError("", err);
3014 fprintf(STDERR, "vos: can't find volume '%s'\n",
3015 as->parms[4].items->data);
3021 if (as->parms[5].items) {
3022 if ((strcmp(as->parms[5].items->data, "a") == 0)
3023 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3025 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3026 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3028 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3029 || (strcmp(as->parms[5].items->data, "inc") == 0)
3030 || (strcmp(as->parms[5].items->data, "increment") == 0)
3031 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3034 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3035 as->parms[5].items->data);
3039 if (as->parms[6].items)
3041 if (as->parms[7].items) {
3046 if (as->parms[8].items) {
3047 if ((strcmp(as->parms[8].items->data, "d") == 0)
3048 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3049 acreation = TS_DUMP;
3050 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3051 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3052 acreation = TS_KEEP;
3053 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3054 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3057 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3058 as->parms[8].items->data);
3063 if (as->parms[9].items) {
3064 if ((strcmp(as->parms[9].items->data, "d") == 0)
3065 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3066 alastupdate = TS_DUMP;
3067 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3068 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3069 alastupdate = TS_KEEP;
3070 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3071 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3072 alastupdate = TS_NEW;
3074 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3075 as->parms[9].items->data);
3080 aserver = GetServer(as->parms[0].items->data);
3082 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3083 as->parms[0].items->data);
3086 apart = volutil_GetPartitionID(as->parms[1].items->data);
3088 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3089 as->parms[1].items->data);
3092 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3094 PrintError("", code);
3097 "vos : partition %s does not exist on the server\n",
3098 as->parms[1].items->data);
3101 strcpy(avolname, as->parms[2].items->data);
3102 if (!ISNAMEVALID(avolname)) {
3104 "vos: the name of the volume %s exceeds the size limit\n",
3108 if (!VolNameOK(avolname)) {
3110 "Illegal volume name %s, should not end in .readonly or .backup\n",
3114 if (as->parms[3].items) {
3115 strcpy(afilename, as->parms[3].items->data);
3116 if (!FileExists(afilename)) {
3117 fprintf(STDERR, "Can't access file %s\n", afilename);
3121 strcpy(afilename, "");
3124 /* Check if volume exists or not */
3126 vsu_ExtractName(volname, avolname);
3127 vcode = VLDB_GetEntryByName(volname, &entry);
3128 if (vcode) { /* no volume - do a full restore */
3129 restoreflags = RV_FULLRST;
3130 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3132 "Volume does not exist; Will perform a full restore\n");
3135 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3136 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3137 restoreflags = RV_FULLRST;
3138 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3140 "%s Volume does not exist; Will perform a full restore\n",
3141 readonly ? "RO" : "RW");
3144 avolid = entry.volumeId[voltype];
3145 } else if (entry.volumeId[voltype] != 0
3146 && entry.volumeId[voltype] != avolid) {
3147 avolid = entry.volumeId[voltype];
3149 aparentid = entry.volumeId[RWVOL];
3152 else { /* volume exists - do we do a full incremental or abort */
3154 afs_int32 Opart, Otype, vol_elsewhere = 0;
3155 struct nvldbentry Oentry;
3159 avolid = entry.volumeId[voltype];
3160 } else if (entry.volumeId[voltype] != 0
3161 && entry.volumeId[voltype] != avolid) {
3162 avolid = entry.volumeId[voltype];
3164 aparentid = entry.volumeId[RWVOL];
3166 /* A file name was specified - check if volume is on another partition */
3167 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3171 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3174 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3178 if (!vcode || (Opart != apart))
3181 if (aoverwrite == ASK) {
3182 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3184 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3188 /* Ask what to do */
3189 if (vol_elsewhere) {
3191 "The volume %s %u already exists on a different server/part\n",
3192 volname, entry.volumeId[voltype]);
3194 "Do you want to do a full restore or abort? [fa](a): ");
3197 "The volume %s %u already exists in the VLDB\n",
3198 volname, entry.volumeId[voltype]);
3200 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3203 while (!(dc == EOF || dc == '\n'))
3204 dc = getchar(); /* goto end of line */
3205 if ((c == 'f') || (c == 'F'))
3207 else if ((c == 'i') || (c == 'I'))
3213 if (aoverwrite == ABORT) {
3214 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3216 } else if (aoverwrite == FULL) {
3217 restoreflags = RV_FULLRST;
3219 "Volume exists; Will delete and perform full restore\n");
3220 } else if (aoverwrite == INC) {
3222 if (vol_elsewhere) {
3224 "%s volume %lu already exists on a different server/part; not allowed\n",
3225 readonly ? "RO" : "RW", (unsigned long)avolid);
3231 restoreflags |= RV_OFFLINE;
3233 restoreflags |= RV_RDONLY;
3235 switch (acreation) {
3237 restoreflags |= RV_CRDUMP;
3240 restoreflags |= RV_CRKEEP;
3243 restoreflags |= RV_CRNEW;
3246 if (aoverwrite == FULL)
3247 restoreflags |= RV_CRNEW;
3249 restoreflags |= RV_CRKEEP;
3252 switch (alastupdate) {
3254 restoreflags |= RV_LUDUMP;
3257 restoreflags |= RV_LUKEEP;
3260 restoreflags |= RV_LUNEW;
3263 restoreflags |= RV_LUDUMP;
3265 if (as->parms[10].items) {
3266 restoreflags |= RV_NODEL;
3271 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3272 avolname, restoreflags, WriteData, afilename);
3274 PrintDiagnostics("restore", code);
3277 MapPartIdIntoName(apart, apartName);
3280 * patch typo here - originally "parms[1]", should be "parms[0]"
3283 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3284 as->parms[0].items->data, apartName);
3289 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3292 afs_int32 code, err;
3294 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3297 PrintError("", err);
3299 fprintf(STDERR, "vos: can't find volume '%s'\n",
3300 as->parms[0].items->data);
3304 code = UV_LockRelease(avolid);
3306 PrintDiagnostics("unlock", code);
3309 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3310 as->parms[0].items->data);
3315 AddSite(struct cmd_syndesc *as, void *arock)
3319 afs_int32 apart, code, err, arovolid, valid = 0;
3320 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3322 vsu_ExtractName(avolname, as->parms[2].items->data);;
3323 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3326 PrintError("", err);
3328 fprintf(STDERR, "vos: can't find volume '%s'\n",
3329 as->parms[2].items->data);
3333 if (as->parms[3].items) {
3334 vsu_ExtractName(avolname, as->parms[3].items->data);
3335 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3337 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3338 as->parms[3].items->data);
3342 aserver = GetServer(as->parms[0].items->data);
3344 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3345 as->parms[0].items->data);
3348 apart = volutil_GetPartitionID(as->parms[1].items->data);
3350 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3351 as->parms[1].items->data);
3354 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3356 PrintError("", code);
3359 "vos : partition %s does not exist on the server\n",
3360 as->parms[1].items->data);
3363 if (as->parms[4].items) {
3366 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3368 PrintDiagnostics("addsite", code);
3371 MapPartIdIntoName(apart, apartName);
3372 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3373 as->parms[0].items->data, apartName, as->parms[2].items->data);
3378 RemoveSite(struct cmd_syndesc *as, void *arock)
3383 afs_int32 apart, code, err;
3384 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3386 vsu_ExtractName(avolname, as->parms[2].items->data);
3387 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3390 PrintError("", err);
3392 fprintf(STDERR, "vos: can't find volume '%s'\n",
3393 as->parms[2].items->data);
3396 aserver = GetServer(as->parms[0].items->data);
3398 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3399 as->parms[0].items->data);
3402 apart = volutil_GetPartitionID(as->parms[1].items->data);
3404 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3405 as->parms[1].items->data);
3409 *skip the partition validity check, since it is possible that the partition
3410 *has since been decomissioned.
3413 if (!IsPartValid(apart,aserver,&code)){
3414 if(code) PrintError("",code);
3415 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3419 code = UV_RemoveSite(aserver, apart, avolid);
3421 PrintDiagnostics("remsite", code);
3424 MapPartIdIntoName(apart, apartName);
3425 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3426 as->parms[0].items->data, apartName, as->parms[2].items->data);
3431 ChangeLocation(struct cmd_syndesc *as, void *arock)
3435 afs_int32 apart, code, err;
3438 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3441 PrintError("", err);
3443 fprintf(STDERR, "vos: can't find volume '%s'\n",
3444 as->parms[2].items->data);
3447 aserver = GetServer(as->parms[0].items->data);
3449 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3450 as->parms[0].items->data);
3453 apart = volutil_GetPartitionID(as->parms[1].items->data);
3455 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3456 as->parms[1].items->data);
3459 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3461 PrintError("", code);
3464 "vos : partition %s does not exist on the server\n",
3465 as->parms[1].items->data);
3468 code = UV_ChangeLocation(aserver, apart, avolid);
3470 PrintDiagnostics("changeloc", code);
3473 MapPartIdIntoName(apart, apartName);
3474 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3475 as->parms[0].items->data, apartName, as->parms[2].items->data);
3480 ListPartitions(struct cmd_syndesc *as, void *arock)
3484 struct partList dummyPartList;
3489 aserver = GetServer(as->parms[0].items->data);
3491 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3492 as->parms[0].items->data);
3497 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3499 PrintDiagnostics("listpart", code);
3503 fprintf(STDOUT, "The partitions on the server are:\n");
3504 for (i = 0; i < cnt; i++) {
3505 if (dummyPartList.partFlags[i] & PARTVALID) {
3506 memset(pname, 0, sizeof(pname));
3507 MapPartIdIntoName(dummyPartList.partId[i], pname);
3508 fprintf(STDOUT, " %10s ", pname);
3510 if ((i % 5) == 0 && (i != 0))
3511 fprintf(STDOUT, "\n");
3514 fprintf(STDOUT, "\n");
3515 fprintf(STDOUT, "Total: %d\n", total);
3521 CompareVolName(const void *p1, const void *p2)
3523 volintInfo *arg1, *arg2;
3525 arg1 = (volintInfo *) p1;
3526 arg2 = (volintInfo *) p2;
3527 return (strcmp(arg1->name, arg2->name));
3531 /*------------------------------------------------------------------------
3532 * PRIVATE XCompareVolName
3535 * Comparison routine for volume names coming from an extended
3539 * a_obj1P : Char ptr to first extended vol info object
3540 * a_obj1P : Char ptr to second extended vol info object
3543 * The value of strcmp() on the volume names within the passed
3544 * objects (i,e., -1, 0, or 1).
3547 * Passed to qsort() as the designated comparison routine.
3551 *------------------------------------------------------------------------*/
3554 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3555 { /*XCompareVolName */
3558 (((struct volintXInfo *)(a_obj1P))->name,
3559 ((struct volintXInfo *)(a_obj2P))->name));
3561 } /*XCompareVolName */
3564 CompareVolID(const void *p1, const void *p2)
3566 volintInfo *arg1, *arg2;
3568 arg1 = (volintInfo *) p1;
3569 arg2 = (volintInfo *) p2;
3570 if (arg1->volid == arg2->volid)
3572 if (arg1->volid > arg2->volid)
3579 /*------------------------------------------------------------------------
3580 * PRIVATE XCompareVolID
3583 * Comparison routine for volume IDs coming from an extended
3587 * a_obj1P : Char ptr to first extended vol info object
3588 * a_obj1P : Char ptr to second extended vol info object
3591 * The value of strcmp() on the volume names within the passed
3592 * objects (i,e., -1, 0, or 1).
3595 * Passed to qsort() as the designated comparison routine.
3599 *------------------------------------------------------------------------*/
3602 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3603 { /*XCompareVolID */
3605 afs_int32 id1, id2; /*Volume IDs we're comparing */
3607 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3608 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3616 } /*XCompareVolID */
3618 /*------------------------------------------------------------------------
3619 * PRIVATE ListVolumes
3622 * Routine used to list volumes, contacting the Volume Server
3623 * directly, bypassing the VLDB.
3626 * as : Ptr to parsed command line arguments.
3629 * 0 Successful operation
3632 * Nothing interesting.
3636 *------------------------------------------------------------------------*/
3639 ListVolumes(struct cmd_syndesc *as, void *arock)
3641 afs_int32 apart, int32list, fast;
3645 volintInfo *oldpntr = NULL;
3649 volintXInfo *xInfoP;
3650 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3651 int wantExtendedInfo; /*Do we want extended vol info? */
3654 struct partList dummyPartList;
3662 if (as->parms[3].items)
3664 if (as->parms[4].items)
3668 if (as->parms[2].items)
3674 if (as->parms[5].items) {
3676 * We can't coexist with the fast flag.
3680 "vos: Can't use the -fast and -extended flags together\n");
3685 * We need to turn on ``long'' listings to get the full effect.
3687 wantExtendedInfo = 1;
3690 wantExtendedInfo = 0;
3691 if (as->parms[1].items) {
3692 apart = volutil_GetPartitionID(as->parms[1].items->data);
3694 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3695 as->parms[1].items->data);
3698 dummyPartList.partId[0] = apart;
3699 dummyPartList.partFlags[0] = PARTVALID;
3702 aserver = GetServer(as->parms[0].items->data);
3704 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3705 as->parms[0].items->data);
3710 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3712 PrintError("", code);
3715 "vos : partition %s does not exist on the server\n",
3716 as->parms[1].items->data);
3720 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3722 PrintDiagnostics("listvol", code);
3726 for (i = 0; i < cnt; i++) {
3727 if (dummyPartList.partFlags[i] & PARTVALID) {
3728 if (wantExtendedInfo)
3730 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3734 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3737 PrintDiagnostics("listvol", code);
3740 if (wantExtendedInfo) {
3741 origxInfoP = xInfoP;
3742 base = (char *)xInfoP;
3745 base = (char *)pntr;
3749 if (wantExtendedInfo)
3750 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3752 qsort(base, count, sizeof(volintInfo), CompareVolName);
3754 if (wantExtendedInfo)
3755 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3757 qsort(base, count, sizeof(volintInfo), CompareVolID);
3759 MapPartIdIntoName(dummyPartList.partId[i], pname);
3762 "Total number of volumes on server %s partition %s: %lu \n",
3763 as->parms[0].items->data, pname,
3764 (unsigned long)count);
3765 if (wantExtendedInfo) {
3766 if (as->parms[6].items)
3767 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3768 count, int32list, fast, quiet);
3770 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3771 count, int32list, fast, quiet);
3774 xInfoP = (volintXInfo *) 0;
3776 if (as->parms[6].items)
3777 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3780 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3781 count, int32list, fast, quiet);
3784 pntr = (volintInfo *) 0;
3792 SyncVldb(struct cmd_syndesc *as, void *arock)
3794 afs_int32 pnum = 0, code; /* part name */
3801 if (as->parms[0].items) {
3802 tserver = GetServer(as->parms[0].items->data);
3804 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3805 as->parms[0].items->data);
3810 if (as->parms[1].items) {
3811 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3813 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3814 as->parms[1].items->data);
3817 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3819 PrintError("", code);
3822 "vos: partition %s does not exist on the server\n",
3823 as->parms[1].items->data);
3830 "The -partition option requires a -server option\n");
3835 if (as->parms[3].items) {
3836 flags |= 2; /* don't update */
3839 if (as->parms[2].items) {
3840 /* Synchronize an individual volume */
3841 volname = as->parms[2].items->data;
3842 code = UV_SyncVolume(tserver, pnum, volname, flags);
3846 "Without a -volume option, the -server option is required\n");
3849 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3853 PrintDiagnostics("syncvldb", code);
3857 /* Print a summary of what we did */
3859 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3861 fprintf(STDOUT, "VLDB synchronized");
3863 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3866 MapPartIdIntoName(pnum, part);
3867 fprintf(STDOUT, " partition %s\n", part);
3869 fprintf(STDOUT, "\n");
3875 SyncServer(struct cmd_syndesc *as, void *arock)
3877 afs_int32 pnum, code; /* part name */
3883 tserver = GetServer(as->parms[0].items->data);
3885 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3886 as->parms[0].items->data);
3889 if (as->parms[1].items) {
3890 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3892 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3893 as->parms[1].items->data);
3896 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3898 PrintError("", code);
3901 "vos : partition %s does not exist on the server\n",
3902 as->parms[1].items->data);
3910 if (as->parms[2].items) {
3911 flags |= 2; /* don't update */
3913 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3915 PrintDiagnostics("syncserv", code);
3919 MapPartIdIntoName(pnum, part);
3920 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3921 as->parms[0].items->data, part);
3923 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3924 as->parms[0].items->data);
3930 VolumeInfoCmd(char *name)
3932 struct nvldbentry entry;
3935 /* The vlserver will handle names with the .readonly
3936 * and .backup extension as well as volume ids.
3938 vcode = VLDB_GetEntryByName(name, &entry);
3940 PrintError("", vcode);
3943 MapHostToNetwork(&entry);
3944 EnumerateEntry(&entry);
3946 /* Defect #3027: grubby check to handle locked volume.
3947 * If VLOP_ALLOPERS is set, the entry is locked.
3948 * Leave this routine as is, but put in correct check.
3950 PrintLocked(entry.flags);
3956 VolumeZap(struct cmd_syndesc *as, void *arock)
3958 struct nvldbentry entry;
3959 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3960 afs_int32 code, server, part, err;
3962 if (as->parms[3].items) {
3963 /* force flag is on, use the other version */
3964 return NukeVolume(as);
3967 if (as->parms[4].items) {
3971 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3974 PrintError("", err);
3976 fprintf(STDERR, "vos: can't find volume '%s'\n",
3977 as->parms[2].items->data);
3980 part = volutil_GetPartitionID(as->parms[1].items->data);
3982 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3983 as->parms[1].items->data);
3986 server = GetServer(as->parms[0].items->data);
3988 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3989 as->parms[0].items->data);
3992 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3994 PrintError("", code);
3997 "vos : partition %s does not exist on the server\n",
3998 as->parms[1].items->data);
4001 code = VLDB_GetEntryByID(volid, -1, &entry);
4003 if (volid == entry.volumeId[RWVOL])
4004 backupid = entry.volumeId[BACKVOL];
4006 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4007 (unsigned long)volid);
4010 volintInfo *pntr = (volintInfo *) 0;
4013 code = UV_ListOneVolume(server, part, volid, &pntr);
4015 if (volid == pntr->parentID)
4016 backupid = pntr->backupID;
4022 code = UV_VolumeZap(server, part, backupid);
4024 PrintDiagnostics("zap", code);
4027 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4028 (unsigned long)backupid);
4031 code = UV_VolumeZap(server, part, volid);
4033 PrintDiagnostics("zap", code);
4036 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4042 VolserStatus(struct cmd_syndesc *as, void *arock)
4046 transDebugInfo *pntr, *oldpntr;
4052 server = GetServer(as->parms[0].items->data);
4054 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4055 as->parms[0].items->data);
4058 code = UV_VolserStatus(server, &pntr, &count);
4060 PrintDiagnostics("status", code);
4065 fprintf(STDOUT, "No active transactions on %s\n",
4066 as->parms[0].items->data);
4068 fprintf(STDOUT, "Total transactions: %d\n", count);
4070 for (i = 0; i < count; i++) {
4071 /*print out the relevant info */
4072 fprintf(STDOUT, "--------------------------------------\n");
4073 t = pntr->creationTime;
4074 fprintf(STDOUT, "transaction: %lu created: %s",
4075 (unsigned long)pntr->tid, ctime(&t));
4077 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4078 if (pntr->returnCode) {
4079 fprintf(STDOUT, "returnCode: %lu\n",
4080 (unsigned long)pntr->returnCode);
4083 fprintf(STDOUT, "attachFlags: ");
4084 switch (pntr->iflags) {
4086 fprintf(STDOUT, "offline ");
4089 fprintf(STDOUT, "busy ");
4092 fprintf(STDOUT, "readonly ");
4095 fprintf(STDOUT, "create ");
4098 fprintf(STDOUT, "create volid ");
4101 fprintf(STDOUT, "\n");
4104 fprintf(STDOUT, "volumeStatus: ");
4105 switch (pntr->vflags) {
4106 case VTDeleteOnSalvage:
4107 fprintf(STDOUT, "deleteOnSalvage ");
4108 case VTOutOfService:
4109 fprintf(STDOUT, "outOfService ");
4111 fprintf(STDOUT, "deleted ");
4113 fprintf(STDOUT, "\n");
4116 fprintf(STDOUT, "transactionFlags: ");
4117 fprintf(STDOUT, "delete\n");
4119 MapPartIdIntoName(pntr->partition, pname);
4120 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4121 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4122 if (pntr->callValid) {
4123 t = pntr->lastReceiveTime;
4124 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4125 (unsigned long)pntr->readNext, ctime(&t));
4126 t = pntr->lastSendTime;
4127 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4128 (unsigned long)pntr->transmitNext, ctime(&t));
4131 fprintf(STDOUT, "--------------------------------------\n");
4132 fprintf(STDOUT, "\n");
4140 RenameVolume(struct cmd_syndesc *as, void *arock)
4142 afs_int32 code1, code2, code;
4143 struct nvldbentry entry;
4145 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4147 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4148 as->parms[0].items->data);
4151 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4152 if ((!code1) && (!code2)) { /*the newname already exists */
4153 fprintf(STDERR, "vos: volume %s already exists\n",
4154 as->parms[1].items->data);
4158 if (code1 && code2) {
4159 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4160 as->parms[0].items->data, as->parms[1].items->data);
4163 if (!VolNameOK(as->parms[0].items->data)) {
4165 "Illegal volume name %s, should not end in .readonly or .backup\n",
4166 as->parms[0].items->data);
4169 if (!ISNAMEVALID(as->parms[1].items->data)) {
4171 "vos: the new volume name %s exceeds the size limit of %d\n",
4172 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4175 if (!VolNameOK(as->parms[1].items->data)) {
4177 "Illegal volume name %s, should not end in .readonly or .backup\n",
4178 as->parms[1].items->data);
4181 if (IsNumeric(as->parms[1].items->data)) {
4182 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4183 as->parms[1].items->data);
4186 MapHostToNetwork(&entry);
4188 UV_RenameVolume(&entry, as->parms[0].items->data,
4189 as->parms[1].items->data);
4191 PrintDiagnostics("rename", code);
4194 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4195 as->parms[1].items->data);
4200 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4201 struct nvldbentry *rentry)
4206 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4209 "Could not fetch the entry for volume %lu from VLDB \n",
4210 (unsigned long)volid);
4211 PrintError("", vcode);
4214 MapHostToNetwork(rentry);
4215 if (volid == rentry->volumeId[ROVOL]) {
4217 for (i = 0; i < rentry->nServers; i++) {
4218 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4219 && !(rentry->serverFlags[i] & RO_DONTUSE))
4224 "RO volume is not found in VLDB entry for volume %lu\n",
4225 (unsigned long)volid);
4229 *server = rentry->serverNumber[index];
4230 *part = rentry->serverPartition[index];
4234 index = Lp_GetRwIndex(rentry);
4237 "RW Volume is not found in VLDB entry for volume %lu\n",
4238 (unsigned long)volid);
4241 if (volid == rentry->volumeId[RWVOL]) {
4243 *server = rentry->serverNumber[index];
4244 *part = rentry->serverPartition[index];
4247 if (volid == rentry->volumeId[BACKVOL]) {
4249 *server = rentry->serverNumber[index];
4250 *part = rentry->serverPartition[index];
4254 "unexpected volume type for volume %lu\n",
4255 (unsigned long)volid);
4260 DeleteEntry(struct cmd_syndesc *as, void *arock)
4262 afs_int32 apart = 0;
4265 struct VldbListByAttributes attributes;
4266 nbulkentries arrayEntries;
4267 struct nvldbentry *vllist;
4268 struct cmd_item *itp;
4271 char prefix[VOLSER_MAXVOLNAME + 1];
4273 afs_int32 totalBack = 0, totalFail = 0, err;
4275 if (as->parms[0].items) { /* -id */
4276 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4278 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4281 for (itp = as->parms[0].items; itp; itp = itp->next) {
4282 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4285 PrintError("", err);
4287 fprintf(STDERR, "vos: can't find volume '%s'\n",
4291 if (as->parms[4].items || as->parms[5].items) {
4292 /* -noexecute (hidden) or -dryrun */
4293 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4298 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4300 fprintf(STDERR, "Could not delete entry for volume %s\n",
4303 "You must specify a RW volume name or ID "
4304 "(the entire VLDB entry will be deleted)\n");
4305 PrintError("", vcode);
4311 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4315 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4316 fprintf(STDERR, "You must specify an option\n");
4320 /* Zero out search attributes */
4321 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4323 if (as->parms[1].items) { /* -prefix */
4324 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4326 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4328 "You must provide -server with the -prefix argument\n");
4333 if (as->parms[2].items) { /* -server */
4335 aserver = GetServer(as->parms[2].items->data);
4337 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4338 as->parms[2].items->data);
4341 attributes.server = ntohl(aserver);
4342 attributes.Mask |= VLLIST_SERVER;
4345 if (as->parms[3].items) { /* -partition */
4346 if (!as->parms[2].items) {
4348 "You must provide -server with the -partition argument\n");
4351 apart = volutil_GetPartitionID(as->parms[3].items->data);
4353 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4354 as->parms[3].items->data);
4357 attributes.partition = apart;
4358 attributes.Mask |= VLLIST_PARTITION;
4361 /* Print status line of what we are doing */
4362 fprintf(STDOUT, "Deleting VLDB entries for ");
4363 if (as->parms[2].items) {
4364 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4366 if (as->parms[3].items) {
4368 MapPartIdIntoName(apart, pname);
4369 fprintf(STDOUT, "partition %s ", pname);
4372 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4374 fprintf(STDOUT, "\n");
4377 /* Get all the VLDB entries on a server and/or partition */
4378 memset(&arrayEntries, 0, sizeof(arrayEntries));
4379 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4381 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4382 PrintError("", vcode);
4386 /* Process each entry */
4387 for (j = 0; j < nentries; j++) {
4388 vllist = &arrayEntries.nbulkentries_val[j];
4390 /* It only deletes the RW volumes */
4391 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4394 "Omitting to delete %s due to prefix %s mismatch\n",
4395 vllist->name, prefix);
4402 if (as->parms[4].items || as->parms[5].items) {
4403 /* -noexecute (hidden) or -dryrun */
4404 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4410 /* Only matches the RW volume name */
4411 avolid = vllist->volumeId[RWVOL];
4412 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4414 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4417 PrintError("", vcode);
4422 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4427 fprintf(STDOUT, "----------------------\n");
4429 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4430 (unsigned long)totalBack, (unsigned long)totalFail);
4432 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4438 CompareVldbEntryByName(const void *p1, const void *p2)
4440 struct nvldbentry *arg1, *arg2;
4442 arg1 = (struct nvldbentry *)p1;
4443 arg2 = (struct nvldbentry *)p2;
4444 return (strcmp(arg1->name, arg2->name));
4448 static int CompareVldbEntry(char *p1, char *p2)
4450 struct nvldbentry *arg1,*arg2;
4453 char comp1[100],comp2[100];
4454 char temp1[20],temp2[20];
4456 arg1 = (struct nvldbentry *)p1;
4457 arg2 = (struct nvldbentry *)p2;
4461 for(i = 0; i < arg1->nServers; i++)
4462 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4463 for(i = 0; i < arg2->nServers; i++)
4464 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4465 if(pos1 == -1 || pos2 == -1){
4469 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4470 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4471 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4472 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4473 strcat(comp1,temp1);
4474 strcat(comp2,temp2);
4475 strcat(comp1,arg1->name);
4476 strcat(comp1,arg2->name);
4477 return(strcmp(comp1,comp2));
4483 ListVLDB(struct cmd_syndesc *as, void *arock)
4488 struct VldbListByAttributes attributes;
4489 nbulkentries arrayEntries;
4490 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4491 afs_int32 centries, nentries = 0;
4492 afs_int32 tarraysize = 0;
4493 afs_int32 parraysize;
4496 int quiet, sort, lock;
4497 afs_int32 thisindex, nextindex;
4501 attributes.Mask = 0;
4502 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4503 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4504 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4506 /* If the volume name is given, Use VolumeInfoCmd to look it up
4507 * and not ListAttributes.
4509 if (as->parms[0].items) {
4512 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4515 code = VolumeInfoCmd(as->parms[0].items->data);
4517 PrintError("", code);
4523 /* Server specified */
4524 if (as->parms[1].items) {
4527 aserver = GetServer(as->parms[1].items->data);
4529 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4530 as->parms[1].items->data);
4533 attributes.server = ntohl(aserver);
4534 attributes.Mask |= VLLIST_SERVER;
4537 /* Partition specified */
4538 if (as->parms[2].items) {
4539 apart = volutil_GetPartitionID(as->parms[2].items->data);
4541 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4542 as->parms[2].items->data);
4545 attributes.partition = apart;
4546 attributes.Mask |= VLLIST_PARTITION;
4550 attributes.Mask |= VLLIST_FLAG;
4551 attributes.flag = VLOP_ALLOPERS;
4554 /* Print header information */
4556 MapPartIdIntoName(apart, pname);
4557 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4558 (as->parms[1].items ? "server" : "all"),
4559 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4560 (as->parms[2].items ? " partition " : ""),
4561 (as->parms[2].items ? pname : ""),
4562 (lock ? "which are locked:" : ""));
4565 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4566 memset(&arrayEntries, 0, sizeof(arrayEntries));
4571 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4572 &arrayEntries, &nextindex);
4573 if (vcode == RXGEN_OPCODE) {
4574 /* Vlserver not running with ListAttributesN2. Fall back */
4576 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4580 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4581 PrintError("", vcode);
4584 nentries += centries;
4586 /* We don't sort, so just print the entries now */
4588 for (j = 0; j < centries; j++) { /* process each entry */
4589 vllist = &arrayEntries.nbulkentries_val[j];
4590 MapHostToNetwork(vllist);
4591 EnumerateEntry(vllist);
4593 PrintLocked(vllist->flags);
4597 /* So we sort. First we must collect all the entries and keep
4600 else if (centries > 0) {
4602 /* malloc the first bulk entries array */
4603 tarraysize = centries * sizeof(struct nvldbentry);
4604 tarray = malloc(tarraysize);
4607 "Could not allocate enough space for the VLDB entries\n");
4610 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4612 /* Grow the tarray to keep the extra entries */
4613 parraysize = (centries * sizeof(struct nvldbentry));
4614 ttarray = realloc(tarray, tarraysize + parraysize);
4617 "Could not allocate enough space for the VLDB entries\n");
4623 memcpy(((char *)tarray) + tarraysize,
4624 (char *)arrayEntries.nbulkentries_val, parraysize);
4625 tarraysize += parraysize;
4629 /* Free the bulk array */
4630 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4633 /* Here is where we now sort all the entries and print them */
4634 if (sort && (nentries > 0)) {
4635 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4636 CompareVldbEntryByName);
4637 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4638 MapHostToNetwork(vllist);
4639 EnumerateEntry(vllist);
4641 PrintLocked(vllist->flags);
4647 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4654 BackSys(struct cmd_syndesc *as, void *arock)
4657 afs_int32 apart = 0;
4658 afs_uint32 aserver = 0, aserver1;
4659 afs_int32 code, apart1;
4661 struct VldbListByAttributes attributes;
4662 nbulkentries arrayEntries;
4663 struct nvldbentry *vllist;
4667 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4668 afs_int32 totalBack = 0;
4669 afs_int32 totalFail = 0;
4673 struct cmd_item *ti;
4675 #ifndef HAVE_POSIX_REGEX
4679 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4680 attributes.Mask = 0;
4682 seenprefix = (as->parms[0].items ? 1 : 0);
4683 exclude = (as->parms[3].items ? 1 : 0);
4684 seenxprefix = (as->parms[4].items ? 1 : 0);
4685 noaction = (as->parms[5].items ? 1 : 0);
4687 if (as->parms[1].items) { /* -server */
4688 aserver = GetServer(as->parms[1].items->data);
4690 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4691 as->parms[1].items->data);
4694 attributes.server = ntohl(aserver);
4695 attributes.Mask |= VLLIST_SERVER;
4698 if (as->parms[2].items) { /* -partition */
4699 apart = volutil_GetPartitionID(as->parms[2].items->data);
4701 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4702 as->parms[2].items->data);
4705 attributes.partition = apart;
4706 attributes.Mask |= VLLIST_PARTITION;
4709 /* Check to make sure the prefix and xprefix expressions compile ok */
4711 for (ti = as->parms[0].items; ti; ti = ti->next) {
4712 if (strncmp(ti->data, "^", 1) == 0) {
4713 #ifdef HAVE_POSIX_REGEX
4717 code = regcomp(&re, ti->data, REG_NOSUB);
4719 regerror(code, &re, errbuf, sizeof errbuf);
4721 "Unrecognizable -prefix regular expression: '%s': %s\n",
4727 ccode = (char *)re_comp(ti->data);
4730 "Unrecognizable -prefix regular expression: '%s': %s\n",
4739 for (ti = as->parms[4].items; ti; ti = ti->next) {
4740 if (strncmp(ti->data, "^", 1) == 0) {
4741 #ifdef HAVE_POSIX_REGEX
4745 code = regcomp(&re, ti->data, REG_NOSUB);
4747 regerror(code, &re, errbuf, sizeof errbuf);
4749 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4755 ccode = (char *)re_comp(ti->data);
4758 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4767 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4768 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4770 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4771 PrintError("", vcode);
4775 if (as->parms[1].items || as->parms[2].items || verbose) {
4776 fprintf(STDOUT, "%s up volumes",
4777 (noaction ? "Would have backed" : "Backing"));
4779 if (as->parms[1].items) {
4780 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4781 } else if (as->parms[2].items) {
4782 fprintf(STDOUT, " for all servers");
4785 if (as->parms[2].items) {
4786 MapPartIdIntoName(apart, pname);
4787 fprintf(STDOUT, " partition %s", pname);
4790 if (seenprefix || (!seenprefix && seenxprefix)) {
4791 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4792 ex = (seenprefix ? exclude : !exclude);
4793 exp = (strncmp(ti->data, "^", 1) == 0);
4794 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4795 (exp ? "expression" : "prefix"), ti->data);
4796 for (ti = ti->next; ti; ti = ti->next) {
4797 exp = (strncmp(ti->data, "^", 1) == 0);
4798 printf(" %sor %s '%s'", (ex ? "n" : ""),
4799 (exp ? "expression" : "prefix"), ti->data);
4803 if (seenprefix && seenxprefix) {
4804 ti = as->parms[4].items;
4805 exp = (strncmp(ti->data, "^", 1) == 0);
4806 fprintf(STDOUT, " %swhich match %s '%s'",
4807 (exclude ? "adding those " : "removing those "),
4808 (exp ? "expression" : "prefix"), ti->data);
4809 for (ti = ti->next; ti; ti = ti->next) {
4810 exp = (strncmp(ti->data, "^", 1) == 0);
4811 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4815 fprintf(STDOUT, " .. ");
4817 fprintf(STDOUT, "\n");
4821 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4822 vllist = &arrayEntries.nbulkentries_val[j];
4825 for (ti = as->parms[0].items; ti; ti = ti->next) {
4826 if (strncmp(ti->data, "^", 1) == 0) {
4827 #ifdef HAVE_POSIX_REGEX
4831 /* XXX -- should just do the compile once! */
4832 code = regcomp(&re, ti->data, REG_NOSUB);
4834 regerror(code, &re, errbuf, sizeof errbuf);
4836 "Error in -prefix regular expression: '%s': %s\n",
4840 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4843 ccode = (char *)re_comp(ti->data);
4846 "Error in -prefix regular expression: '%s': %s\n",
4850 match = (re_exec(vllist->name) == 1);
4854 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4864 /* Without the -exclude flag: If it matches the prefix, then
4865 * check if we want to exclude any from xprefix.
4866 * With the -exclude flag: If it matches the prefix, then
4867 * check if we want to add any from xprefix.
4869 if (match && seenxprefix) {
4870 for (ti = as->parms[4].items; ti; ti = ti->next) {
4871 if (strncmp(ti->data, "^", 1) == 0) {
4872 #ifdef HAVE_POSIX_REGEX
4876 /* XXX -- should just do the compile once! */
4877 code = regcomp(&re, ti->data, REG_NOSUB);
4879 regerror(code, &re, errbuf, sizeof errbuf);
4881 "Error in -xprefix regular expression: '%s': %s\n",
4885 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4889 ccode = (char *)re_comp(ti->data);
4892 "Error in -xprefix regular expression: '%s': %s\n",
4896 if (re_exec(vllist->name) == 1) {
4902 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4912 match = !match; /* -exclude will reverse the match */
4914 continue; /* Skip if no match */
4916 /* Print list of volumes to backup */
4918 fprintf(STDOUT, " %s\n", vllist->name);
4922 if (!(vllist->flags & RW_EXISTS)) {
4925 "Omitting to backup %s since RW volume does not exist \n",
4927 fprintf(STDOUT, "\n");
4933 avolid = vllist->volumeId[RWVOL];
4934 MapHostToNetwork(vllist);
4935 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4936 if (aserver1 == -1 || apart1 == -1) {
4937 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4943 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4946 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4952 if ((aserver && !same) || (apart && (apart != apart1))) {
4955 "Omitting to backup %s since the RW is in a different location\n",
4961 time_t now = time(0);
4962 fprintf(STDOUT, "Creating backup volume for %s on %s",
4963 vllist->name, ctime(&now));
4967 code = UV_BackupVolume(aserver1, apart1, avolid);
4969 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4975 fprintf(STDOUT, "\n");
4977 } /* process each vldb entry */
4978 fprintf(STDOUT, "done\n");
4979 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4980 (unsigned long)totalBack, (unsigned long)totalFail);
4982 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4987 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4990 afs_uint32 aserver = 0;
4993 struct VldbListByAttributes attributes;
4994 nbulkentries arrayEntries;
4995 struct nvldbentry *vllist;
5004 attributes.Mask = 0;
5006 if (as->parms[0].items) { /* server specified */
5007 aserver = GetServer(as->parms[0].items->data);
5009 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5010 as->parms[0].items->data);
5013 attributes.server = ntohl(aserver);
5014 attributes.Mask |= VLLIST_SERVER;
5016 if (as->parms[1].items) { /* partition specified */
5017 apart = volutil_GetPartitionID(as->parms[1].items->data);
5019 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5020 as->parms[1].items->data);
5023 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5025 PrintError("", code);
5028 "vos : partition %s does not exist on the server\n",
5029 as->parms[1].items->data);
5032 attributes.partition = apart;
5033 attributes.Mask |= VLLIST_PARTITION;
5035 attributes.flag = VLOP_ALLOPERS;
5036 attributes.Mask |= VLLIST_FLAG;
5037 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5038 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5040 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5041 PrintError("", vcode);
5044 for (j = 0; j < nentries; j++) { /* process each entry */
5045 vllist = &arrayEntries.nbulkentries_val[j];
5046 volid = vllist->volumeId[RWVOL];
5048 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5049 LOCKREL_OPCODE | LOCKREL_AFSID |
5052 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5054 PrintError("", vcode);
5059 MapPartIdIntoName(apart, pname);
5062 "Could not lock %lu VLDB entries of %lu locked entries\n",
5063 (unsigned long)totalE, (unsigned long)nentries);
5065 if (as->parms[0].items) {
5067 "Unlocked all the VLDB entries for volumes on server %s ",
5068 as->parms[0].items->data);
5069 if (as->parms[1].items) {
5070 MapPartIdIntoName(apart, pname);
5071 fprintf(STDOUT, "partition %s\n", pname);
5073 fprintf(STDOUT, "\n");
5075 } else if (as->parms[1].items) {
5076 MapPartIdIntoName(apart, pname);
5078 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5083 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5088 PrintInt64Size(afs_uint64 in)
5092 static char output[16];
5094 SplitInt64(in,hi,lo);
5098 } else if (!(hi & 0xFFFFFC00)) {
5100 lo = (hi << 22) | (lo >> 10);
5101 } else if (!(hi & 0xFFF00000)) {
5103 lo = (hi << 12) | (lo >> 20);
5104 } else if (!(hi & 0xC0000000)) {
5106 lo = (hi << 2) | (lo >> 30);
5111 sprintf(output,"%u %s", lo, units);
5116 PartitionInfo(struct cmd_syndesc *as, void *arock)
5122 struct diskPartition64 partition;
5123 struct partList dummyPartList;
5125 int printSummary=0, sumPartitions=0;
5126 afs_uint64 sumFree, sumStorage;
5129 ZeroInt64(sumStorage);
5131 aserver = GetServer(as->parms[0].items->data);
5133 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5134 as->parms[0].items->data);
5137 if (as->parms[1].items) {
5138 apart = volutil_GetPartitionID(as->parms[1].items->data);
5140 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5141 as->parms[1].items->data);
5144 dummyPartList.partId[0] = apart;
5145 dummyPartList.partFlags[0] = PARTVALID;
5148 if (as->parms[2].items) {
5152 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5154 PrintError("", code);
5157 "vos : partition %s does not exist on the server\n",
5158 as->parms[1].items->data);
5162 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5164 PrintDiagnostics("listpart", code);
5168 for (i = 0; i < cnt; i++) {
5169 if (dummyPartList.partFlags[i] & PARTVALID) {
5170 MapPartIdIntoName(dummyPartList.partId[i], pname);
5171 code = UV_PartitionInfo64(aserver, pname, &partition);
5173 fprintf(STDERR, "Could not get information on partition %s\n",
5175 PrintError("", code);
5179 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5180 pname, partition.free, partition.minFree);
5182 AddUInt64(sumFree,partition.free,&sumFree);
5183 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5188 "Summary: %s free out of ",
5189 PrintInt64Size(sumFree));
5191 "%s on %d partitions\n",
5192 PrintInt64Size(sumStorage),
5199 ChangeAddr(struct cmd_syndesc *as, void *arock)
5201 afs_int32 ip1, ip2, vcode;
5205 ip1 = GetServerNoresolve(as->parms[0].items->data);
5207 ip1 = GetServer(as->parms[0].items->data);
5209 fprintf(STDERR, "vos: invalid host address\n");
5213 if ((as->parms[1].items && as->parms[2].items)
5214 || (!as->parms[1].items && !as->parms[2].items)) {
5216 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5220 if (as->parms[1].items) {
5222 ip2 = GetServerNoresolve(as->parms[1].items->data);
5224 ip2 = GetServer(as->parms[1].items->data);
5226 fprintf(STDERR, "vos: invalid host address\n");
5230 /* Play a trick here. If we are removing an address, ip1 will be -1
5231 * and ip2 will be the original address. This switch prevents an
5232 * older revision vlserver from removing the IP address.
5239 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5241 char hoststr1[16], hoststr2[16];
5243 afs_inet_ntoa_r(ip2, hoststr2);
5244 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5246 if (vcode == VL_NOENT) {
5248 "vlserver does not support the remove flag or ");
5251 afs_inet_ntoa_r(ip1, hoststr1);
5252 afs_inet_ntoa_r(ip2, hoststr2);
5253 fprintf(STDERR, "Could not change server %s to server %s\n",
5254 hoststr1, hoststr2);
5256 PrintError("", vcode);
5261 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5262 as->parms[0].items->data);
5264 fprintf(STDOUT, "Changed server %s to server %s\n",
5265 as->parms[0].items->data, as->parms[1].items->data);
5271 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5279 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5280 printf("UUID: %s\n", buf);
5283 /* print out the list of all the server */
5284 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5285 for (i = 0; i < nentries; i++, addrp++) {
5286 *addrp = htonl(*addrp);
5289 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5291 printf("%s\n", hostutil_GetNameByINet(*addrp));
5302 ListAddrs(struct cmd_syndesc *as, void *arock)
5304 afs_int32 vcode, m_uniq=0;
5305 afs_int32 i, printuuid = 0;
5306 struct VLCallBack vlcb;
5309 ListAddrByAttributes m_attrs;
5310 afsUUID m_uuid, askuuid;
5311 afs_int32 m_nentries;
5313 if (as->parms[0].items && as->parms[1].items) {
5314 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5318 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5319 memset(&askuuid, 0, sizeof(afsUUID));
5320 if (as->parms[0].items) {
5322 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5323 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5324 as->parms[0].items->data);
5327 m_attrs.Mask = VLADDR_UUID;
5328 m_attrs.uuid = askuuid;
5329 } else if (as->parms[1].items) {
5333 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5335 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5336 as->parms[1].items->data);
5339 memcpy(&saddr, he->h_addr, 4);
5340 m_attrs.Mask = VLADDR_IPADDR;
5341 m_attrs.ipaddr = ntohl(saddr);
5344 m_attrs.Mask = VLADDR_INDEX;
5347 if (as->parms[2].items) {
5351 memset(&m_addrs, 0, sizeof(bulkaddrs));
5352 memset(&vlcb, 0, sizeof(struct VLCallBack));
5355 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5358 fprintf(STDERR, "vos: could not list the server addresses\n");
5359 PrintError("", vcode);
5363 for (i = 1, m_nentries = 0; nentries; i++) {
5366 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5368 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5369 &m_uniq, &m_nentries, &m_addrs);
5371 case 0: /* success */
5372 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5377 if (m_attrs.Mask == VLADDR_UUID) {
5378 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5379 as->parms[0].items->data);
5381 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5382 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5383 as->parms[1].items->data, m_attrs.ipaddr);
5388 case VL_INDEXERANGE:
5389 vcode = 0; /* not an error, just means we're done */
5392 default: /* any other error */
5393 fprintf(STDERR, "vos: could not list the server addresses\n");
5394 PrintError("", vcode);
5398 /* if -uuid or -host, only list one response */
5399 if (as->parms[1].items || as->parms[0].items)
5404 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5410 SetAddrs(struct cmd_syndesc *as, void *arock)
5415 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5417 memset(&m_addrs, 0, sizeof(bulkaddrs));
5418 memset(&askuuid, 0, sizeof(afsUUID));
5419 if (as->parms[0].items) {
5421 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5422 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5423 as->parms[0].items->data);
5427 if (as->parms[1].items) {
5429 struct cmd_item *ti;
5433 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5436 saddr = GetServerNoresolve(ti->data);
5438 saddr = GetServer(ti->data);
5441 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5445 /* Convert it to host byte order */
5446 FS_HostAddrs_HBO[i] = ntohl(saddr);
5449 m_addrs.bulkaddrs_len = i;
5450 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5453 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5456 if (vcode == VL_MULTIPADDR) {
5457 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5458 } else if (vcode == RXGEN_OPCODE) {
5459 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5461 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5463 PrintError("", vcode);
5467 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5468 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5474 LockEntry(struct cmd_syndesc *as, void *arock)
5477 afs_int32 vcode, err;
5479 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5482 PrintError("", err);
5484 fprintf(STDERR, "vos: can't find volume '%s'\n",
5485 as->parms[0].items->data);
5488 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5490 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5491 as->parms[0].items->data);
5492 PrintError("", vcode);
5495 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5496 as->parms[0].items->data);
5501 ConvertRO(struct cmd_syndesc *as, void *arock)
5503 afs_int32 partition = -1;
5506 afs_int32 code, i, same;
5507 struct nvldbentry entry, checkEntry, storeEntry;
5509 afs_int32 rwindex = 0;
5510 afs_uint32 rwserver = 0;
5511 afs_int32 rwpartition = 0;
5512 afs_int32 roindex = 0;
5513 afs_uint32 roserver = 0;
5514 afs_int32 ropartition = 0;
5516 struct rx_connection *aconn;
5519 server = GetServer(as->parms[0].items->data);
5521 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5522 as->parms[0].items->data);
5525 partition = volutil_GetPartitionID(as->parms[1].items->data);
5526 if (partition < 0) {
5527 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5528 as->parms[1].items->data);
5531 if (!IsPartValid(partition, server, &code)) {
5533 PrintError("", code);
5536 "vos : partition %s does not exist on the server\n",
5537 as->parms[1].items->data);
5540 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5543 PrintError("", code);
5545 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5546 as->parms[2].items->data);
5549 if (as->parms[3].items)
5552 memset(&entry, 0, sizeof(entry));
5553 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5556 "Could not fetch the entry for volume %lu from VLDB\n",
5557 (unsigned long)volid);
5558 PrintError("convertROtoRW ", vcode);
5562 /* use RO volid even if user specified RW or BK volid */
5563 if (volid != entry.volumeId[ROVOL])
5564 volid = entry.volumeId[ROVOL];
5566 MapHostToNetwork(&entry);
5567 for (i = 0; i < entry.nServers; i++) {
5568 if (entry.serverFlags[i] & ITSRWVOL) {
5570 rwserver = entry.serverNumber[i];
5571 rwpartition = entry.serverPartition[i];
5574 } else if ((entry.serverFlags[i] & ITSROVOL) && !roserver) {
5575 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5578 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5584 roserver = entry.serverNumber[i];
5585 ropartition = entry.serverPartition[i];
5592 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5594 if (roserver && (ropartition != partition)) {
5596 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5597 ropartition, partition);
5602 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5603 hostutil_GetNameByINet(rwserver),
5604 volutil_PartitionName(rwpartition));
5606 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5608 while (!(dc == EOF || dc == '\n'))
5609 dc = getchar(); /* goto end of line */
5610 if ((c != 'y') && (c != 'Y')) {
5611 fprintf(STDERR, "aborted.\n");
5618 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5622 "Unable to lock volume %lu, code %d\n",
5623 (unsigned long)entry.volumeId[RWVOL],vcode);
5624 PrintError("", vcode);
5628 /* make sure the VLDB entry hasn't changed since we started */
5629 memset(&checkEntry, 0, sizeof(checkEntry));
5630 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
5633 "Could not fetch the entry for volume %lu from VLDB\n",
5634 (unsigned long)volid);
5635 PrintError("convertROtoRW ", vcode);
5640 MapHostToNetwork(&checkEntry);
5641 entry.flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
5642 entry.flags |= VLOP_MOVE; /* set to match SetLock operation above */
5643 if (memcmp(&entry, &checkEntry, sizeof(entry)) != 0) {
5645 "VLDB entry for volume %lu has changed; please reissue the command.\n",
5646 (unsigned long)volid);
5651 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5652 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5655 "Converting RO volume %lu to RW volume failed with code %d\n",
5656 (unsigned long)volid, code);
5657 PrintError("convertROtoRW ", code);
5660 /* Update the VLDB to match what we did on disk as much as possible. */
5661 /* If the converted RO was in the VLDB, make it look like the new RW. */
5663 entry.serverFlags[roindex] = ITSRWVOL;
5665 /* Add a new site entry for the newly created RW. It's possible
5666 * (but unlikely) that we are already at MAXNSERVERS and that this
5667 * new site will invalidate the whole VLDB entry; however,
5668 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
5669 * so we need no extra guard logic here.
5671 afs_int32 newrwindex = entry.nServers;
5673 entry.serverNumber[newrwindex] = server;
5674 entry.serverPartition[newrwindex] = partition;
5675 entry.serverFlags[newrwindex] = ITSRWVOL;
5677 entry.flags |= RW_EXISTS;
5678 entry.flags &= ~BACK_EXISTS;
5680 /* if the old RW was in the VLDB, remove it by decrementing the number */
5681 /* of servers, replacing the RW entry with the last entry, and zeroing */
5682 /* out the last entry. */
5685 if (rwindex != entry.nServers) {
5686 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5687 entry.serverPartition[rwindex] =
5688 entry.serverPartition[entry.nServers];
5689 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5690 entry.serverNumber[entry.nServers] = 0;
5691 entry.serverPartition[entry.nServers] = 0;
5692 entry.serverFlags[entry.nServers] = 0;
5695 entry.flags &= ~RO_EXISTS;
5696 for (i = 0; i < entry.nServers; i++) {
5697 if (entry.serverFlags[i] & ITSROVOL) {
5698 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5699 entry.flags |= RO_EXISTS;
5702 MapNetworkToHost(&entry, &storeEntry);
5704 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5705 (LOCKREL_OPCODE | LOCKREL_AFSID |
5706 LOCKREL_TIMESTAMP));
5709 "Warning: volume converted, but vldb update failed with code %d!\n",
5714 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5717 "Unable to unlock volume %lu, code %d\n",
5718 (unsigned long)entry.volumeId[RWVOL],vcode);
5719 PrintError("", vcode);
5725 Sizes(struct cmd_syndesc *as, void *arock)
5729 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5730 struct nvldbentry entry;
5731 volintSize vol_size;
5733 rx_SetRxDeadTime(60 * 10);
5734 for (i = 0; i < MAXSERVERS; i++) {
5735 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5738 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5739 if (rx_ServiceOf(rxConn))
5740 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5743 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5746 PrintError("", err);
5748 fprintf(STDERR, "vos: can't find volume '%s'\n",
5749 as->parms[0].items->data);
5753 if (as->parms[1].items || as->parms[2].items) {
5754 if (!as->parms[1].items || !as->parms[2].items) {
5756 "Must specify both -server and -partition options\n");
5759 aserver = GetServer(as->parms[2].items->data);
5761 fprintf(STDERR, "Invalid server name\n");
5764 apart = volutil_GetPartitionID(as->parms[1].items->data);
5766 fprintf(STDERR, "Invalid partition name\n");
5770 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5777 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5778 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5780 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5781 as->parms[4].items->data, code);
5786 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5788 if (as->parms[3].items) { /* do the dump estimate */
5789 vol_size.dump_size = 0;
5790 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5792 PrintDiagnostics("size", code);
5795 /* presumably the size info is now gathered in pntr */
5796 /* now we display it */
5798 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5807 EndTrans(struct cmd_syndesc *as, void *arock)
5810 afs_int32 code, tid, rcode;
5811 struct rx_connection *aconn;
5813 server = GetServer(as->parms[0].items->data);
5815 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5816 as->parms[0].items->data);
5820 code = util_GetInt32(as->parms[1].items->data, &tid);
5822 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5826 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5827 code = AFSVolEndTrans(aconn, tid, &rcode);
5833 PrintDiagnostics("endtrans", code);
5841 PrintDiagnostics(char *astring, afs_int32 acode)
5843 if (acode == EACCES) {
5845 "You are not authorized to perform the 'vos %s' command (%d)\n",
5848 fprintf(STDERR, "Error in vos %s command.\n", astring);
5849 PrintError("", acode);
5857 win32_enableCrypt(void)
5864 /* Look up configuration parameters in Registry */
5865 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5866 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5867 if (code != ERROR_SUCCESS) {
5868 dummyLen = sizeof(cryptall);
5869 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5870 (BYTE *) &cryptall, &dummyLen);
5872 RegCloseKey (parmKey);
5876 #endif /* AFS_NT40_ENV */
5879 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5885 /* Initialize the ubik_client connection */
5886 rx_SetRxDeadTime(90);
5888 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5891 if (as->parms[12].items) /* if -cell specified */
5892 tcell = as->parms[12].items->data;
5894 if (as->parms[13].items)
5895 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5897 if (as->parms[14].items) { /* -localauth specified */
5898 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5899 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5902 if (as->parms[16].items /* -encrypt specified */
5904 || win32_enableCrypt()
5905 #endif /* AFS_NT40_ENV */
5907 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5909 if (as->parms[18].items) /* -config flag set */
5910 confdir = as->parms[18].items->data;
5912 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5914 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5915 (unsigned long)code);
5919 if (as->parms[15].items) /* -verbose flag set */
5923 if (as->parms[17].items) /* -noresolve flag set */
5934 /* this sucks but it works for now.
5939 #include "AFS_component_version_number.c"
5942 main(int argc, char **argv)
5946 struct cmd_syndesc *ts;
5948 #ifdef AFS_AIX32_ENV
5950 * The following signal action for AIX is necessary so that in case of a
5951 * crash (i.e. core is generated) we can include the user's data section
5952 * in the core dump. Unfortunately, by default, only a partial core is
5953 * generated which, in many cases, isn't too useful.
5955 struct sigaction nsa;
5957 sigemptyset(&nsa.sa_mask);
5958 nsa.sa_handler = SIG_DFL;
5959 nsa.sa_flags = SA_FULLDUMP;
5960 sigaction(SIGSEGV, &nsa, NULL);
5963 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5965 cmd_SetBeforeProc(MyBeforeProc, NULL);
5967 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5968 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5969 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5970 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5971 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5972 "initial quota (KB)");
5973 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5974 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5976 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5980 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5981 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5982 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5983 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5987 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5988 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5989 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5990 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5991 "partition name on source");
5992 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5993 "machine name on destination");
5994 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5995 "partition name on destination");
5996 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5997 "copy live volume without cloning");
6000 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
6001 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6002 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6003 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6004 "partition name on source");
6005 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
6006 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6007 "machine name on destination");
6008 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6009 "partition name on destination");
6010 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6011 "leave new volume offline");
6012 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6013 "make new volume read-only");
6014 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6015 "copy live volume without cloning");
6018 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6019 "make or update a shadow volume");
6020 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6021 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6022 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6023 "partition name on source");
6024 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6025 "machine name on destination");
6026 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6027 "partition name on destination");
6028 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6029 "volume name on destination");
6030 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6031 "volume ID on destination");
6032 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6033 "leave shadow volume offline");
6034 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6035 "make shadow volume read-only");
6036 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6037 "copy live volume without cloning");
6038 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6039 "do incremental update if target exists");
6042 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6043 "make backup of a volume");
6044 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6047 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6048 "make clone of a volume");
6049 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6050 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6051 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6052 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6053 "volume name on destination");
6054 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6055 "volume ID on destination");
6056 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6057 "leave clone volume offline");
6058 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6059 "make clone volume read-only, not readwrite");
6060 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6061 "make clone volume readwrite, not read-only");
6064 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6065 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6066 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6067 "force a complete release");
6068 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
6069 "release to cloned temp vol, then clone back to repsite RO");
6072 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6073 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6074 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6075 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6076 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6077 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6078 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6079 "dump a clone of the volume");
6080 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6081 "omit unchanged directories from an incremental dump");
6084 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6085 "restore a volume");
6086 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6087 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6088 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6089 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6090 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6091 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6092 "abort | full | incremental");
6093 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6094 "leave restored volume offline");
6095 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6096 "make restored volume read-only");
6097 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6098 "dump | keep | new");
6099 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6100 "dump | keep | new");
6101 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6102 "do not delete old site when restoring to a new site");
6105 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6106 "release lock on VLDB entry for a volume");
6107 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6110 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6111 "change an RW volume's location in the VLDB");
6112 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6113 "machine name for new location");
6114 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6115 "partition name for new location");
6116 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6119 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6120 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6121 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6122 "partition name for new site");
6123 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6124 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6125 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6128 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6129 "remove a replication site");
6130 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6131 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6132 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6135 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6136 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6139 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6140 "list volumes on server (bypass VLDB)");
6141 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6142 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6143 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6144 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6145 "list all normal volume fields");
6146 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6147 "generate minimal information");
6148 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6149 "list extended volume fields");
6150 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6151 "machine readable format");
6154 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6155 "synchronize VLDB with server");
6156 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6157 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6158 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6159 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6162 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6163 "synchronize server with VLDB");
6164 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6165 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6166 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6169 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6170 "everything about the volume");
6171 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6172 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6173 "list extended volume fields");
6174 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6175 "machine readable format");
6177 cmd_CreateAlias(ts, "volinfo");
6178 cmd_CreateAlias(ts, "e");
6180 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6181 "change volume info fields");
6182 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6183 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6184 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6185 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6188 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6189 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6190 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6191 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6192 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6193 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6196 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6197 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6198 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6199 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6202 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6203 "delete the volume, don't bother with VLDB");
6204 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6205 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6206 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6207 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6208 "force deletion of bad volumes");
6209 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6210 "also delete backup volume if one is found");
6213 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6214 "report on volser status");
6215 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6218 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6219 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6220 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6223 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6224 "list volumes in the VLDB");
6225 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6226 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6227 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6228 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6229 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6230 "generate minimal information");
6231 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6232 "do not alphabetically sort the volume names");
6235 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6236 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6237 "common prefix on volume(s)");
6238 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6239 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6240 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6241 "exclude common prefix volumes");
6242 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6243 "negative prefix on volume(s)");
6244 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6247 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6248 "delete VLDB entry for a volume");
6249 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6250 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6251 "prefix of the volume whose VLDB entry is to be deleted");
6252 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6253 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6254 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6255 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6256 "list what would be done, don't do it");
6259 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6260 "list partition information");
6261 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6262 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6263 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6264 "print storage summary");
6267 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6268 "unlock all the locked entries in the VLDB");
6269 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6270 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6273 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6274 "lock VLDB entry for a volume");
6275 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6278 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6279 "change the IP address of a file server");
6280 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6281 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6282 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6283 "remove the IP address from the VLDB");
6286 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6287 "list the IP address of all file servers registered in the VLDB");
6288 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6289 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6290 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6291 "print uuid of hosts");
6294 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6295 "convert a RO volume into a RW volume (after loss of old RW volume)");
6296 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6297 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6298 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6299 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6302 ts = cmd_CreateSyntax("size", Sizes, NULL,
6303 "obtain various sizes of the volume.");
6304 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6305 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6306 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6307 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6308 "Obtain the size of the dump");
6309 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6312 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6313 "end a volserver transaction");
6314 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6315 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6319 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6320 "set the list of IP address for a given UUID in the VLDB");
6321 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6322 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6325 code = cmd_Dispatch(argc, argv);
6327 /* Shut down the ubik_client and rx connections */
6329 (void)ubik_ClientDestroy(cstruct);
6335 exit((code ? -1 : 0));