2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
31 #include <sys/statfs.h>
39 #include <rx/rx_globals.h>
41 #include <afs/vlserver.h>
42 #include <afs/cellconfig.h>
44 #include <afs/afsutil.h>
46 #include <afs/afsint.h>
51 #include <afs/ihandle.h>
52 #include <afs/vnode.h>
53 #include <afs/volume.h>
60 #include "volser_prototypes.h"
61 #include "vsutils_prototypes.h"
62 #include "lockprocs_prototypes.h"
64 #ifdef HAVE_POSIX_REGEX
68 /* Local Prototypes */
69 int PrintDiagnostics(char *astring, afs_int32 acode);
70 int GetVolumeInfo(afs_uint32 volid, afs_int32 *server, afs_int32 *part,
71 afs_int32 *voltype, struct nvldbentry *rentry);
83 #define COMMONPARMS cmd_Seek(ts, 12);\
84 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
85 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
86 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
87 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
88 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
89 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
91 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
94 struct rx_connection *tconn;
96 extern struct ubik_client *cstruct;
99 static struct tqHead busyHead, notokHead;
102 qInit(struct tqHead *ahead)
104 memset((char *)ahead, 0, sizeof(struct tqHead));
110 qPut(struct tqHead *ahead, afs_uint32 volid)
114 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
115 elem->next = ahead->next;
123 qGet(struct tqHead *ahead, afs_int32 *volid)
127 if (ahead->count <= 0)
129 *volid = ahead->next->volid;
131 ahead->next = tmp->next;
137 /* returns 1 if <filename> exists else 0 */
139 FileExists(char *filename)
145 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
149 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
157 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
159 VolNameOK(char *name)
164 total = strlen(name);
165 if (!strcmp(&name[total - 9], ".readonly")) {
167 } else if (!strcmp(&name[total - 7], ".backup")) {
174 /* return 1 if name is a number else 0 */
176 IsNumeric(char *name)
184 for (i = 0; i < len; i++) {
185 if (*ptr < '0' || *ptr > '9') {
197 * Parse a server name/address and return the address in HOST BYTE order
200 GetServer(char *aname)
202 register struct hostent *th;
205 register afs_int32 code;
206 char hostname[MAXHOSTCHARS];
208 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
210 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
211 addr = ntohl(addr); /* convert to host order */
213 th = gethostbyname(aname);
216 memcpy(&addr, th->h_addr, sizeof(addr));
219 if (addr == htonl(0x7f000001)) { /* local host */
220 code = gethostname(hostname, MAXHOSTCHARS);
223 th = gethostbyname(hostname); /* returns host byte order */
226 memcpy(&addr, th->h_addr, sizeof(addr));
233 GetVolumeType(char *aname)
236 if (!strcmp(aname, "ro"))
238 else if (!strcmp(aname, "rw"))
240 else if (!strcmp(aname, "bk"))
247 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
249 struct partList dummyPartList;
255 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
258 for (i = 0; i < cnt; i++) {
259 if (dummyPartList.partFlags[i] & PARTVALID)
260 if (dummyPartList.partId[i] == partId)
268 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
269 * associated with <call> */
271 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
273 char *buffer = (char *)0;
278 buffer = (char *)malloc(blksize);
280 fprintf(STDERR, "malloc failed\n");
284 while (!error && !done) {
285 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
288 FD_SET((int)(ufd->handle), &in);
289 /* don't timeout if read blocks */
290 #if defined(AFS_PTHREAD_ENV)
291 select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
293 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
296 error = USD_READ(ufd, buffer, blksize, &nbytes);
298 fprintf(STDERR, "File system read failed\n");
305 if (rx_Write(call, buffer, nbytes) != nbytes) {
315 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
316 * writes it out to the volume. */
318 WriteData(struct rx_call *call, char *rock)
323 afs_int32 error, code;
325 afs_hyper_t filesize, currOffset;
332 if (!filename || !*filename) {
333 usd_StandardInput(&ufd);
337 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
340 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
343 fprintf(STDERR, "Could not access file '%s'\n", filename);
347 /* test if we have a valid dump */
348 hset64(filesize, 0, 0);
349 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
350 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
351 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
352 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
353 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
354 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
358 /* rewind, we are done */
359 hset64(filesize, 0, 0);
360 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
362 code = SendFile(ufd, call, blksize);
369 code = USD_CLOSE(ufd);
371 fprintf(STDERR, "Could not close dump file %s\n",
372 (filename && *filename) ? filename : "STDOUT");
380 /* Receive data from <call> stream into file associated
381 * with <fd> <blksize>
384 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
388 afs_uint32 bytesleft, w;
391 buffer = (char *)malloc(blksize);
393 fprintf(STDERR, "memory allocation failed\n");
397 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
398 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
399 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
402 FD_SET((int)(ufd->handle), &out);
403 /* don't timeout if write blocks */
404 #if defined(AFS_PTHREAD_ENV)
405 select(((int)(ufd->handle)) + 1, &out, 0, 0, 0);
407 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
411 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
413 fprintf(STDERR, "File system write failed\n");
426 DumpFunction(struct rx_call *call, char *filename)
428 usd_handle_t ufd; /* default is to stdout */
429 afs_int32 error = 0, code;
434 /* Open the output file */
435 if (!filename || !*filename) {
436 usd_StandardOutput(&ufd);
441 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
445 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
448 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
451 fprintf(STDERR, "Could not create file '%s'\n", filename);
452 ERROR_EXIT(VOLSERBADOP);
456 code = ReceiveFile(ufd, call, blksize);
461 /* Close the output file */
463 code = USD_CLOSE(ufd);
465 fprintf(STDERR, "Could not close dump file %s\n",
466 (filename && *filename) ? filename : "STDIN");
476 vos_ctime(afs_int32 *timep)
483 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
486 afs_int32 server, part;
487 int *totalOK, *totalNotOK, *totalBusy;
488 int fast, longlist, disp;
493 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
494 } else if (longlist) {
495 if (pntr->status == VOK) {
496 fprintf(STDOUT, "%-32s ", pntr->name);
497 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
499 fprintf(STDOUT, "RW ");
501 fprintf(STDOUT, "RO ");
503 fprintf(STDOUT, "BK ");
504 fprintf(STDOUT, "%10d K ", pntr->size);
505 if (pntr->inUse == 1) {
506 fprintf(STDOUT, "On-line");
509 fprintf(STDOUT, "Off-line");
512 if (pntr->needsSalvaged == 1)
513 fprintf(STDOUT, "**needs salvage**");
514 fprintf(STDOUT, "\n");
515 MapPartIdIntoName(part, pname);
516 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
518 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
519 (unsigned long)pntr->parentID,
520 (unsigned long)pntr->cloneID,
521 (unsigned long)pntr->backupID);
522 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
523 fprintf(STDOUT, " Creation %s",
524 vos_ctime(& pntr->creationDate));
525 #ifdef FULL_LISTVOL_SWITCH
526 fprintf(STDOUT, " Copy %s",
527 vos_ctime( & pntr->copyDate));
528 if (!pntr->backupDate)
529 fprintf(STDOUT, " Backup Never\n");
531 fprintf(STDOUT, " Backup %s",
532 vos_ctime( & pntr->backupDate));
533 if (pntr->accessDate)
534 fprintf(STDOUT, " Last Access %s",
535 vos_ctime( & pntr->accessDate));
537 if (!pntr->updateDate)
538 fprintf(STDOUT, " Last Update Never\n");
540 fprintf(STDOUT, " Last Update %s",
541 vos_ctime( & pntr->updateDate));
543 " %d accesses in the past day (i.e., vnode references)\n",
546 } else if (pntr->status == VBUSY) {
548 qPut(&busyHead, pntr->volid);
550 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
551 (unsigned long)pntr->volid);
554 qPut(¬okHead, pntr->volid);
556 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
557 (unsigned long)pntr->volid);
559 fprintf(STDOUT, "\n");
560 } else { /* default listing */
561 if (pntr->status == VOK) {
562 fprintf(STDOUT, "%-32s ", pntr->name);
563 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
565 fprintf(STDOUT, "RW ");
567 fprintf(STDOUT, "RO ");
569 fprintf(STDOUT, "BK ");
570 fprintf(STDOUT, "%10d K ", pntr->size);
571 if (pntr->inUse == 1) {
572 fprintf(STDOUT, "On-line");
575 fprintf(STDOUT, "Off-line");
578 if (pntr->needsSalvaged == 1)
579 fprintf(STDOUT, "**needs salvage**");
580 fprintf(STDOUT, "\n");
581 } else if (pntr->status == VBUSY) {
583 qPut(&busyHead, pntr->volid);
585 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
586 (unsigned long)pntr->volid);
589 qPut(¬okHead, pntr->volid);
591 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
592 (unsigned long)pntr->volid);
597 /*------------------------------------------------------------------------
598 * PRIVATE XDisplayFormat
601 * Display the contents of one extended volume info structure.
604 * a_xInfoP : Ptr to extended volume info struct to print.
605 * a_servID : Server ID to print.
606 * a_partID : Partition ID to print.
607 * a_totalOKP : Ptr to total-OK counter.
608 * a_totalNotOKP : Ptr to total-screwed counter.
609 * a_totalBusyP : Ptr to total-busy counter.
610 * a_fast : Fast listing?
611 * a_int32 : Int32 listing?
612 * a_showProblems : Show volume problems?
618 * Nothing interesting.
622 *------------------------------------------------------------------------*/
625 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
626 a_totalBusyP, a_fast, a_int32, a_showProblems)
627 volintXInfo *a_xInfoP;
637 { /*XDisplayFormat */
645 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
646 } else if (a_int32) {
648 * Fully-detailed listing.
650 if (a_xInfoP->status == VOK) {
652 * Volume's status is OK - all the fields are valid.
654 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
655 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
656 if (a_xInfoP->type == 0)
657 fprintf(STDOUT, "RW ");
658 if (a_xInfoP->type == 1)
659 fprintf(STDOUT, "RO ");
660 if (a_xInfoP->type == 2)
661 fprintf(STDOUT, "BK ");
662 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
663 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
664 if (a_xInfoP->inUse == 1) {
665 fprintf(STDOUT, "On-line");
668 fprintf(STDOUT, "Off-line");
671 fprintf(STDOUT, "\n");
672 MapPartIdIntoName(a_partID, pname);
673 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
675 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
676 (unsigned long)a_xInfoP->parentID,
677 (unsigned long)a_xInfoP->cloneID,
678 (unsigned long)a_xInfoP->backupID);
679 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
680 fprintf(STDOUT, " Creation %s",
681 vos_ctime( & a_xInfoP->creationDate));
682 #ifdef FULL_LISTVOL_SWITCH
683 fprintf(STDOUT, " Copy %s",
684 vos_ctime( & a_xInfoP->copyDate));
685 if (!a_xInfoP->backupDate)
686 fprintf(STDOUT, " Backup Never\n");
688 fprintf(STDOUT, " Backup %s",
689 vos_ctime( & a_xInfoP->backupDate));
690 if (a_xInfoP->accessDate)
691 fprintf(STDOUT, " Last Access %s",
692 vos_ctime( & a_xInfoP->accessDate));
694 if (!a_xInfoP->updateDate)
695 fprintf(STDOUT, " Last Update Never\n");
697 fprintf(STDOUT, " Last Update %s",
698 vos_ctime( & a_xInfoP->updateDate));
700 " %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 #ifdef FULL_LISTVOL_SWITCH
833 /*------------------------------------------------------------------------
834 * PRIVATE XDisplayFormat2
837 * Display the formated contents of one extended volume info structure.
840 * a_xInfoP : Ptr to extended volume info struct to print.
841 * a_servID : Server ID to print.
842 * a_partID : Partition ID to print.
843 * a_totalOKP : Ptr to total-OK counter.
844 * a_totalNotOKP : Ptr to total-screwed counter.
845 * a_totalBusyP : Ptr to total-busy counter.
846 * a_fast : Fast listing?
847 * a_int32 : Int32 listing?
848 * a_showProblems : Show volume problems?
854 * Nothing interesting.
858 *------------------------------------------------------------------------*/
861 XDisplayFormat2(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
862 a_totalBusyP, a_fast, a_int32, a_showProblems)
863 volintXInfo *a_xInfoP;
873 { /*XDisplayFormat */
878 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
879 } else if (a_int32) {
881 * Fully-detailed listing.
883 if (a_xInfoP->status == VOK) {
885 * Volume's status is OK - all the fields are valid.
888 static long server_cache = -1, partition_cache = -1;
889 static char hostname[256], address[32], pname[16];
890 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
891 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
893 if (a_servID != server_cache) {
897 strcpy(hostname, hostutil_GetNameByINet(a_servID));
898 strcpy(address, inet_ntoa(s));
899 server_cache = a_servID;
901 if (a_partID != partition_cache) {
902 MapPartIdIntoName(a_partID, pname);
903 partition_cache = a_partID;
906 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
907 fprintf(STDOUT, "id\t\t%lu\n", afs_cast_uint32(a_xInfoP->volid));
908 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
909 fprintf(STDOUT, "part\t\t%s\n", pname);
910 switch (a_xInfoP->status) {
912 fprintf(STDOUT, "status\t\tOK\n");
915 fprintf(STDOUT, "status\t\tBUSY\n");
918 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
921 fprintf(STDOUT, "backupID\t%lu\n",
922 afs_cast_uint32(a_xInfoP->backupID));
923 fprintf(STDOUT, "parentID\t%lu\n",
924 afs_cast_uint32(a_xInfoP->parentID));
925 fprintf(STDOUT, "cloneID\t\t%lu\n",
926 afs_cast_uint32(a_xInfoP->cloneID));
927 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
928 switch (a_xInfoP->type) {
930 fprintf(STDOUT, "type\t\tRW\n");
933 fprintf(STDOUT, "type\t\tRO\n");
936 fprintf(STDOUT, "type\t\tBK\n");
939 fprintf(STDOUT, "type\t\t?\n");
942 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
943 afs_cast_uint32(a_xInfoP->creationDate),
944 vos_ctime(&a_xInfoP->creationDate));
945 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
946 afs_cast_uint32(a_xInfoP->accessDate),
947 vos_ctime(&a_xInfoP->accessDate));
948 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
949 afs_cast_uint32(a_xInfoP->updateDate),
950 vos_ctime(&a_xInfoP->updateDate));
951 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
952 afs_cast_uint32(a_xInfoP->backupDate),
953 vos_ctime(&a_xInfoP->backupDate));
954 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
955 afs_cast_uint32(a_xInfoP->copyDate),
956 vos_ctime(&a_xInfoP->copyDate));
958 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
959 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
961 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
962 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
966 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
967 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
968 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
969 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
971 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
972 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
973 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
974 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
978 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
979 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
980 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
981 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
984 } /*Volume status OK */
985 else if (a_xInfoP->status == VBUSY) {
987 qPut(&busyHead, a_xInfoP->volid);
989 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
990 (unsigned long)a_xInfoP->volid);
994 qPut(¬okHead, a_xInfoP->volid);
996 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
997 (unsigned long)a_xInfoP->volid);
998 } /*Screwed volume */
1004 if (a_xInfoP->status == VOK) {
1005 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1006 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1007 if (a_xInfoP->type == 0)
1008 fprintf(STDOUT, "type\tRW\n");
1009 if (a_xInfoP->type == 1)
1010 fprintf(STDOUT, "type\tRO\n");
1011 if (a_xInfoP->type == 2)
1012 fprintf(STDOUT, "type\tBK\n");
1013 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1015 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1016 if (a_xInfoP->inUse == 1)
1022 else if (a_xInfoP->status == VBUSY) {
1024 qPut(&busyHead, a_xInfoP->volid);
1026 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1027 (unsigned long)a_xInfoP->volid);
1031 qPut(¬okHead, a_xInfoP->volid);
1033 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1034 (unsigned long)a_xInfoP->volid);
1035 } /*Screwed volume */
1036 } /*Default listing */
1037 } /*XDisplayFormat */
1038 #endif /*FULL_LISTVOL_SWITCH*/
1040 #ifdef FULL_LISTVOL_SWITCH
1042 DisplayFormat2(server, partition, pntr)
1043 long server, partition;
1046 static long server_cache = -1, partition_cache = -1;
1047 static char hostname[256], address[32], pname[16];
1049 if (server != server_cache) {
1053 strcpy(hostname, hostutil_GetNameByINet(server));
1054 strcpy(address, inet_ntoa(s));
1055 server_cache = server;
1057 if (partition != partition_cache) {
1058 MapPartIdIntoName(partition, pname);
1059 partition_cache = partition;
1061 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1062 fprintf(STDOUT, "id\t\t%lu\n",
1063 afs_cast_uint32(pntr->volid));
1064 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1065 fprintf(STDOUT, "part\t\t%s\n", pname);
1066 switch (pntr->status) {
1068 fprintf(STDOUT, "status\t\tOK\n");
1071 fprintf(STDOUT, "status\t\tBUSY\n");
1074 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1077 fprintf(STDOUT, "backupID\t%lu\n",
1078 afs_cast_uint32(pntr->backupID));
1079 fprintf(STDOUT, "parentID\t%lu\n",
1080 afs_cast_uint32(pntr->parentID));
1081 fprintf(STDOUT, "cloneID\t\t%lu\n",
1082 afs_cast_uint32(pntr->cloneID));
1083 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1084 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1085 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1086 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1087 switch (pntr->type) {
1089 fprintf(STDOUT, "type\t\tRW\n");
1092 fprintf(STDOUT, "type\t\tRO\n");
1095 fprintf(STDOUT, "type\t\tBK\n");
1098 fprintf(STDOUT, "type\t\t?\n");
1101 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1102 afs_cast_uint32(pntr->creationDate),
1103 vos_ctime(&pntr->creationDate));
1104 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1105 afs_cast_uint32(pntr->accessDate),
1106 vos_ctime(&pntr->accessDate));
1107 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1108 afs_cast_uint32(pntr->updateDate),
1109 vos_ctime(&pntr->updateDate));
1110 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1111 afs_cast_uint32(pntr->backupDate),
1112 vos_ctime(&pntr->backupDate));
1113 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1114 afs_cast_uint32(pntr->copyDate),
1115 vos_ctime(&pntr->copyDate));
1116 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1117 afs_cast_uint32(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_cast_uint32(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_cast_uint32(pntr->spare1));
1126 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1127 afs_cast_uint32(pntr->spare2));
1128 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1129 afs_cast_uint32(pntr->spare3));
1134 DisplayVolumes2(server, partition, pntr, count)
1136 long server, partition, count;
1140 for (i = 0; i < count; i++) {
1141 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1142 DisplayFormat2(server, partition, pntr);
1143 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1148 #endif /* FULL_LISTVOL_SWITCH */
1151 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
1152 afs_int32 server, part;
1154 afs_int32 count, longlist, fast;
1157 int totalOK, totalNotOK, totalBusy, i;
1158 afs_uint32 volid = 0;
1165 for (i = 0; i < count; i++) {
1166 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1171 while (busyHead.count) {
1172 qGet(&busyHead, &volid);
1173 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1174 (unsigned long)volid);
1178 while (notokHead.count) {
1179 qGet(¬okHead, &volid);
1180 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1181 (unsigned long)volid);
1185 fprintf(STDOUT, "\n");
1188 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1189 totalOK, totalNotOK, totalBusy);
1193 /*------------------------------------------------------------------------
1194 * PRIVATE XDisplayVolumes
1197 * Display extended volume information.
1200 * a_servID : Pointer to the Rx call we're performing.
1201 * a_partID : Partition for which we want the extended list.
1202 * a_xInfoP : Ptr to extended volume info.
1203 * a_count : Number of volume records contained above.
1204 * a_int32 : Int32 listing generated?
1205 * a_fast : Fast listing generated?
1206 * a_quiet : Quiet listing generated?
1212 * Nothing interesting.
1216 *------------------------------------------------------------------------*/
1219 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1223 volintXInfo *a_xInfoP;
1229 { /*XDisplayVolumes */
1231 int totalOK; /*Total OK volumes */
1232 int totalNotOK; /*Total screwed volumes */
1233 int totalBusy; /*Total busy volumes */
1234 int i; /*Loop variable */
1235 afs_uint32 volid = 0; /*Current volume ID */
1238 * Initialize counters and (global!!) queues.
1247 * Display each volume in the list.
1249 for (i = 0; i < a_count; i++) {
1250 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1251 &totalBusy, a_fast, a_int32, 0);
1256 * If any volumes were found to be busy or screwed, display them.
1259 while (busyHead.count) {
1260 qGet(&busyHead, &volid);
1261 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1262 (unsigned long)volid);
1266 while (notokHead.count) {
1267 qGet(¬okHead, &volid);
1268 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1269 (unsigned long)volid);
1274 fprintf(STDOUT, "\n");
1277 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1278 totalOK, totalNotOK, totalBusy);
1282 } /*XDisplayVolumes */
1283 #ifdef FULL_LISTVOL_SWITCH
1284 /*------------------------------------------------------------------------
1285 * PRIVATE XDisplayVolumes2
1288 * Display extended formated volume information.
1291 * a_servID : Pointer to the Rx call we're performing.
1292 * a_partID : Partition for which we want the extended list.
1293 * a_xInfoP : Ptr to extended volume info.
1294 * a_count : Number of volume records contained above.
1295 * a_int32 : Int32 listing generated?
1296 * a_fast : Fast listing generated?
1297 * a_quiet : Quiet listing generated?
1303 * Nothing interesting.
1307 *------------------------------------------------------------------------*/
1310 XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1314 volintXInfo *a_xInfoP;
1320 { /*XDisplayVolumes */
1322 int totalOK; /*Total OK volumes */
1323 int totalNotOK; /*Total screwed volumes */
1324 int totalBusy; /*Total busy volumes */
1325 int i; /*Loop variable */
1326 afs_uint32 volid = 0; /*Current volume ID */
1329 * Initialize counters and (global!!) queues.
1338 * Display each volume in the list.
1340 for (i = 0; i < a_count; i++) {
1341 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1342 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1343 &totalBusy, a_fast, a_int32, 0);
1344 fprintf(STDOUT, "END_OF_ENTRY\n");
1349 * If any volumes were found to be busy or screwed, display them.
1352 while (busyHead.count) {
1353 qGet(&busyHead, &volid);
1354 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1355 (unsigned long)volid);
1359 while (notokHead.count) {
1360 qGet(¬okHead, &volid);
1361 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1362 (unsigned long)volid);
1367 fprintf(STDOUT, "\n");
1370 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1371 totalOK, totalNotOK, totalBusy);
1375 } /*XDisplayVolumes2 */
1376 #endif /* FULL_LISTVOL_SWITCH */
1379 /* set <server> and <part> to the correct values depending on
1380 * <voltype> and <entry> */
1382 GetServerAndPart(entry, voltype, server, part, previdx)
1383 struct nvldbentry *entry;
1384 afs_int32 *server, *part;
1388 int i, istart, vtype;
1393 /* Doesn't check for non-existance of backup volume */
1394 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1396 istart = 0; /* seach the entire entry */
1399 /* Seach from beginning of entry or pick up where we left off */
1400 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1403 for (i = istart; i < entry->nServers; i++) {
1404 if (entry->serverFlags[i] & vtype) {
1405 *server = entry->serverNumber[i];
1406 *part = entry->serverPartition[i];
1412 /* Didn't find any, return -1 */
1418 PostVolumeStats(struct nvldbentry *entry)
1420 SubEnumerateEntry(entry);
1421 /* Check for VLOP_ALLOPERS */
1422 if (entry->flags & VLOP_ALLOPERS)
1423 fprintf(STDOUT, " Volume is currently LOCKED \n");
1427 /*------------------------------------------------------------------------
1428 * PRIVATE XVolumeStats
1431 * Display extended volume information.
1434 * a_xInfoP : Ptr to extended volume info.
1435 * a_entryP : Ptr to the volume's VLDB entry.
1436 * a_srvID : Server ID.
1437 * a_partID : Partition ID.
1438 * a_volType : Type of volume to print.
1444 * Nothing interesting.
1448 *------------------------------------------------------------------------*/
1451 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1452 volintXInfo *a_xInfoP;
1453 struct nvldbentry *a_entryP;
1460 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1462 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1463 a_srvID, /*Server ID to print */
1464 a_partID, /*Partition ID to print */
1465 &totalOK, /*Ptr to total-OK counter */
1466 &totalNotOK, /*Ptr to total-screwed counter */
1467 &totalBusy, /*Ptr to total-busy counter */
1468 0, /*Don't do a fast listing */
1469 1, /*Do a long listing */
1470 1); /*Show volume problems */
1476 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_int32 server,
1477 afs_int32 part, int voltype)
1479 int totalOK, totalNotOK, totalBusy;
1481 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1486 /* command to forcibly remove a volume */
1488 NukeVolume(register struct cmd_syndesc *as)
1490 register afs_int32 code;
1497 server = GetServer(tp = as->parms[0].items->data);
1499 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1503 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1505 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1509 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1512 PrintError("", err);
1515 "vos: could not parse '%s' as a numeric volume ID", tp);
1520 "vos: forcibly removing all traces of volume %d, please wait...",
1523 code = UV_NukeVolume(server, partID, volID);
1525 fprintf(STDOUT, "done.\n");
1527 fprintf(STDOUT, "failed with code %d.\n", code);
1532 /*------------------------------------------------------------------------
1533 * PRIVATE ExamineVolume
1536 * Routine used to examine a single volume, contacting the VLDB as
1537 * well as the Volume Server.
1540 * as : Ptr to parsed command line arguments.
1543 * 0 for a successful operation,
1544 * Otherwise, one of the ubik or VolServer error values.
1547 * Nothing interesting.
1551 *------------------------------------------------------------------------
1554 ExamineVolume(register struct cmd_syndesc *as, void *arock)
1556 struct nvldbentry entry;
1557 afs_int32 vcode = 0;
1558 volintInfo *pntr = (volintInfo *) 0;
1559 volintXInfo *xInfoP = (volintXInfo *) 0;
1561 afs_int32 code, err, error = 0;
1562 int voltype, foundserv = 0, foundentry = 0;
1563 afs_int32 aserver, apart;
1565 int wantExtendedInfo; /*Do we want extended vol info? */
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);
1654 #ifdef FULL_LISTVOL_SWITCH
1655 if (as->parms[2].items) {
1656 DisplayFormat2(aserver, apart, pntr);
1657 EnumerateEntry(&entry);
1659 #endif /* FULL_LISTVOL_SWITCH */
1660 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1662 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1663 /* The VLDB says there is no backup volume yet we found one on disk */
1664 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1665 as->parms[0].items->data);
1674 } while (voltype == ROVOL);
1677 fprintf(STDERR, "Dump only information from VLDB\n\n");
1678 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(register struct cmd_syndesc *as, void *arock)
1708 struct nvldbentry entry;
1709 afs_int32 vcode = 0;
1712 afs_int32 code, err;
1713 afs_int32 aserver, apart;
1716 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1719 PrintError("", err);
1721 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1722 as->parms[0].items->data);
1726 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1729 "Could not fetch the entry for volume number %lu from VLDB \n",
1730 (unsigned long)volid);
1733 MapHostToNetwork(&entry);
1735 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1736 if (previdx == -1) {
1737 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1738 as->parms[0].items->data);
1742 init_volintInfo(&info);
1746 if (as->parms[1].items) {
1748 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1750 fprintf(STDERR, "invalid quota value\n");
1754 if (as->parms[2].items) {
1758 if (as->parms[3].items) {
1759 /* -clearVolUpCounter */
1762 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1765 "Could not update volume info fields for volume number %lu\n",
1766 (unsigned long)volid);
1770 /*------------------------------------------------------------------------
1774 * Brings a volume online.
1777 * as : Ptr to parsed command line arguments.
1780 * 0 for a successful operation,
1783 * Nothing interesting.
1787 *------------------------------------------------------------------------
1790 volOnline(register struct cmd_syndesc *as, void *arock)
1792 afs_int32 server, partition;
1794 afs_int32 code, err = 0;
1796 server = GetServer(as->parms[0].items->data);
1798 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1799 as->parms[0].items->data);
1803 partition = volutil_GetPartitionID(as->parms[1].items->data);
1804 if (partition < 0) {
1805 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1806 as->parms[1].items->data);
1810 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1813 PrintError("", err);
1815 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1816 as->parms[0].items->data);
1820 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1823 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1830 /*------------------------------------------------------------------------
1831 * PRIVATE volOffline
1834 * Brings a volume offline.
1837 * as : Ptr to parsed command line arguments.
1840 * 0 for a successful operation,
1843 * Nothing interesting.
1847 *------------------------------------------------------------------------
1850 volOffline(register struct cmd_syndesc *as, void *arock)
1852 afs_int32 server, partition;
1854 afs_int32 code, err = 0;
1855 afs_int32 transflag, sleeptime, transdone;
1857 server = GetServer(as->parms[0].items->data);
1859 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1860 as->parms[0].items->data);
1864 partition = volutil_GetPartitionID(as->parms[1].items->data);
1865 if (partition < 0) {
1866 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1867 as->parms[1].items->data);
1871 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1874 PrintError("", err);
1876 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1877 as->parms[0].items->data);
1881 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1882 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1883 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1884 if (as->parms[4].items && !as->parms[3].items) {
1885 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1890 UV_SetVolume(server, partition, volid, transflag, transdone,
1893 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1901 CreateVolume(register struct cmd_syndesc *as, void *arock)
1907 struct nvldbentry entry;
1912 tserver = GetServer(as->parms[0].items->data);
1914 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1915 as->parms[0].items->data);
1918 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1920 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1921 as->parms[1].items->data);
1924 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1926 PrintError("", code);
1929 "vos : partition %s does not exist on the server\n",
1930 as->parms[1].items->data);
1933 if (!ISNAMEVALID(as->parms[2].items->data)) {
1935 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1936 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1939 if (!VolNameOK(as->parms[2].items->data)) {
1941 "Illegal volume name %s, should not end in .readonly or .backup\n",
1942 as->parms[2].items->data);
1945 if (IsNumeric(as->parms[2].items->data)) {
1946 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1947 as->parms[2].items->data);
1950 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1952 fprintf(STDERR, "Volume %s already exists\n",
1953 as->parms[2].items->data);
1954 PrintDiagnostics("create", code);
1958 if (as->parms[3].items) {
1959 if (!IsNumeric(as->parms[3].items->data)) {
1960 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1961 as->parms[3].items->data);
1965 code = util_GetInt32(as->parms[3].items->data, "a);
1967 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1973 UV_CreateVolume2(tserver, pnum, as->parms[2].items->data, quota, 0,
1976 PrintDiagnostics("create", code);
1979 MapPartIdIntoName(pnum, part);
1980 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1981 (unsigned long)volid, part, as->parms[0].items->data);
1988 struct nvldbentry *entry;
1991 afs_int32 error, code, curserver, curpart;
1994 MapHostToNetwork(entry);
1996 for (i = 0; i < entry->nServers; i++) {
1997 curserver = entry->serverNumber[i];
1998 curpart = entry->serverPartition[i];
1999 if (entry->serverFlags[i] & ITSROVOL) {
2000 volid = entry->volumeId[ROVOL];
2002 volid = entry->volumeId[RWVOL];
2004 code = UV_DeleteVolume(curserver, curpart, volid);
2012 DeleteVolume(struct cmd_syndesc *as, void *arock)
2014 afs_int32 err, code = 0;
2015 afs_int32 server = 0, partition = -1;
2020 if (as->parms[0].items) {
2021 server = GetServer(as->parms[0].items->data);
2023 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2024 as->parms[0].items->data);
2029 if (as->parms[1].items) {
2030 partition = volutil_GetPartitionID(as->parms[1].items->data);
2031 if (partition < 0) {
2032 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2033 as->parms[1].items->data);
2037 /* Check for validity of the partition */
2038 if (!IsPartValid(partition, server, &code)) {
2040 PrintError("", code);
2043 "vos : partition %s does not exist on the server\n",
2044 as->parms[1].items->data);
2050 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2052 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2053 as->parms[2].items->data);
2055 PrintError("", err);
2059 /* If the server or partition option are not complete, try to fill
2060 * them in from the VLDB entry.
2062 if ((partition == -1) || !server) {
2063 struct nvldbentry entry;
2065 code = VLDB_GetEntryByID(volid, -1, &entry);
2068 "Could not fetch the entry for volume %lu from VLDB\n",
2069 (unsigned long)volid);
2070 PrintError("", code);
2074 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2075 || ((volid == entry.volumeId[BACKVOL])
2076 && (entry.flags & BACK_EXISTS))) {
2077 idx = Lp_GetRwIndex(&entry);
2078 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2079 || ((partition != -1)
2080 && (partition != entry.serverPartition[idx]))) {
2081 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2082 as->parms[2].items->data);
2085 } else if ((volid == entry.volumeId[ROVOL])
2086 && (entry.flags & RO_EXISTS)) {
2087 for (idx = -1, j = 0; j < entry.nServers; j++) {
2088 if (entry.serverFlags[j] != ITSROVOL)
2091 if (((server == 0) || (server == entry.serverNumber[j]))
2092 && ((partition == -1)
2093 || (partition == entry.serverPartition[j]))) {
2096 "VLDB: Volume '%s' matches more than one RO\n",
2097 as->parms[2].items->data);
2104 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2105 as->parms[2].items->data);
2109 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2110 as->parms[2].items->data);
2114 server = htonl(entry.serverNumber[idx]);
2115 partition = entry.serverPartition[idx];
2119 code = UV_DeleteVolume(server, partition, volid);
2121 PrintDiagnostics("remove", code);
2125 MapPartIdIntoName(partition, pname);
2126 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2127 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2131 #define TESTM 0 /* set for move space tests, clear for production */
2133 MoveVolume(register struct cmd_syndesc *as, void *arock)
2137 afs_int32 fromserver, toserver, frompart, topart;
2138 afs_int32 flags, code, err;
2139 char fromPartName[10], toPartName[10];
2141 struct diskPartition64 partition; /* for space check */
2144 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2147 PrintError("", err);
2149 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2150 as->parms[0].items->data);
2153 fromserver = GetServer(as->parms[1].items->data);
2154 if (fromserver == 0) {
2155 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2156 as->parms[1].items->data);
2159 toserver = GetServer(as->parms[3].items->data);
2160 if (toserver == 0) {
2161 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2162 as->parms[3].items->data);
2165 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2167 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2168 as->parms[2].items->data);
2171 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2173 PrintError("", code);
2176 "vos : partition %s does not exist on the server\n",
2177 as->parms[2].items->data);
2180 topart = volutil_GetPartitionID(as->parms[4].items->data);
2182 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2183 as->parms[4].items->data);
2186 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2188 PrintError("", code);
2191 "vos : partition %s does not exist on the server\n",
2192 as->parms[4].items->data);
2197 if (as->parms[5].items) flags |= RV_NOCLONE;
2200 * check source partition for space to clone volume
2203 MapPartIdIntoName(topart, toPartName);
2204 MapPartIdIntoName(frompart, fromPartName);
2207 * check target partition for space to move volume
2210 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2212 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2216 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2219 p = (volintInfo *) 0;
2220 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2222 fprintf(STDERR, "vos:cannot access volume %lu\n",
2223 (unsigned long)volid);
2227 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2229 if (partition.free <= p->size) {
2231 "vos: no space on target partition %s to move volume %lu\n",
2232 toPartName, (unsigned long)volid);
2239 fprintf(STDOUT, "size test - don't do move\n");
2243 /* successful move still not guaranteed but shoot for it */
2246 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2248 PrintDiagnostics("move", code);
2251 MapPartIdIntoName(topart, toPartName);
2252 MapPartIdIntoName(frompart, fromPartName);
2253 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2254 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2255 as->parms[3].items->data, toPartName);
2261 CopyVolume(register struct cmd_syndesc *as, void *arock)
2264 afs_int32 fromserver, toserver, frompart, topart, code, err, flags;
2265 char fromPartName[10], toPartName[10], *tovolume;
2266 struct nvldbentry entry;
2267 struct diskPartition64 partition; /* for space check */
2270 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2273 PrintError("", err);
2275 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2276 as->parms[0].items->data);
2279 fromserver = GetServer(as->parms[1].items->data);
2280 if (fromserver == 0) {
2281 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2282 as->parms[1].items->data);
2286 toserver = GetServer(as->parms[4].items->data);
2287 if (toserver == 0) {
2288 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2289 as->parms[4].items->data);
2293 tovolume = as->parms[3].items->data;
2294 if (!ISNAMEVALID(tovolume)) {
2296 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2297 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2300 if (!VolNameOK(tovolume)) {
2302 "Illegal volume name %s, should not end in .readonly or .backup\n",
2306 if (IsNumeric(tovolume)) {
2307 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2311 code = VLDB_GetEntryByName(tovolume, &entry);
2313 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2314 PrintDiagnostics("copy", code);
2318 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2320 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2321 as->parms[2].items->data);
2324 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2326 PrintError("", code);
2329 "vos : partition %s does not exist on the server\n",
2330 as->parms[2].items->data);
2334 topart = volutil_GetPartitionID(as->parms[5].items->data);
2336 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2337 as->parms[5].items->data);
2340 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2342 PrintError("", code);
2345 "vos : partition %s does not exist on the server\n",
2346 as->parms[5].items->data);
2351 if (as->parms[6].items) flags |= RV_OFFLINE;
2352 if (as->parms[7].items) flags |= RV_RDONLY;
2353 if (as->parms[8].items) flags |= RV_NOCLONE;
2355 MapPartIdIntoName(topart, toPartName);
2356 MapPartIdIntoName(frompart, fromPartName);
2359 * check target partition for space to move volume
2362 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2364 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2368 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2371 p = (volintInfo *) 0;
2372 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2374 fprintf(STDERR, "vos:cannot access volume %lu\n",
2375 (unsigned long)volid);
2379 if (partition.free <= p->size) {
2381 "vos: no space on target partition %s to copy volume %lu\n",
2382 toPartName, (unsigned long)volid);
2388 /* successful copy still not guaranteed but shoot for it */
2391 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2394 PrintDiagnostics("copy", code);
2397 MapPartIdIntoName(topart, toPartName);
2398 MapPartIdIntoName(frompart, fromPartName);
2399 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2400 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2401 tovolume, as->parms[4].items->data, toPartName);
2408 ShadowVolume(register struct cmd_syndesc *as, void *arock)
2410 afs_uint32 volid, tovolid;
2411 afs_int32 fromserver, toserver, frompart, topart;
2412 afs_int32 code, err, flags;
2413 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2414 struct diskPartition64 partition; /* for space check */
2417 p = (volintInfo *) 0;
2418 q = (volintInfo *) 0;
2420 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2423 PrintError("", err);
2425 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2426 as->parms[0].items->data);
2429 fromserver = GetServer(as->parms[1].items->data);
2430 if (fromserver == 0) {
2431 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2432 as->parms[1].items->data);
2436 toserver = GetServer(as->parms[3].items->data);
2437 if (toserver == 0) {
2438 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2439 as->parms[3].items->data);
2443 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2445 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2446 as->parms[2].items->data);
2449 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2451 PrintError("", code);
2454 "vos : partition %s does not exist on the server\n",
2455 as->parms[2].items->data);
2459 topart = volutil_GetPartitionID(as->parms[4].items->data);
2461 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2462 as->parms[4].items->data);
2465 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2467 PrintError("", code);
2470 "vos : partition %s does not exist on the server\n",
2471 as->parms[4].items->data);
2475 if (as->parms[5].items) {
2476 tovolume = as->parms[5].items->data;
2477 if (!ISNAMEVALID(tovolume)) {
2479 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2480 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2483 if (!VolNameOK(tovolume)) {
2485 "Illegal volume name %s, should not end in .readonly or .backup\n",
2489 if (IsNumeric(tovolume)) {
2491 "Illegal volume name %s, should not be a number\n",
2496 /* use actual name of source volume */
2497 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2499 fprintf(STDERR, "vos:cannot access volume %lu\n",
2500 (unsigned long)volid);
2503 strcpy(toVolName, p->name);
2504 tovolume = toVolName;
2505 /* save p for size checks later */
2508 if (as->parms[6].items) {
2509 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2512 PrintError("", err);
2514 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2515 as->parms[6].items->data);
2521 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2524 PrintError("", err);
2526 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2535 if (as->parms[7].items) flags |= RV_OFFLINE;
2536 if (as->parms[8].items) flags |= RV_RDONLY;
2537 if (as->parms[9].items) flags |= RV_NOCLONE;
2538 if (as->parms[10].items) flags |= RV_CPINCR;
2540 MapPartIdIntoName(topart, toPartName);
2541 MapPartIdIntoName(frompart, fromPartName);
2544 * check target partition for space to move volume
2547 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2549 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2553 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2556 /* Don't do this again if we did it above */
2558 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2560 fprintf(STDERR, "vos:cannot access volume %lu\n",
2561 (unsigned long)volid);
2566 /* OK if this fails */
2567 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2569 /* Treat existing volume size as "free" */
2571 p->size = (q->size < p->size) ? p->size - q->size : 0;
2573 if (partition.free <= p->size) {
2575 "vos: no space on target partition %s to copy volume %lu\n",
2576 toPartName, (unsigned long)volid);
2584 /* successful copy still not guaranteed but shoot for it */
2587 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2588 topart, tovolid, flags);
2590 PrintDiagnostics("shadow", code);
2593 MapPartIdIntoName(topart, toPartName);
2594 MapPartIdIntoName(frompart, fromPartName);
2595 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2596 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2597 as->parms[3].items->data, toPartName);
2604 CloneVolume(register struct cmd_syndesc *as, void *arock)
2606 afs_uint32 volid, cloneid;
2607 afs_int32 server, part, voltype;
2608 char partName[10], *volname;
2609 afs_int32 code, err, flags;
2610 struct nvldbentry entry;
2612 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2615 PrintError("", err);
2617 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2618 as->parms[0].items->data);
2622 if (as->parms[1].items || as->parms[2].items) {
2623 if (!as->parms[1].items || !as->parms[2].items) {
2625 "Must specify both -server and -partition options\n");
2628 server = GetServer(as->parms[1].items->data);
2630 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2631 as->parms[1].items->data);
2634 part = volutil_GetPartitionID(as->parms[2].items->data);
2636 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2637 as->parms[2].items->data);
2640 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2642 PrintError("", code);
2645 "vos : partition %s does not exist on the server\n",
2646 as->parms[2].items->data);
2650 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2656 if (as->parms[3].items) {
2657 volname = as->parms[3].items->data;
2658 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2660 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2661 volname, VOLSER_OLDMAXVOLNAME - 1);
2666 * In order that you be able to make clones of RO or BK, this
2667 * check must be omitted.
2669 if (!VolNameOK(volname)) {
2671 "Illegal volume name %s, should not end in .readonly or .backup\n",
2676 if (IsNumeric(volname)) {
2678 "Illegal volume name %s, should not be a number\n",
2685 if (as->parms[4].items) {
2686 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2689 PrintError("", err);
2691 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2692 as->parms[4].items->data);
2698 if (as->parms[5].items) flags |= RV_OFFLINE;
2699 if (as->parms[6].items) flags |= RV_RDONLY;
2703 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2706 PrintDiagnostics("clone", code);
2709 MapPartIdIntoName(part, partName);
2710 fprintf(STDOUT, "Created clone for volume %s\n",
2711 as->parms[0].items->data);
2718 BackupVolume(register struct cmd_syndesc *as, void *arock)
2721 afs_int32 aserver, apart, vtype, code, err;
2722 struct nvldbentry entry;
2725 afs_int32 buserver, bupart, butype;
2726 struct nvldbentry buentry;
2728 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2731 PrintError("", err);
2733 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2734 as->parms[0].items->data);
2737 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2741 /* verify this is a readwrite volume */
2743 if (vtype != RWVOL) {
2744 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2748 /* is there a backup volume already? */
2750 if (entry.flags & BACK_EXISTS) {
2751 /* yep, where is it? */
2753 buvolid = entry.volumeId[BACKVOL];
2754 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2759 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2762 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2768 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2769 (unsigned long)buvolid, (unsigned long)buserver);
2774 /* nope, carry on */
2776 code = UV_BackupVolume(aserver, apart, avolid);
2779 PrintDiagnostics("backup", code);
2782 fprintf(STDOUT, "Created backup volume for %s \n",
2783 as->parms[0].items->data);
2788 ReleaseVolume(register struct cmd_syndesc *as, void *arock)
2791 struct nvldbentry entry;
2793 afs_int32 aserver, apart, vtype, code, err;
2796 if (as->parms[1].items)
2798 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2801 PrintError("", err);
2803 fprintf(STDERR, "vos: can't find volume '%s'\n",
2804 as->parms[0].items->data);
2807 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2811 if (vtype != RWVOL) {
2812 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2816 if (!ISNAMEVALID(entry.name)) {
2818 "Volume name %s is too long, rename before releasing\n",
2823 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2825 PrintDiagnostics("release", code);
2828 fprintf(STDOUT, "Released volume %s successfully\n",
2829 as->parms[0].items->data);
2834 DumpVolume(register struct cmd_syndesc *as, void *arock)
2837 afs_int32 aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2838 char filename[MAXPATHLEN];
2839 struct nvldbentry entry;
2841 rx_SetRxDeadTime(60 * 10);
2842 for (i = 0; i < MAXSERVERS; i++) {
2843 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2846 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2847 if (rxConn->service)
2848 rxConn->service->connDeadTime = rx_connDeadTime;
2851 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2854 PrintError("", err);
2856 fprintf(STDERR, "vos: can't find volume '%s'\n",
2857 as->parms[0].items->data);
2861 if (as->parms[3].items || as->parms[4].items) {
2862 if (!as->parms[3].items || !as->parms[4].items) {
2864 "Must specify both -server and -partition options\n");
2867 aserver = GetServer(as->parms[3].items->data);
2869 fprintf(STDERR, "Invalid server name\n");
2872 apart = volutil_GetPartitionID(as->parms[4].items->data);
2874 fprintf(STDERR, "Invalid partition name\n");
2878 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2883 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2884 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2886 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2887 as->parms[1].items->data, code);
2891 if (as->parms[2].items) {
2892 strcpy(filename, as->parms[2].items->data);
2894 strcpy(filename, "");
2897 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2899 if (as->parms[5].items) {
2901 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2902 DumpFunction, filename, flags);
2905 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2908 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2909 flags &= ~VOLDUMPV2_OMITDIRS;
2913 PrintDiagnostics("dump", code);
2916 if (strcmp(filename, ""))
2917 fprintf(STDERR, "Dumped volume %s in file %s\n",
2918 as->parms[0].items->data, filename);
2920 fprintf(STDERR, "Dumped volume %s in stdout \n",
2921 as->parms[0].items->data);
2935 RestoreVolume(register struct cmd_syndesc *as, void *arock)
2937 afs_uint32 avolid, aparentid;
2938 afs_int32 aserver, apart, code, vcode, err;
2939 afs_int32 aoverwrite = ASK;
2940 afs_int32 acreation = 0, alastupdate = 0;
2941 int restoreflags = 0;
2942 int readonly = 0, offline = 0, voltype = RWVOL;
2944 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2945 char volname[VOLSER_MAXVOLNAME + 1];
2946 struct nvldbentry entry;
2951 if (as->parms[4].items) {
2952 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2955 PrintError("", err);
2957 fprintf(STDERR, "vos: can't find volume '%s'\n",
2958 as->parms[4].items->data);
2964 if (as->parms[5].items) {
2965 if ((strcmp(as->parms[5].items->data, "a") == 0)
2966 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2968 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2969 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2971 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2972 || (strcmp(as->parms[5].items->data, "inc") == 0)
2973 || (strcmp(as->parms[5].items->data, "increment") == 0)
2974 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2977 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2978 as->parms[5].items->data);
2982 if (as->parms[6].items)
2984 if (as->parms[7].items) {
2989 if (as->parms[8].items) {
2990 if ((strcmp(as->parms[8].items->data, "d") == 0)
2991 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
2992 acreation = TS_DUMP;
2993 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
2994 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
2995 acreation = TS_KEEP;
2996 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
2997 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3000 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3001 as->parms[8].items->data);
3006 if (as->parms[9].items) {
3007 if ((strcmp(as->parms[9].items->data, "d") == 0)
3008 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3009 alastupdate = TS_DUMP;
3010 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3011 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3012 alastupdate = TS_KEEP;
3013 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3014 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3015 alastupdate = TS_NEW;
3017 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3018 as->parms[9].items->data);
3023 aserver = GetServer(as->parms[0].items->data);
3025 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3026 as->parms[0].items->data);
3029 apart = volutil_GetPartitionID(as->parms[1].items->data);
3031 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3032 as->parms[1].items->data);
3035 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3037 PrintError("", code);
3040 "vos : partition %s does not exist on the server\n",
3041 as->parms[1].items->data);
3044 strcpy(avolname, as->parms[2].items->data);
3045 if (!ISNAMEVALID(avolname)) {
3047 "vos: the name of the volume %s exceeds the size limit\n",
3051 if (!VolNameOK(avolname)) {
3053 "Illegal volume name %s, should not end in .readonly or .backup\n",
3057 if (as->parms[3].items) {
3058 strcpy(afilename, as->parms[3].items->data);
3059 if (!FileExists(afilename)) {
3060 fprintf(STDERR, "Can't access file %s\n", afilename);
3064 strcpy(afilename, "");
3067 /* Check if volume exists or not */
3069 vsu_ExtractName(volname, avolname);
3070 vcode = VLDB_GetEntryByName(volname, &entry);
3071 if (vcode) { /* no volume - do a full restore */
3072 restoreflags = RV_FULLRST;
3073 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3075 "Volume does not exist; Will perform a full restore\n");
3078 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3079 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3080 restoreflags = RV_FULLRST;
3081 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3083 "%s Volume does not exist; Will perform a full restore\n",
3084 readonly ? "RO" : "RW");
3087 avolid = entry.volumeId[voltype];
3088 } else if (entry.volumeId[voltype] != 0
3089 && entry.volumeId[voltype] != avolid) {
3090 avolid = entry.volumeId[voltype];
3092 aparentid = entry.volumeId[RWVOL];
3095 else { /* volume exists - do we do a full incremental or abort */
3096 int Oserver, Opart, Otype, vol_elsewhere = 0;
3097 struct nvldbentry Oentry;
3101 avolid = entry.volumeId[voltype];
3102 } else if (entry.volumeId[voltype] != 0
3103 && entry.volumeId[voltype] != avolid) {
3104 avolid = entry.volumeId[voltype];
3106 aparentid = entry.volumeId[RWVOL];
3108 /* A file name was specified - check if volume is on another partition */
3109 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3113 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3116 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3120 if (!vcode || (Opart != apart))
3123 if (aoverwrite == ASK) {
3124 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3126 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3130 /* Ask what to do */
3131 if (vol_elsewhere) {
3133 "The volume %s %u already exists on a different server/part\n",
3134 volname, entry.volumeId[voltype]);
3136 "Do you want to do a full restore or abort? [fa](a): ");
3139 "The volume %s %u already exists in the VLDB\n",
3140 volname, entry.volumeId[voltype]);
3142 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3145 while (!(dc == EOF || dc == '\n'))
3146 dc = getchar(); /* goto end of line */
3147 if ((c == 'f') || (c == 'F'))
3149 else if ((c == 'i') || (c == 'I'))
3155 if (aoverwrite == ABORT) {
3156 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3158 } else if (aoverwrite == FULL) {
3159 restoreflags = RV_FULLRST;
3161 "Volume exists; Will delete and perform full restore\n");
3162 } else if (aoverwrite == INC) {
3164 if (vol_elsewhere) {
3166 "%s volume %lu already exists on a different server/part; not allowed\n",
3167 readonly ? "RO" : "RW", (unsigned long)avolid);
3173 restoreflags |= RV_OFFLINE;
3175 restoreflags |= RV_RDONLY;
3177 switch (acreation) {
3179 restoreflags |= RV_CRDUMP;
3182 restoreflags |= RV_CRKEEP;
3185 restoreflags |= RV_CRNEW;
3188 if (aoverwrite == FULL)
3189 restoreflags |= RV_CRNEW;
3191 restoreflags |= RV_CRKEEP;
3194 switch (alastupdate) {
3196 restoreflags |= RV_LUDUMP;
3199 restoreflags |= RV_LUKEEP;
3202 restoreflags |= RV_LUNEW;
3205 restoreflags |= RV_LUDUMP;
3207 if (as->parms[10].items) {
3208 restoreflags |= RV_NODEL;
3213 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3214 avolname, restoreflags, WriteData, afilename);
3216 PrintDiagnostics("restore", code);
3219 MapPartIdIntoName(apart, apartName);
3222 * patch typo here - originally "parms[1]", should be "parms[0]"
3225 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3226 as->parms[0].items->data, apartName);
3231 LockReleaseCmd(register struct cmd_syndesc *as, void *arock)
3234 afs_int32 code, err;
3236 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3239 PrintError("", err);
3241 fprintf(STDERR, "vos: can't find volume '%s'\n",
3242 as->parms[0].items->data);
3246 code = UV_LockRelease(avolid);
3248 PrintDiagnostics("unlock", code);
3251 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3252 as->parms[0].items->data);
3257 AddSite(register struct cmd_syndesc *as, void *arock)
3260 afs_int32 aserver, apart, code, err, valid = 0;
3261 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3263 vsu_ExtractName(avolname, as->parms[2].items->data);;
3264 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3267 PrintError("", err);
3269 fprintf(STDERR, "vos: can't find volume '%s'\n",
3270 as->parms[2].items->data);
3273 aserver = GetServer(as->parms[0].items->data);
3275 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3276 as->parms[0].items->data);
3279 apart = volutil_GetPartitionID(as->parms[1].items->data);
3281 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3282 as->parms[1].items->data);
3285 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3287 PrintError("", code);
3290 "vos : partition %s does not exist on the server\n",
3291 as->parms[1].items->data);
3294 if (as->parms[3].items) {
3297 code = UV_AddSite(aserver, apart, avolid, valid);
3299 PrintDiagnostics("addsite", code);
3302 MapPartIdIntoName(apart, apartName);
3303 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3304 as->parms[0].items->data, apartName, as->parms[2].items->data);
3309 RemoveSite(register struct cmd_syndesc *as, void *arock)
3313 afs_int32 aserver, apart, code, err;
3314 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3316 vsu_ExtractName(avolname, as->parms[2].items->data);
3317 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3320 PrintError("", err);
3322 fprintf(STDERR, "vos: can't find volume '%s'\n",
3323 as->parms[2].items->data);
3326 aserver = GetServer(as->parms[0].items->data);
3328 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3329 as->parms[0].items->data);
3332 apart = volutil_GetPartitionID(as->parms[1].items->data);
3334 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3335 as->parms[1].items->data);
3339 *skip the partition validity check, since it is possible that the partition
3340 *has since been decomissioned.
3343 if (!IsPartValid(apart,aserver,&code)){
3344 if(code) PrintError("",code);
3345 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3349 code = UV_RemoveSite(aserver, apart, avolid);
3351 PrintDiagnostics("remsite", code);
3354 MapPartIdIntoName(apart, apartName);
3355 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3356 as->parms[0].items->data, apartName, as->parms[2].items->data);
3361 ChangeLocation(register struct cmd_syndesc *as, void *arock)
3364 afs_int32 aserver, apart, code, err;
3367 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3370 PrintError("", err);
3372 fprintf(STDERR, "vos: can't find volume '%s'\n",
3373 as->parms[2].items->data);
3376 aserver = GetServer(as->parms[0].items->data);
3378 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3379 as->parms[0].items->data);
3382 apart = volutil_GetPartitionID(as->parms[1].items->data);
3384 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3385 as->parms[1].items->data);
3388 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3390 PrintError("", code);
3393 "vos : partition %s does not exist on the server\n",
3394 as->parms[1].items->data);
3397 code = UV_ChangeLocation(aserver, apart, avolid);
3399 PrintDiagnostics("addsite", code);
3402 MapPartIdIntoName(apart, apartName);
3403 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3404 as->parms[0].items->data, apartName, as->parms[2].items->data);
3409 ListPartitions(register struct cmd_syndesc *as, void *arock)
3411 afs_int32 aserver, code;
3412 struct partList dummyPartList;
3417 aserver = GetServer(as->parms[0].items->data);
3419 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3420 as->parms[0].items->data);
3425 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3427 PrintDiagnostics("listpart", code);
3431 fprintf(STDOUT, "The partitions on the server are:\n");
3432 for (i = 0; i < cnt; i++) {
3433 if (dummyPartList.partFlags[i] & PARTVALID) {
3434 memset(pname, 0, sizeof(pname));
3435 MapPartIdIntoName(dummyPartList.partId[i], pname);
3436 fprintf(STDOUT, " %10s ", pname);
3438 if ((i % 5) == 0 && (i != 0))
3439 fprintf(STDOUT, "\n");
3442 fprintf(STDOUT, "\n");
3443 fprintf(STDOUT, "Total: %d\n", total);
3449 CompareVolName(p1, p2)
3452 volintInfo *arg1, *arg2;
3454 arg1 = (volintInfo *) p1;
3455 arg2 = (volintInfo *) p2;
3456 return (strcmp(arg1->name, arg2->name));
3460 /*------------------------------------------------------------------------
3461 * PRIVATE XCompareVolName
3464 * Comparison routine for volume names coming from an extended
3468 * a_obj1P : Char ptr to first extended vol info object
3469 * a_obj1P : Char ptr to second extended vol info object
3472 * The value of strcmp() on the volume names within the passed
3473 * objects (i,e., -1, 0, or 1).
3476 * Passed to qsort() as the designated comparison routine.
3480 *------------------------------------------------------------------------*/
3483 XCompareVolName(a_obj1P, a_obj2P)
3484 char *a_obj1P, *a_obj2P;
3486 { /*XCompareVolName */
3489 (((struct volintXInfo *)(a_obj1P))->name,
3490 ((struct volintXInfo *)(a_obj2P))->name));
3492 } /*XCompareVolName */
3495 CompareVolID(p1, p2)
3498 volintInfo *arg1, *arg2;
3500 arg1 = (volintInfo *) p1;
3501 arg2 = (volintInfo *) p2;
3502 if (arg1->volid == arg2->volid)
3504 if (arg1->volid > arg2->volid)
3511 /*------------------------------------------------------------------------
3512 * PRIVATE XCompareVolID
3515 * Comparison routine for volume IDs coming from an extended
3519 * a_obj1P : Char ptr to first extended vol info object
3520 * a_obj1P : Char ptr to second extended vol info object
3523 * The value of strcmp() on the volume names within the passed
3524 * objects (i,e., -1, 0, or 1).
3527 * Passed to qsort() as the designated comparison routine.
3531 *------------------------------------------------------------------------*/
3534 XCompareVolID(a_obj1P, a_obj2P)
3535 char *a_obj1P, *a_obj2P;
3537 { /*XCompareVolID */
3539 afs_int32 id1, id2; /*Volume IDs we're comparing */
3541 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3542 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3550 } /*XCompareVolID */
3552 /*------------------------------------------------------------------------
3553 * PRIVATE ListVolumes
3556 * Routine used to list volumes, contacting the Volume Server
3557 * directly, bypassing the VLDB.
3560 * as : Ptr to parsed command line arguments.
3563 * 0 Successful operation
3566 * Nothing interesting.
3570 *------------------------------------------------------------------------*/
3573 ListVolumes(register struct cmd_syndesc *as, void *arock)
3575 afs_int32 apart, int32list, fast;
3576 afs_int32 aserver, code;
3578 volintInfo *oldpntr = NULL;
3582 volintXInfo *xInfoP;
3583 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3584 int wantExtendedInfo; /*Do we want extended vol info? */
3587 struct partList dummyPartList;
3595 if (as->parms[3].items)
3597 if (as->parms[4].items)
3601 if (as->parms[2].items)
3607 if (as->parms[5].items) {
3609 * We can't coexist with the fast flag.
3613 "vos: Can't use the -fast and -extended flags together\n");
3618 * We need to turn on ``long'' listings to get the full effect.
3620 wantExtendedInfo = 1;
3623 wantExtendedInfo = 0;
3624 if (as->parms[1].items) {
3625 apart = volutil_GetPartitionID(as->parms[1].items->data);
3627 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3628 as->parms[1].items->data);
3631 dummyPartList.partId[0] = apart;
3632 dummyPartList.partFlags[0] = PARTVALID;
3635 aserver = GetServer(as->parms[0].items->data);
3637 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3638 as->parms[0].items->data);
3643 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3645 PrintError("", code);
3648 "vos : partition %s does not exist on the server\n",
3649 as->parms[1].items->data);
3653 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3655 PrintDiagnostics("listvol", code);
3659 for (i = 0; i < cnt; i++) {
3660 if (dummyPartList.partFlags[i] & PARTVALID) {
3661 if (wantExtendedInfo)
3663 UV_XListVolumes(aserver, dummyPartList.partId[i], all,