1 /*====================================================================
2 * Copyright (C) 1990, 1998 Transarc Corporation - All rights reserved
3 *====================================================================*/
5 * (C) COPYRIGHT IBM CORPORATION 1988
6 * LICENSED MATERIALS - PROPERTY OF IBM
10 #include <sys/types.h>
19 #include <netinet/in.h>
23 #include <sys/statfs.h>
30 #include <rx/rx_globals.h>
32 #include <afs/vlserver.h>
34 #include <afs/cellconfig.h>
36 #include <afs/afsutil.h>
38 #include <afs/afsint.h>
60 #define COMMONPARMS cmd_Seek(ts, 12);\
61 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
62 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
63 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
64 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
66 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
70 struct rx_connection *tconn;
72 extern struct ubik_client *cstruct;
74 extern struct rx_connection *UV_Bind();
75 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
76 extern int UV_SetSecurity();
78 extern VL_ReleaseLock();
79 extern VL_DeleteEntry();
80 extern VL_ListEntry();
82 extern VL_GetAddrsU();
83 extern VL_ChangeAddr();
85 extern int vsu_ExtractName();
87 extern int MapPartIdIntoName();
88 extern int MapHostToNetwork();
89 extern int MapNetworkToHost();
90 extern void EnumerateEntry();
91 extern void SubEnumerateEntry();
94 static struct tqHead busyHead, notokHead;
96 static void qInit(ahead)
99 bzero((char *)ahead, sizeof(struct tqHead));
104 static void qPut(ahead,volid)
105 struct tqHead *ahead;
110 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
111 elem->next = ahead->next;
118 static void qGet(ahead,volid)
119 struct tqHead *ahead;
124 if(ahead->count <= 0) return;
125 *volid = ahead->next->volid;
127 ahead->next = tmp->next;
133 /* returns 1 if <filename> exists else 0 */
134 static FileExists(filename)
141 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
145 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
153 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
154 static VolNameOK(name)
160 total = strlen(name);
161 if(!strcmp(&name[total - 9],".readonly")) {
164 else if(!strcmp(&name[total - 7 ],".backup")) {
172 /* return 1 if name is a number else 0 */
173 static IsNumeric(name)
182 for(i = 0; i < len ; i++){
183 if(*ptr < '0' || *ptr > '9'){
197 * Parse a server name/address and return the address in HOST BYTE order
199 afs_int32 GetServer(aname)
201 register struct hostent *th;
204 register afs_int32 code;
205 char hostname[MAXHOSTCHARS];
207 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
209 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
210 addr = ntohl(addr); /* convert to host order */
212 th = gethostbyname(aname);
214 bcopy(th->h_addr, &addr, sizeof(addr));
217 if (addr == htonl(0x7f000001)) { /* local host */
218 code = gethostname(hostname, MAXHOSTCHARS);
220 th = gethostbyname(hostname); /* returns host byte order */
222 bcopy(th->h_addr, &addr, sizeof(addr));
228 afs_int32 GetVolumeType(aname)
232 if(!strcmp(aname,"ro"))
234 else if(!strcmp(aname, "rw"))
236 else if(!strcmp(aname,"bk"))
241 int IsPartValid(partId, server, code)
242 afs_int32 server, partId,*code;
245 struct partList dummyPartList;
253 *code = UV_ListPartitions(server,&dummyPartList, &cnt);
254 if(*code) return success;
255 for(i = 0 ; i < cnt ; i++) {
256 if(dummyPartList.partFlags[i] & PARTVALID)
257 if(dummyPartList.partId[i] == partId)
265 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
266 * associated with <call> */
267 SendFile(ufd, call, blksize)
269 register struct rx_call *call;
272 char *buffer = (char*) 0;
277 buffer = (char *)malloc(blksize);
279 fprintf(STDERR,"malloc failed\n");
283 while (!error && !done) {
284 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
287 FD_SET((int)(ufd->handle), &in);
288 /* don't timeout if read blocks */
289 IOMGR_Select(((int)(ufd->handle))+1, &in, 0, 0, 0);
291 error = USD_READ(ufd, buffer, blksize, &nbytes);
293 fprintf(STDERR, "File system read failed\n");
300 if (rx_Write(call, buffer, nbytes) != nbytes){
305 if (buffer) free(buffer);
309 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
310 * writes it out to the volume. */
311 afs_int32 WriteData(call,rock)
312 struct rx_call *call;
318 afs_int32 error,code;
324 if(!filename || !*filename) {
325 usd_StandardInput(&ufd);
329 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
332 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
335 fprintf(STDERR,"Could not access file '%s'\n", filename);
340 code = SendFile(ufd,call,blksize);
347 code = USD_CLOSE(ufd);
349 fprintf(STDERR,"Could not close dump file %s\n",
350 (filename && *filename)?filename:"STDOUT");
351 if(!error) error = code;
357 /* Receive data from <call> stream into file associated
358 * with <fd> <blksize>
360 int ReceiveFile(ufd, call, blksize)
362 struct rx_call *call;
365 char *buffer = (char *) 0;
367 afs_uint32 bytesleft, w;
370 buffer = (char *)malloc(blksize);
372 fprintf(STDERR,"memory allocation failed\n");
376 while ((bytesread=rx_Read(call,buffer,blksize)) > 0) {
377 for (bytesleft=bytesread; bytesleft; bytesleft-=w) {
378 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
381 FD_SET((int)(ufd->handle), &out);
382 /* don't timeout if write blocks */
383 IOMGR_Select(((int)(ufd->handle))+1, 0, &out, 0, 0);
385 error = USD_WRITE(ufd, &buffer[bytesread-bytesleft], bytesleft, &w);
387 fprintf(STDERR,"File system write failed\n");
394 if (buffer) free(buffer);
398 afs_int32 DumpFunction(call, filename)
399 struct rx_call *call;
402 usd_handle_t ufd; /* default is to stdout */
403 afs_int32 error=0, code;
408 /* Open the output file */
409 if (!filename || !*filename) {
410 usd_StandardOutput(&ufd);
414 code = usd_Open(filename, USD_OPEN_CREATE|USD_OPEN_RDWR, 0666, &ufd);
418 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
421 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
424 fprintf(STDERR, "Could not create file '%s'\n", filename);
425 ERROR_EXIT(VOLSERBADOP);
429 code = ReceiveFile(ufd, call, blksize);
430 if (code) ERROR_EXIT(code);
433 /* Close the output file */
435 code = USD_CLOSE(ufd);
437 fprintf(STDERR,"Could not close dump file %s\n",
438 (filename && *filename)?filename:"STDIN");
439 if (!error) error = code;
446 static void DisplayFormat(pntr,server,part,totalOK,totalNotOK,totalBusy,fast,longlist,disp)
448 afs_int32 server,part;
449 int *totalOK,*totalNotOK,*totalBusy;
450 int fast,longlist, disp;
455 fprintf(STDOUT,"%-10u\n",pntr->volid);
458 if(pntr->status == VOK){
459 fprintf(STDOUT,"%-32s ",pntr->name);
460 fprintf(STDOUT,"%10u ",pntr->volid);
461 if(pntr->type == 0) fprintf(STDOUT,"RW ");
462 if(pntr->type == 1) fprintf(STDOUT,"RO ");
463 if(pntr->type == 2) fprintf(STDOUT,"BK ");
464 fprintf(STDOUT,"%10d K ",pntr->size);
465 if(pntr->inUse == 1) {
466 fprintf(STDOUT,"On-line");
469 fprintf(STDOUT,"Off-line");
472 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
473 fprintf(STDOUT,"\n");
474 MapPartIdIntoName(part,pname);
475 fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname);
476 fprintf(STDOUT," RWrite %10u ROnly %10u Backup %10u \n", pntr->parentID,pntr->cloneID, pntr->backupID);
477 fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota);
478 fprintf(STDOUT," Creation %s",
479 ctime((time_t *)&pntr->creationDate));
480 if(pntr->updateDate < pntr->creationDate)
481 fprintf(STDOUT," Last Update %s",
482 ctime((time_t *)&pntr->creationDate));
484 fprintf(STDOUT," Last Update %s",
485 ctime((time_t *)&pntr->updateDate));
486 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
489 else if (pntr->status == VBUSY) {
491 qPut(&busyHead,pntr->volid);
492 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
496 qPut(¬okHead,pntr->volid);
497 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
499 fprintf(STDOUT,"\n");
501 else {/* default listing */
502 if(pntr->status == VOK){
503 fprintf(STDOUT,"%-32s ",pntr->name);
504 fprintf(STDOUT,"%10u ",pntr->volid);
505 if(pntr->type == 0) fprintf(STDOUT,"RW ");
506 if(pntr->type == 1) fprintf(STDOUT,"RO ");
507 if(pntr->type == 2) fprintf(STDOUT,"BK ");
508 fprintf(STDOUT,"%10d K ",pntr->size);
509 if(pntr->inUse == 1) {
510 fprintf(STDOUT,"On-line");
513 fprintf(STDOUT,"Off-line");
516 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
517 fprintf(STDOUT,"\n");
519 else if (pntr->status == VBUSY) {
521 qPut(&busyHead,pntr->volid);
522 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
526 qPut(¬okHead,pntr->volid);
527 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
532 /*------------------------------------------------------------------------
533 * PRIVATE XDisplayFormat
536 * Display the contents of one extended volume info structure.
539 * a_xInfoP : Ptr to extended volume info struct to print.
540 * a_servID : Server ID to print.
541 * a_partID : Partition ID to print.
542 * a_totalOKP : Ptr to total-OK counter.
543 * a_totalNotOKP : Ptr to total-screwed counter.
544 * a_totalBusyP : Ptr to total-busy counter.
545 * a_fast : Fast listing?
546 * a_int32 : Int32 listing?
547 * a_showProblems : Show volume problems?
553 * Nothing interesting.
557 *------------------------------------------------------------------------*/
559 static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP,
560 a_totalNotOKP, a_totalBusyP, a_fast, a_int32,
562 volintXInfo *a_xInfoP;
580 fprintf(STDOUT, "%-10u\n", a_xInfoP->volid);
585 * Fully-detailed listing.
587 if (a_xInfoP->status == VOK) {
589 * Volume's status is OK - all the fields are valid.
591 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
592 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
593 if (a_xInfoP->type == 0) fprintf(STDOUT,"RW ");
594 if (a_xInfoP->type == 1) fprintf(STDOUT,"RO ");
595 if (a_xInfoP->type == 2) fprintf(STDOUT,"BK ");
596 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
597 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
598 if(a_xInfoP->inUse == 1) {
599 fprintf(STDOUT, "On-line");
603 fprintf(STDOUT, "Off-line");
606 fprintf(STDOUT, "\n");
607 MapPartIdIntoName(a_partID, pname);
608 fprintf(STDOUT, " %s %s \n",
609 hostutil_GetNameByINet(a_servID),
611 fprintf(STDOUT, " RWrite %10u ROnly %10u Backup %10u \n",
612 a_xInfoP->parentID, a_xInfoP->cloneID, a_xInfoP->backupID);
613 fprintf(STDOUT, " MaxQuota %10d K \n",
615 fprintf(STDOUT, " Creation %s",
616 ctime((time_t *)&a_xInfoP->creationDate));
617 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
618 fprintf(STDOUT, " Last Update %s",
619 ctime((time_t *)&a_xInfoP->creationDate));
621 fprintf(STDOUT, " Last Update %s",
622 ctime((time_t *)&a_xInfoP->updateDate));
623 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
627 * Print all the read/write and authorship stats.
630 "\n Raw Read/Write Stats\n");
632 " |-------------------------------------------|\n");
634 " | Same Network | Diff Network |\n");
636 " |----------|----------|----------|----------|\n");
638 " | Total | Auth | Total | Auth |\n");
640 " |----------|----------|----------|----------|\n");
642 "Reads | %8d | %8d | %8d | %8d |\n",
643 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
644 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
645 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
646 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
648 "Writes | %8d | %8d | %8d | %8d |\n",
649 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
650 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
651 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
652 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
654 " |-------------------------------------------|\n\n");
657 " Writes Affecting Authorship\n");
659 " |-------------------------------------------|\n");
661 " | File Authorship | Directory Authorship|\n");
663 " |----------|----------|----------|----------|\n");
665 " | Same | Diff | Same | Diff |\n");
667 " |----------|----------|----------|----------|\n");
669 "0-60 sec | %8d | %8d | %8d | %8d |\n",
670 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
671 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
672 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
673 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
675 "1-10 min | %8d | %8d | %8d | %8d |\n",
676 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
677 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
678 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
679 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
681 "10min-1hr | %8d | %8d | %8d | %8d |\n",
682 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
683 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
684 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
685 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
687 "1hr-1day | %8d | %8d | %8d | %8d |\n",
688 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
689 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
690 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
691 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
693 "1day-1wk | %8d | %8d | %8d | %8d |\n",
694 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
695 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
696 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
697 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
699 "> 1wk | %8d | %8d | %8d | %8d |\n",
700 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
701 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
702 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
703 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
705 " |-------------------------------------------|\n");
706 } /*Volume status OK*/
708 if (a_xInfoP->status == VBUSY) {
710 qPut(&busyHead, a_xInfoP->volid);
712 fprintf(STDOUT, "**** Volume %u is busy ****\n",
717 qPut(¬okHead, a_xInfoP->volid);
719 fprintf(STDOUT, "**** Could not attach volume %u ****\n",
722 fprintf(STDOUT,"\n");
728 if (a_xInfoP->status == VOK) {
729 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
730 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
731 if (a_xInfoP->type == 0) fprintf(STDOUT, "RW ");
732 if (a_xInfoP->type == 1) fprintf(STDOUT, "RO ");
733 if (a_xInfoP->type == 2) fprintf(STDOUT, "BK ");
734 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
735 if(a_xInfoP->inUse == 1) {
736 fprintf(STDOUT, "On-line");
739 fprintf(STDOUT, "Off-line");
742 fprintf(STDOUT, "\n");
745 if (a_xInfoP->status == VBUSY) {
747 qPut(&busyHead, a_xInfoP->volid);
749 fprintf(STDOUT,"**** Volume %u is busy ****\n",
754 qPut(¬okHead, a_xInfoP->volid);
756 fprintf(STDOUT,"**** Could not attach volume %u ****\n",
759 } /*Default listing*/
762 static void DisplayVolumes(server,part,pntr,count,longlist,fast,quiet)
763 afs_int32 server,part;
765 afs_int32 count,longlist,fast;
768 int totalOK,totalNotOK,totalBusy, i;
776 for(i = 0; i < count; i++){
777 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,fast,longlist,0);
781 while(busyHead.count){
782 qGet(&busyHead,&volid);
783 fprintf(STDOUT,"**** Volume %u is busy ****\n",volid);
787 while(notokHead.count){
788 qGet(¬okHead,&volid);
789 fprintf(STDOUT,"**** Could not attach volume %u ****\n",volid);
793 fprintf(STDOUT,"\n");
795 fprintf(STDOUT,"Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",totalOK,totalNotOK,totalBusy);
800 /*------------------------------------------------------------------------
801 * PRIVATE XDisplayVolumes
804 * Display extended volume information.
807 * a_servID : Pointer to the Rx call we're performing.
808 * a_partID : Partition for which we want the extended list.
809 * a_xInfoP : Ptr to extended volume info.
810 * a_count : Number of volume records contained above.
811 * a_int32 : Int32 listing generated?
812 * a_fast : Fast listing generated?
813 * a_quiet : Quiet listing generated?
819 * Nothing interesting.
823 *------------------------------------------------------------------------*/
825 static void XDisplayVolumes(a_servID, a_partID, a_xInfoP,
826 a_count, a_int32, a_fast, a_quiet)
829 volintXInfo *a_xInfoP;
835 { /*XDisplayVolumes*/
837 int totalOK; /*Total OK volumes*/
838 int totalNotOK; /*Total screwed volumes*/
839 int totalBusy; /*Total busy volumes*/
840 int i; /*Loop variable*/
841 afs_int32 volid; /*Current volume ID*/
844 * Initialize counters and (global!!) queues.
853 * Display each volume in the list.
855 for(i = 0; i < a_count; i++) {
856 XDisplayFormat(a_xInfoP,
869 * If any volumes were found to be busy or screwed, display them.
872 while (busyHead.count) {
873 qGet(&busyHead, &volid);
874 fprintf(STDOUT, "**** Volume %u is busy ****\n", volid);
878 while (notokHead.count) {
879 qGet(¬okHead, &volid);
880 fprintf(STDOUT, "**** Could not attach volume %u ****\n", volid);
885 fprintf(STDOUT, "\n");
888 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
889 totalOK, totalNotOK, totalBusy);
893 } /*XDisplayVolumes*/
895 /* set <server> and <part> to the correct values depending on
896 * <voltype> and <entry> */
897 static void GetServerAndPart (entry, voltype, server, part, previdx)
898 struct nvldbentry *entry;
899 afs_int32 *server,*part;
903 int i, istart, vtype;
908 /* Doesn't check for non-existance of backup volume */
909 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
911 istart = 0; /* seach the entire entry */
914 /* Seach from beginning of entry or pick up where we left off */
915 istart = ((*previdx < 0) ? 0 : *previdx+1);
918 for (i = istart; i < entry->nServers; i++) {
919 if (entry->serverFlags[i] & vtype) {
920 *server = entry->serverNumber[i];
921 *part = entry->serverPartition[i];
927 /* Didn't find any, return -1 */
932 static void PostVolumeStats(entry)
933 struct nvldbentry *entry;
935 SubEnumerateEntry(entry);
936 /* Check for VLOP_ALLOPERS */
937 if (entry->flags & VLOP_ALLOPERS)
938 fprintf(STDOUT," Volume is currently LOCKED \n");
942 /*------------------------------------------------------------------------
943 * PRIVATE XVolumeStats
946 * Display extended volume information.
949 * a_xInfoP : Ptr to extended volume info.
950 * a_entryP : Ptr to the volume's VLDB entry.
951 * a_srvID : Server ID.
952 * a_partID : Partition ID.
953 * a_volType : Type of volume to print.
959 * Nothing interesting.
963 *------------------------------------------------------------------------*/
965 static void XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
966 volintXInfo *a_xInfoP;
967 struct nvldbentry *a_entryP;
974 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here*/
976 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info*/
977 a_srvID, /*Server ID to print*/
978 a_partID, /*Partition ID to print*/
979 &totalOK, /*Ptr to total-OK counter*/
980 &totalNotOK, /*Ptr to total-screwed counter*/
981 &totalBusy, /*Ptr to total-busy counter*/
982 0, /*Don't do a fast listing*/
983 1, /*Do a long listing*/
984 1); /*Show volume problems*/
989 static void VolumeStats(pntr,entry,server,part,voltype)
991 struct nvldbentry *entry;
993 afs_int32 server,part;
995 int totalOK,totalNotOK,totalBusy;
996 afs_int32 vcode,vcode2;
998 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,0,1,1);
1002 /* command to forcibly remove a volume */
1003 static NukeVolume(as)
1004 register struct cmd_syndesc *as; {
1005 register afs_int32 code;
1006 afs_int32 volID, err;
1011 server = GetServer(tp = as->parms[0].items->data);
1013 fprintf(STDERR,"vos: server '%s' not found in host table\n", tp);
1017 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1019 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1023 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1025 if (err) PrintError("", err);
1026 else fprintf(STDERR, "vos: could not parse '%s' as a numeric volume ID", tp);
1030 fprintf(STDOUT, "vos: forcibly removing all traces of volume %d, please wait...", volID);
1032 code = UV_NukeVolume(server, partID, volID);
1034 fprintf(STDOUT, "done.\n");
1036 fprintf(STDOUT, "failed with code %d.\n", code);
1041 /*------------------------------------------------------------------------
1042 * PRIVATE ExamineVolume
1045 * Routine used to examine a single volume, contacting the VLDB as
1046 * well as the Volume Server.
1049 * as : Ptr to parsed command line arguments.
1052 * 0 for a successful operation,
1053 * Otherwise, one of the ubik or VolServer error values.
1056 * Nothing interesting.
1060 *------------------------------------------------------------------------
1062 static ExamineVolume(as)
1063 register struct cmd_syndesc *as;
1065 struct nvldbentry entry;
1066 afs_int32 vcode = 0;
1067 volintInfo *pntr = (volintInfo *)0;
1068 volintXInfo *xInfoP = (volintXInfo *)0;
1070 afs_int32 code, err, error = 0;
1071 int voltype, foundserv = 0, foundentry = 0;
1072 afs_int32 aserver, apart;
1074 int wantExtendedInfo; /*Do we want extended vol info?*/
1076 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1078 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1080 if (err) PrintError("", err);
1081 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1086 fprintf(STDOUT, "Fetching VLDB entry for %u .. ", volid);
1089 vcode = VLDB_GetEntryByID (volid, -1, &entry);
1091 fprintf(STDERR, "Could not fetch the entry for volume number %u from VLDB \n",volid);
1095 fprintf(STDOUT, "done\n");
1096 MapHostToNetwork(&entry);
1098 if (entry.volumeId[RWVOL] == volid)
1100 else if (entry.volumeId[BACKVOL] == volid)
1102 else /* (entry.volumeId[ROVOL] == volid) */
1105 do { /* do {...} while (voltype == ROVOL) */
1106 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1107 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1108 * If its a RO vol, get the next RO entry.
1110 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart, &previdx);
1111 if (previdx == -1) { /* searched all entries */
1113 fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data);
1120 /* Get information about the volume from the server */
1122 fprintf(STDOUT,"Getting volume listing from the server %s .. ",
1123 hostutil_GetNameByINet(aserver));
1126 if (wantExtendedInfo)
1127 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1129 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1131 fprintf(STDOUT,"done\n");
1135 if (code == ENODEV) {
1136 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1137 /* The VLDB says there is no backup volume and its not on disk */
1138 fprintf(STDERR, "Volume %s does not exist\n", as->parms[0].items->data);
1141 fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n",
1142 hostutil_GetNameByINet(aserver));
1145 PrintDiagnostics("examine", code);
1147 fprintf(STDOUT, "\n");
1150 if (wantExtendedInfo)
1151 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1153 VolumeStats(pntr, &entry, aserver, apart, voltype);
1155 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1156 /* The VLDB says there is no backup volume yet we found one on disk */
1157 fprintf(STDERR, "Volume %s does not exist in VLDB\n", as->parms[0].items->data);
1162 if (pntr) free(pntr);
1163 if (xInfoP) free(xInfoP);
1164 } while (voltype == ROVOL);
1167 fprintf(STDERR,"Dump only information from VLDB\n\n");
1168 fprintf(STDOUT,"%s \n", entry.name); /* PostVolumeStats doesn't print name */
1170 PostVolumeStats(&entry);
1175 /*------------------------------------------------------------------------
1179 * Brings a volume online.
1182 * as : Ptr to parsed command line arguments.
1185 * 0 for a successful operation,
1188 * Nothing interesting.
1192 *------------------------------------------------------------------------
1194 static volOnline(as)
1195 register struct cmd_syndesc *as;
1197 afs_int32 server, partition, volid;
1198 afs_int32 code, err=0;
1200 server = GetServer(as->parms[0].items->data);
1202 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1206 partition = volutil_GetPartitionID(as->parms[1].items->data);
1207 if (partition < 0) {
1208 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1212 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1214 if (err) PrintError("", err);
1215 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1219 code = UV_SetVolume(server, partition, volid, ITOffline, 0/*online*/, 0/*sleep*/);
1221 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1228 /*------------------------------------------------------------------------
1229 * PRIVATE volOffline
1232 * Brings a volume offline.
1235 * as : Ptr to parsed command line arguments.
1238 * 0 for a successful operation,
1241 * Nothing interesting.
1245 *------------------------------------------------------------------------
1247 static volOffline(as)
1248 register struct cmd_syndesc *as;
1250 afs_int32 server, partition, volid;
1251 afs_int32 code, err=0;
1252 afs_int32 transflag, sleeptime, transdone;
1254 server = GetServer(as->parms[0].items->data);
1256 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1260 partition = volutil_GetPartitionID(as->parms[1].items->data);
1261 if (partition < 0) {
1262 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1266 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1268 if (err) PrintError("", err);
1269 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1273 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1274 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1275 transdone = (sleeptime ? 0/*online*/ : VTOutOfService);
1276 if (as->parms[4].items && !as->parms[3].items) {
1277 fprintf(STDERR,"-sleep option must be used with -busy flag\n");
1281 code = UV_SetVolume(server, partition, volid, transflag, transdone, sleeptime);
1283 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1290 static CreateVolume(as)
1291 register struct cmd_syndesc *as;
1295 afs_int32 volid,code;
1296 struct nvldbentry entry;
1301 tserver = GetServer(as->parms[0].items->data);
1303 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
1306 pname = volutil_GetPartitionID(as->parms[1].items->data);
1308 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1311 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
1312 if(code) PrintError("",code);
1313 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1316 if(!ISNAMEVALID(as->parms[2].items->data)) {
1317 fprintf(STDERR,"vos: the name of the root volume %s exceeds the size limit of %d\n",as->parms[2].items->data,VOLSER_OLDMAXVOLNAME - 10);
1320 if(!VolNameOK(as->parms[2].items->data)){
1321 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[2].items->data);
1324 if(IsNumeric(as->parms[2].items->data)){
1325 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[2].items->data);
1328 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1330 fprintf(STDERR,"Volume %s already exists\n",as->parms[2].items->data);
1331 PrintDiagnostics("create", code);
1335 if (as->parms[3].items) {
1336 if (!IsNumeric(as->parms[3].items->data)){
1337 fprintf(STDERR,"Initial quota %s should be numeric.\n", as->parms[3].items->data);
1341 code = util_GetInt32(as->parms[3].items->data, "a);
1343 fprintf(STDERR,"vos: bad integer specified for quota.\n");
1348 code = UV_CreateVolume2(tserver, pname,as->parms[2].items->data,
1349 quota, 0, 0, 0, 0, &volid);
1351 PrintDiagnostics("create", code);
1354 MapPartIdIntoName(pname, part);
1355 fprintf(STDOUT,"Volume %u created on partition %s of %s\n", volid, part,as->parms[0].items->data );
1360 static afs_int32 DeleteAll(entry)
1361 struct nvldbentry *entry;
1364 afs_int32 error, code, curserver, curpart, volid;
1366 MapHostToNetwork(entry);
1368 for(i=0; i < entry->nServers; i++){
1369 curserver = entry->serverNumber[i];
1370 curpart = entry->serverPartition[i];
1371 if(entry->serverFlags[i] & ITSROVOL){
1372 volid = entry->volumeId[ROVOL];
1375 volid = entry->volumeId[RWVOL];
1377 code = UV_DeleteVolume(curserver,curpart,volid);
1384 static DeleteVolume(as)
1385 struct cmd_syndesc *as;
1387 afs_int32 err, code = 0;
1388 afs_int32 server = 0, partition = -1, volid;
1392 if (as->parms[0].items) {
1393 server = GetServer(as->parms[0].items->data);
1395 fprintf(STDERR,"vos: server '%s' not found in host table\n",
1396 as->parms[0].items->data);
1401 if (as->parms[1].items) {
1402 partition = volutil_GetPartitionID(as->parms[1].items->data);
1403 if (partition < 0) {
1404 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
1405 as->parms[1].items->data );
1409 /* Check for validity of the partition */
1410 if (!IsPartValid(partition, server, &code)) {
1412 PrintError("", code);
1414 fprintf(STDERR,"vos : partition %s does not exist on the server\n",
1415 as->parms[1].items->data);
1421 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1423 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1424 as->parms[2].items->data);
1425 if (err) PrintError("", err);
1429 /* If the server or partition option are not complete, try to fill
1430 * them in from the VLDB entry.
1432 if ((partition == -1) || !server) {
1433 struct nvldbentry entry;
1435 code = VLDB_GetEntryByID(volid, -1, &entry);
1437 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB\n",
1439 PrintError("",code);
1443 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) ||
1444 ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS)) ) {
1445 idx = Lp_GetRwIndex(&entry);
1447 (server && (server != entry.serverNumber[idx])) ||
1448 ((partition != -1) && (partition != entry.serverPartition[idx])) ) {
1449 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1453 else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
1454 for (idx=-1,j=0; j<entry.nServers; j++) {
1455 if (entry.serverFlags[j] != ITSROVOL) continue;
1457 if ( ((server == 0) || (server == entry.serverNumber[j])) &&
1458 ((partition == -1) || (partition == entry.serverPartition[j])) ) {
1460 fprintf(STDERR,"VLDB: Volume '%s' matches more than one RO\n",
1461 as->parms[2].items->data);
1468 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1473 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1477 server = htonl(entry.serverNumber[idx]);
1478 partition = entry.serverPartition[idx];
1482 code = UV_DeleteVolume(server, partition, volid);
1484 PrintDiagnostics("remove", code);
1488 MapPartIdIntoName(partition, pname);
1489 fprintf(STDOUT,"Volume %u on partition %s server %s deleted\n",
1490 volid, pname, hostutil_GetNameByINet(server));
1494 #define TESTM 0 /* set for move space tests, clear for production */
1495 static MoveVolume(as)
1496 register struct cmd_syndesc *as;
1499 afs_int32 volid, fromserver, toserver, frompart, topart,code, err;
1500 char fromPartName[10], toPartName[10];
1502 struct diskPartition partition; /* for space check */
1505 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1507 if (err) PrintError("", err);
1508 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1509 as->parms[0].items->data);
1512 fromserver = GetServer(as->parms[1].items->data);
1513 if (fromserver == 0) {
1514 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data);
1517 toserver = GetServer(as->parms[3].items->data);
1518 if (toserver == 0) {
1519 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data);
1522 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1524 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
1527 if (!IsPartValid(frompart,fromserver,&code)){/*check for validity of the partition */
1528 if(code) PrintError("",code);
1529 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data);
1532 topart = volutil_GetPartitionID(as->parms[4].items->data);
1534 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data);
1537 if (!IsPartValid(topart,toserver,&code)){/*check for validity of the partition */
1538 if(code) PrintError("",code);
1539 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data);
1544 check source partition for space to clone volume
1547 MapPartIdIntoName(topart,toPartName);
1548 MapPartIdIntoName(frompart, fromPartName);
1551 check target partition for space to move volume
1554 code=UV_PartitionInfo(toserver,toPartName,&partition);
1557 fprintf(STDERR,"vos: cannot access partition %s\n",toPartName);
1561 fprintf(STDOUT,"target partition %s free space %d\n",
1562 toPartName,partition.free);
1565 code=UV_ListOneVolume(fromserver,frompart,volid,&p);
1568 fprintf(STDERR,"vos:cannot access volume %u\n",volid);
1573 fprintf(STDOUT,"volume %u size %d\n",volid,p->size);
1574 if(partition.free<=p->size)
1576 fprintf(STDERR,"vos: no space on target partition %s to move volume %u\n",
1585 fprintf(STDOUT,"size test - don't do move\n");
1589 /* successful move still not guaranteed but shoot for it */
1591 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1593 PrintDiagnostics("move", code);
1596 MapPartIdIntoName(topart,toPartName);
1597 MapPartIdIntoName(frompart, fromPartName);
1598 fprintf(STDOUT,"Volume %u moved from %s %s to %s %s \n",volid,as->parms[1].items->data,fromPartName,as->parms[3].items->data,toPartName);
1602 static BackupVolume(as)
1603 register struct cmd_syndesc *as;
1605 afs_int32 avolid, aserver, apart,vtype,code, err;
1606 struct nvldbentry entry;
1608 afs_int32 buvolid,buserver,bupart,butype;
1609 struct nvldbentry buentry;
1610 struct rx_connection *conn;
1612 struct nvldbentry store;
1614 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1616 if (err) PrintError("", err);
1617 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1618 as->parms[0].items->data);
1621 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1624 /* verify this is a readwrite volume */
1628 fprintf(STDERR,"%s not RW volume\n",as->parms[0].items->data);
1632 /* is there a backup volume already? */
1634 if(entry.flags & BACK_EXISTS)
1636 /* yep, where is it? */
1638 buvolid=entry.volumeId[BACKVOL];
1639 code=GetVolumeInfo(buvolid,&buserver,&bupart,&butype,&buentry);
1643 code = VLDB_IsSameAddrs(buserver, aserver, &err);
1645 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver; aborting call!\n", buserver);
1650 fprintf(STDERR,"FATAL ERROR: backup volume %u exists on server %u\n",
1656 /* nope, carry on */
1658 code = UV_BackupVolume(aserver, apart, avolid);
1661 PrintDiagnostics("backup", code);
1664 fprintf(STDOUT,"Created backup volume for %s \n",as->parms[0].items->data);
1667 static ReleaseVolume(as)
1668 register struct cmd_syndesc *as;
1671 struct nvldbentry entry;
1672 afs_int32 avolid, aserver, apart,vtype,code, err;
1675 if(as->parms[1].items) force = 1;
1676 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1678 if (err) PrintError("", err);
1679 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1682 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1683 if(code) return code;
1685 if (vtype != RWVOL) {
1686 fprintf(STDERR,"%s not a RW volume\n", as->parms[0].items->data);
1690 if(!ISNAMEVALID(entry.name)){
1691 fprintf(STDERR,"Volume name %s is too long, rename before releasing\n",entry.name);
1695 code = UV_ReleaseVolume(avolid, aserver, apart, force);
1697 PrintDiagnostics("release", code);
1700 fprintf(STDOUT,"Released volume %s successfully\n",as->parms[0].items->data );
1703 static DumpVolume(as)
1704 register struct cmd_syndesc *as;
1707 afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i;
1708 char filename[NameLen];
1709 struct nvldbentry entry;
1711 rx_SetRxDeadTime(60 * 10);
1712 for (i = 0; i<MAXSERVERS; i++) {
1713 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct,i);
1714 if (rxConn == 0) break;
1715 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
1716 if (rxConn->service) rxConn->service->connDeadTime = rx_connDeadTime;
1719 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1721 if (err) PrintError("", err);
1722 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1726 if (as->parms[3].items || as->parms[4].items) {
1727 if (!as->parms[3].items || !as->parms[4].items) {
1728 fprintf(STDERR, "Must specify both -server and -partition options\n");
1731 aserver = GetServer(as->parms[3].items->data);
1733 fprintf(STDERR, "Invalid server name\n");
1736 apart = volutil_GetPartitionID(as->parms[4].items->data);
1738 fprintf(STDERR, "Invalid partition name\n");
1742 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
1743 if (code) return code;
1746 if (as->parms[1].items && strcmp(as->parms[1].items->data,"0")) {
1747 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
1749 fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n",
1750 as->parms[1].items->data, code);
1754 if(as->parms[2].items){
1755 strcpy(filename,as->parms[2].items->data);
1758 strcpy(filename,"");
1760 code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
1762 PrintDiagnostics("dump", code);
1765 if(strcmp(filename,""))
1766 fprintf(STDERR,"Dumped volume %s in file %s\n",as->parms[0].items->data, filename);
1768 fprintf(STDERR,"Dumped volume %s in stdout \n",as->parms[0].items->data);
1777 static RestoreVolume(as)
1778 register struct cmd_syndesc *as;
1781 afs_int32 avolid, aserver, apart, code,vcode, err;
1782 afs_int32 aoverwrite = ASK;
1785 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1],apartName[10];
1786 char volname[VOLSER_MAXVOLNAME +1];
1787 struct nvldbentry entry;
1791 if(as->parms[4].items){
1792 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
1794 if (err) PrintError("", err);
1795 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[4].items->data);
1802 if (as->parms[5].items) {
1803 if ( (strcmp(as->parms[5].items->data, "a") == 0) ||
1804 (strcmp(as->parms[5].items->data, "abort") == 0) ) {
1807 else if ( (strcmp(as->parms[5].items->data, "f") == 0) ||
1808 (strcmp(as->parms[5].items->data, "full") == 0) ) {
1811 else if ( (strcmp(as->parms[5].items->data, "i") == 0) ||
1812 (strcmp(as->parms[5].items->data, "inc") == 0) ||
1813 (strcmp(as->parms[5].items->data, "increment") == 0) ||
1814 (strcmp(as->parms[5].items->data, "incremental") == 0) ) {
1818 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
1819 as->parms[5].items->data);
1824 aserver = GetServer(as->parms[0].items->data);
1826 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1829 apart = volutil_GetPartitionID(as->parms[1].items->data);
1831 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1834 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
1835 if(code) PrintError("",code);
1836 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1839 strcpy(avolname,as->parms[2].items->data );
1840 if(!ISNAMEVALID(avolname)) {
1841 fprintf(STDERR,"vos: the name of the volume %s exceeds the size limit\n",avolname);
1844 if(!VolNameOK(avolname)){
1845 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",avolname);
1848 if(as->parms[3].items){
1849 strcpy(afilename,as->parms[3].items->data );
1850 if(!FileExists(afilename)){
1851 fprintf(STDERR,"Can't access file %s\n",afilename);
1856 strcpy(afilename,"");
1859 /* Check if volume exists or not */
1861 vsu_ExtractName(volname,avolname);
1862 vcode = VLDB_GetEntryByName(volname, &entry);
1863 if (vcode) { /* no volume - do a full restore */
1864 restoreflags = RV_FULLRST;
1865 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1866 fprintf(STDERR,"Volume does not exist; Will perform a full restore\n");
1869 else if (Lp_GetRwIndex(&entry) == -1) { /* RW volume does not exist - do a full */
1870 restoreflags = RV_FULLRST;
1871 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1872 fprintf(STDERR,"RW Volume does not exist; Will perform a full restore\n");
1875 avolid = entry.volumeId[RWVOL];
1877 else if (entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1878 avolid = entry.volumeId[RWVOL];
1882 else { /* volume exists - do we do a full incremental or abort */
1883 int Oserver, Opart, Otype, vol_elsewhere = 0;
1884 struct nvldbentry Oentry;
1888 avolid = entry.volumeId[RWVOL];
1890 else if(entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1891 avolid = entry.volumeId[RWVOL];
1894 /* A file name was specified - check if volume is on another partition */
1895 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
1898 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
1900 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1904 if (!vcode || (Opart != apart)) vol_elsewhere = 1;
1906 if (aoverwrite == ASK) {
1907 if (strcmp(afilename,"") == 0) { /* The file is from standard in */
1908 fprintf(STDERR,"Volume exists and no -overwrite option specified; Aborting restore command\n");
1912 /* Ask what to do */
1913 if (vol_elsewhere) {
1914 fprintf(STDERR,"The volume %s %u already exists on a different server/part\n",
1915 volname, entry.volumeId[RWVOL]);
1917 "Do you want to do a full restore or abort? [fa](a): ");
1921 fprintf(STDERR,"The volume %s %u already exists in the VLDB\n",
1922 volname, entry.volumeId[RWVOL]);
1924 "Do you want to do a full/incremental restore or abort? [fia](a): ");
1927 while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */
1928 if ((c == 'f') || (c == 'F')) aoverwrite = FULL;
1929 else if ((c == 'i') || (c == 'I')) aoverwrite = INC;
1930 else aoverwrite = ABORT;
1933 if (aoverwrite == ABORT) {
1934 fprintf(STDERR,"Volume exists; Aborting restore command\n");
1937 else if (aoverwrite == FULL) {
1938 restoreflags = RV_FULLRST;
1939 fprintf(STDERR,"Volume exists; Will delete and perform full restore\n");
1941 else if (aoverwrite == INC) {
1943 if (vol_elsewhere) {
1945 "RW volume %u already exists on a different server/part; not allowed\n",
1951 code = UV_RestoreVolume(aserver, apart, avolid, avolname,
1952 restoreflags, WriteData, afilename);
1954 PrintDiagnostics("restore", code);
1957 MapPartIdIntoName(apart,apartName);
1960 patch typo here - originally "parms[1]", should be "parms[0]"
1963 fprintf(STDOUT,"Restored volume %s on %s %s\n",
1964 avolname, as->parms[0].items->data, apartName);
1967 static LockReleaseCmd(as)
1968 register struct cmd_syndesc *as;
1971 afs_int32 avolid,code, err;
1973 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1975 if (err) PrintError("", err);
1976 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1980 code = UV_LockRelease(avolid);
1982 PrintDiagnostics("unlock", code);
1985 fprintf(STDOUT,"Released lock on vldb entry for volume %s\n",as->parms[0].items->data);
1989 register struct cmd_syndesc *as;
1991 afs_int32 avolid, aserver, apart,code, err;
1994 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1996 if (err) PrintError("", err);
1997 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2000 aserver = GetServer(as->parms[0].items->data);
2002 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2005 apart = volutil_GetPartitionID(as->parms[1].items->data);
2007 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2010 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2011 if(code) PrintError("",code);
2012 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2015 code = UV_AddSite(aserver, apart, avolid);
2017 PrintDiagnostics("addsite", code);
2020 MapPartIdIntoName(apart,apartName);
2021 fprintf(STDOUT,"Added replication site %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data);
2025 static RemoveSite(as)
2026 register struct cmd_syndesc *as;
2029 afs_int32 avolid, aserver, apart, code, err;
2032 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2034 if (err) PrintError("", err);
2035 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2038 aserver = GetServer(as->parms[0].items->data);
2040 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2043 apart = volutil_GetPartitionID(as->parms[1].items->data);
2045 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2049 *skip the partition validity check, since it is possible that the partition
2050 *has since been decomissioned.
2053 if (!IsPartValid(apart,aserver,&code)){
2054 if(code) PrintError("",code);
2055 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2059 code = UV_RemoveSite(aserver, apart, avolid);
2061 PrintDiagnostics("remsite", code);
2064 MapPartIdIntoName(apart,apartName);
2065 fprintf(STDOUT,"Removed replication site %s %s for volume %s\n",as->parms[0].items->data,apartName,as->parms[2].items->data);
2069 static ListPartitions(as)
2070 register struct cmd_syndesc *as;
2072 afs_int32 aserver,code;
2073 struct partList dummyPartList;
2078 aserver = GetServer(as->parms[0].items->data);
2080 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2085 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2087 PrintDiagnostics("listpart", code);
2091 fprintf(STDOUT,"The partitions on the server are:\n");
2092 for(i = 0 ; i < cnt ; i++){
2093 if(dummyPartList.partFlags[i] & PARTVALID){
2094 bzero(pname,sizeof(pname));
2095 MapPartIdIntoName(dummyPartList.partId[i],pname);
2096 fprintf(STDOUT," %10s ",pname);
2098 if( (i % 5) == 0 && (i != 0)) fprintf(STDOUT,"\n");
2101 fprintf(STDOUT,"\n");
2102 fprintf(STDOUT,"Total: %d\n",total);
2107 static int CompareVolName(p1,p2)
2110 volintInfo *arg1,*arg2;
2112 arg1 = (volintInfo *)p1;
2113 arg2 = (volintInfo *)p2;
2114 return(strcmp(arg1->name,arg2->name));
2118 /*------------------------------------------------------------------------
2119 * PRIVATE XCompareVolName
2122 * Comparison routine for volume names coming from an extended
2126 * a_obj1P : Char ptr to first extended vol info object
2127 * a_obj1P : Char ptr to second extended vol info object
2130 * The value of strcmp() on the volume names within the passed
2131 * objects (i,e., -1, 0, or 1).
2134 * Passed to qsort() as the designated comparison routine.
2138 *------------------------------------------------------------------------*/
2140 static int XCompareVolName(a_obj1P, a_obj2P)
2141 char *a_obj1P, *a_obj2P;
2143 { /*XCompareVolName*/
2145 return(strcmp(((struct volintXInfo *)(a_obj1P))->name,
2146 ((struct volintXInfo *)(a_obj2P))->name));
2148 } /*XCompareVolName*/
2150 static int CompareVolID(p1,p2)
2153 volintInfo *arg1,*arg2;
2155 arg1 = (volintInfo *)p1;
2156 arg2 = (volintInfo *)p2;
2157 if(arg1->volid == arg2->volid) return 0;
2158 if(arg1->volid > arg2->volid) return 1;
2163 /*------------------------------------------------------------------------
2164 * PRIVATE XCompareVolID
2167 * Comparison routine for volume IDs coming from an extended
2171 * a_obj1P : Char ptr to first extended vol info object
2172 * a_obj1P : Char ptr to second extended vol info object
2175 * The value of strcmp() on the volume names within the passed
2176 * objects (i,e., -1, 0, or 1).
2179 * Passed to qsort() as the designated comparison routine.
2183 *------------------------------------------------------------------------*/
2185 static int XCompareVolID(a_obj1P, a_obj2P)
2186 char *a_obj1P, *a_obj2P;
2190 afs_int32 id1, id2; /*Volume IDs we're comparing*/
2192 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2193 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2204 /*------------------------------------------------------------------------
2205 * PRIVATE ListVolumes
2208 * Routine used to list volumes, contacting the Volume Server
2209 * directly, bypassing the VLDB.
2212 * as : Ptr to parsed command line arguments.
2215 * 0 Successful operation
2218 * Nothing interesting.
2222 *------------------------------------------------------------------------*/
2224 static ListVolumes(as)
2225 register struct cmd_syndesc *as;
2227 afs_int32 apart,int32list,fast;
2228 afs_int32 aserver,code;
2229 volintInfo *pntr,*oldpntr;
2233 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info*/
2234 int wantExtendedInfo; /*Do we want extended vol info?*/
2237 struct partList dummyPartList;
2245 if(as->parms[3].items) int32list = 1;
2246 if(as->parms[4].items) quiet = 1;
2248 if(as->parms[2].items) fast = 1;
2251 if (as->parms[5].items) {
2253 * We can't coexist with the fast flag.
2257 "vos: Can't use the -fast and -extended flags together\n");
2262 * We need to turn on ``long'' listings to get the full effect.
2264 wantExtendedInfo = 1;
2268 wantExtendedInfo = 0;
2269 if(as->parms[1].items){
2270 apart = volutil_GetPartitionID(as->parms[1].items->data);
2272 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
2275 dummyPartList.partId[0] = apart;
2276 dummyPartList.partFlags[0] = PARTVALID;
2279 aserver = GetServer(as->parms[0].items->data);
2281 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
2286 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2287 if(code) PrintError("",code);
2288 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2293 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2295 PrintDiagnostics("listvol", code);
2299 for(i = 0 ; i < cnt ; i++){
2300 if(dummyPartList.partFlags[i] & PARTVALID){
2301 if (wantExtendedInfo)
2302 code = UV_XListVolumes(aserver,
2303 dummyPartList.partId[i],
2308 code = UV_ListVolumes(aserver,
2309 dummyPartList.partId[i],
2314 PrintDiagnostics("listvol", code);
2315 if(pntr) free(pntr);
2318 if (wantExtendedInfo) {
2319 origxInfoP = xInfoP;
2320 base = (char *)xInfoP;
2323 base = (char *)pntr;
2327 if (wantExtendedInfo)
2328 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2330 qsort(base, count, sizeof(volintInfo), CompareVolName);
2332 if (wantExtendedInfo)
2333 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2335 qsort(base, count, sizeof(volintInfo), CompareVolID);
2337 MapPartIdIntoName(dummyPartList.partId[i],pname);
2339 fprintf(STDOUT,"Total number of volumes on server %s partition %s: %u \n",as->parms[0].items->data,pname,count);
2340 if (wantExtendedInfo) {
2341 XDisplayVolumes(aserver,
2342 dummyPartList.partId[i],
2350 xInfoP = (volintXInfo *)0;
2353 DisplayVolumes(aserver,
2354 dummyPartList.partId[i],
2362 pntr = (volintInfo *)0;
2370 register struct cmd_syndesc *as;
2372 afs_int32 pname, code; /* part name */
2378 if (as->parms[0].items) {
2379 tserver = GetServer(as->parms[0].items->data);
2381 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2386 if (as->parms[1].items) {
2387 pname = volutil_GetPartitionID(as->parms[1].items->data);
2389 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2392 if (!IsPartValid(pname,tserver,&code)) { /*check for validity of the partition */
2393 if(code) PrintError("",code);
2394 else fprintf(STDERR,"vos: partition %s does not exist on the server\n",
2395 as->parms[1].items->data);
2401 fprintf(STDERR,"The -partition option requires a -server option\n");
2406 if (as->parms[2].items) {
2407 /* Synchronize an individual volume */
2408 volname = as->parms[2].items->data;
2409 code = UV_SyncVolume(tserver, pname, volname, flags);
2412 fprintf(STDERR,"Without a -volume option, the -server option is required\n");
2415 code = UV_SyncVldb(tserver, pname, flags, 0/*unused*/);
2419 PrintDiagnostics("syncvldb", code);
2423 /* Print a summary of what we did */
2424 if (volname) fprintf(STDOUT,"VLDB volume %s synchronized", volname);
2425 else fprintf(STDOUT,"VLDB synchronized");
2427 fprintf(STDOUT," with state of server %s", as->parms[0].items->data);
2430 MapPartIdIntoName(pname,part);
2431 fprintf(STDOUT," partition %s\n", part);
2433 fprintf(STDOUT, "\n");
2438 static SyncServer(as)
2439 register struct cmd_syndesc *as;
2442 afs_int32 pname,code; /* part name */
2447 tserver = GetServer(as->parms[0].items->data);
2449 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2452 if(as->parms[1].items){
2453 pname = volutil_GetPartitionID(as->parms[1].items->data);
2455 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data);
2458 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
2459 if(code) PrintError("",code);
2460 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2466 code = UV_SyncServer(tserver, pname, flags, 0/*unused*/);
2468 PrintDiagnostics("syncserv", code);
2472 MapPartIdIntoName(pname,part);
2473 fprintf(STDOUT,"Server %s partition %s synchronized with VLDB\n",as->parms[0].items->data,part);
2475 else fprintf(STDOUT,"Server %s synchronized with VLDB\n",as->parms[0].items->data);
2480 static VolumeInfoCmd(name)
2483 struct nvldbentry entry;
2486 /* The vlserver will handle names with the .readonly
2487 * and .backup extension as well as volume ids.
2489 vcode = VLDB_GetEntryByName(name, &entry);
2491 PrintError("", vcode);
2494 MapHostToNetwork(&entry);
2495 EnumerateEntry(&entry);
2497 /* Defect #3027: grubby check to handle locked volume.
2498 * If VLOP_ALLOPERS is set, the entry is locked.
2499 * Leave this routine as is, but put in correct check.
2501 if (entry.flags & VLOP_ALLOPERS)
2502 fprintf(STDOUT," Volume is currently LOCKED \n");
2507 static VolumeZap(as)
2508 register struct cmd_syndesc *as;
2511 struct nvldbentry entry;
2512 afs_int32 volid,code,server,part, zapbackupid=0, backupid=0, err;
2514 if (as->parms[3].items) {
2515 /* force flag is on, use the other version */
2516 return NukeVolume(as);
2519 if (as->parms[4].items) {
2523 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2525 if (err) PrintError("", err);
2526 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2529 part = volutil_GetPartitionID(as->parms[1].items->data);
2531 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2534 server = GetServer(as->parms[0].items->data);
2536 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2539 if (!IsPartValid(part,server,&code)){/*check for validity of the partition */
2540 if(code) PrintError("",code);
2541 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2544 code = VLDB_GetEntryByID(volid,-1, &entry);
2546 if (volid == entry.volumeId[RWVOL])
2547 backupid = entry.volumeId[BACKVOL];
2548 fprintf(STDERR,"Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n",
2552 volintInfo *pntr = (volintInfo *)0;
2555 code = UV_ListOneVolume(server, part, volid, &pntr);
2557 if (volid == pntr->parentID)
2558 backupid = pntr->backupID;
2559 if (pntr) free(pntr);
2563 code = UV_VolumeZap(server,part, backupid);
2565 PrintDiagnostics("zap", code);
2568 fprintf(STDOUT,"Backup Volume %u deleted\n", backupid);
2571 code = UV_VolumeZap(server,part,volid);
2573 PrintDiagnostics("zap", code);
2576 fprintf(STDOUT,"Volume %u deleted\n",volid);
2581 static VolserStatus(as)
2582 register struct cmd_syndesc *as;
2585 afs_int32 server, code;
2586 transDebugInfo *pntr,*oldpntr;
2591 server = GetServer(as->parms[0].items->data);
2593 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2596 code = UV_VolserStatus(server,&pntr,&count);
2598 PrintDiagnostics("status",code);
2603 fprintf(STDOUT,"No active transactions on %s\n",as->parms[0].items->data);
2605 fprintf(STDOUT,"Total transactions: %d\n",count);
2607 for(i = 0; i < count ; i++){
2608 /*print out the relevant info */
2609 fprintf(STDOUT,"--------------------------------------\n");
2610 fprintf(STDOUT,"transaction: %u created: %s",pntr->tid,
2611 ctime((time_t *)&pntr->time));
2612 if(pntr->returnCode){
2613 fprintf(STDOUT,"returnCode: %u\n",pntr->returnCode);
2616 fprintf(STDOUT,"attachFlags: ");
2617 switch(pntr->iflags){
2618 case ITOffline: fprintf(STDOUT,"offline ");
2620 case ITBusy: fprintf(STDOUT,"busy ");
2622 case ITReadOnly: fprintf(STDOUT,"readonly ");
2624 case ITCreate: fprintf(STDOUT,"create ");
2626 case ITCreateVolID: fprintf(STDOUT,"create volid ");
2629 fprintf(STDOUT,"\n");
2632 fprintf(STDOUT,"volumeStatus: ");
2633 switch(pntr->vflags){
2634 case VTDeleteOnSalvage: fprintf(STDOUT,"deleteOnSalvage ");
2635 case VTOutOfService: fprintf(STDOUT,"outOfService ");
2636 case VTDeleted: fprintf(STDOUT,"deleted ");
2638 fprintf(STDOUT,"\n");
2641 fprintf(STDOUT,"transactionFlags: ");
2642 fprintf(STDOUT,"delete\n");
2644 MapPartIdIntoName(pntr->partition ,pname);
2645 fprintf(STDOUT,"volume: %u partition: %s procedure: %s\n",pntr->volid,pname, pntr->lastProcName);
2646 if(pntr->callValid){
2647 fprintf(STDOUT,"packetRead: %u lastReceiveTime: %d packetSend: %u lastSendTime: %d\n",pntr->readNext,pntr->lastReceiveTime,pntr->transmitNext, pntr->lastSendTime);
2650 fprintf(STDOUT,"--------------------------------------\n");
2651 fprintf(STDOUT,"\n");
2653 if(oldpntr) free(oldpntr);
2657 static RenameVolume(as)
2658 register struct cmd_syndesc *as;
2660 afs_int32 code1,code2,code;
2661 struct nvldbentry entry;
2663 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
2665 fprintf(STDERR,"vos: Could not find entry for volume %s\n",as->parms[0].items->data);
2668 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
2669 if((!code1) && (!code2)) { /*the newname already exists */
2670 fprintf(STDERR,"vos: volume %s already exists\n",as->parms[1].items->data);
2675 fprintf(STDERR,"vos: Could not find entry for volume %s or %s\n",as->parms[0].items->data,as->parms[1].items->data);
2678 if(!VolNameOK(as->parms[0].items->data)){
2679 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[0].items->data);
2682 if(!ISNAMEVALID(as->parms[1].items->data)) {
2683 fprintf(STDERR,"vos: the new volume name %s exceeds the size limit of %d\n",as->parms[1].items->data,VOLSER_OLDMAXVOLNAME - 10);
2686 if(!VolNameOK(as->parms[1].items->data)){
2687 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[1].items->data);
2690 if(IsNumeric(as->parms[1].items->data)){
2691 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[1].items->data);
2694 MapHostToNetwork(&entry);
2695 code = UV_RenameVolume(&entry,as->parms[0].items->data,as->parms[1].items->data);
2697 PrintDiagnostics("rename", code);
2700 fprintf(STDOUT,"Renamed volume %s to %s\n",as->parms[0].items->data,as->parms[1].items->data);
2704 GetVolumeInfo(volid, server, part, voltype,rentry)
2705 afs_int32 *server, volid, *part, *voltype;
2706 register struct nvldbentry *rentry;
2711 vcode = VLDB_GetEntryByID(volid, -1, rentry);
2713 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB \n",volid);
2714 PrintError("",vcode);
2717 MapHostToNetwork(rentry);
2718 if(volid == rentry->volumeId[ROVOL]){
2720 for (i = 0; i < rentry->nServers; i++) {
2721 if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
2722 !(rentry->serverFlags[i] & RO_DONTUSE) )
2726 fprintf(STDERR,"RO volume is not found in VLDB entry for volume %u\n", volid);
2730 *server = rentry->serverNumber[index];
2731 *part = rentry->serverPartition[index];
2735 index = Lp_GetRwIndex(rentry);
2737 fprintf(STDERR,"RW Volume is not found in VLDB entry for volume %u\n", volid);
2740 if(volid == rentry->volumeId[RWVOL]){
2742 *server = rentry->serverNumber[index];
2743 *part = rentry->serverPartition[index];
2746 if(volid == rentry->volumeId[BACKVOL]){
2748 *server = rentry->serverNumber[index];
2749 *part = rentry->serverPartition[index];
2754 static DeleteEntry(as)
2755 register struct cmd_syndesc *as;
2761 struct VldbListByAttributes attributes;
2762 nbulkentries arrayEntries;
2763 register struct nvldbentry *vllist;
2764 struct cmd_item *itp;
2767 char prefix[VOLSER_MAXVOLNAME+1];
2769 afs_int32 totalBack=0, totalFail=0, err;
2771 if (as->parms[0].items) { /* -id */
2772 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
2773 fprintf(STDERR,"You cannot use -server, -partition, or -prefix with the -id argument\n");
2776 for (itp=as->parms[0].items; itp; itp=itp->next) {
2777 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
2779 if (err) PrintError("", err);
2780 else fprintf(STDERR, "vos: can't find volume '%s'\n", itp->data);
2783 if (as->parms[4].items) { /* -noexecute */
2784 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", itp->data);
2788 vcode = ubik_Call(VL_DeleteEntry,cstruct, 0, avolid, RWVOL);
2790 fprintf(STDERR,"Could not delete entry for volume %s\n", itp->data);
2791 fprintf(STDERR,"You must specify a RW volume name or ID "
2792 "(the entire VLDB entry will be deleted)\n", itp->data);
2793 PrintError("",vcode);
2799 fprintf(STDOUT,"Deleted %d VLDB entries\n", totalBack);
2803 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
2804 fprintf(STDERR,"You must specify an option\n");
2808 /* Zero out search attributes */
2809 bzero(&attributes,sizeof(struct VldbListByAttributes));
2811 if (as->parms[1].items) { /* -prefix */
2812 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
2814 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
2815 fprintf(STDERR,"You must provide -server with the -prefix argument\n");
2820 if (as->parms[2].items) { /* -server */
2822 aserver = GetServer(as->parms[2].items->data);
2824 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[2].items->data );
2827 attributes.server = ntohl(aserver);
2828 attributes.Mask |= VLLIST_SERVER;
2831 if (as->parms[3].items) { /* -partition */
2832 if (!as->parms[2].items) {
2833 fprintf(STDERR,"You must provide -server with the -partition argument\n");
2836 apart = volutil_GetPartitionID(as->parms[3].items->data);
2838 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
2839 as->parms[3].items->data);
2842 attributes.partition = apart;
2843 attributes.Mask |= VLLIST_PARTITION;
2846 /* Print status line of what we are doing */
2847 fprintf(STDOUT,"Deleting VLDB entries for ");
2848 if (as->parms[2].items) {
2849 fprintf(STDOUT,"server %s ", as->parms[2].items->data);
2851 if (as->parms[3].items) {
2853 MapPartIdIntoName(apart, pname);
2854 fprintf(STDOUT,"partition %s ", pname);
2857 fprintf(STDOUT,"which are prefixed with %s ", prefix);
2859 fprintf(STDOUT,"\n");
2862 /* Get all the VLDB entries on a server and/or partition */
2863 bzero(&arrayEntries, sizeof(arrayEntries));
2864 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
2866 fprintf(STDERR,"Could not access the VLDB for attributes\n");
2867 PrintError("",vcode);
2871 /* Process each entry */
2872 for (j=0; j<nentries; j++) {
2873 vllist = &arrayEntries.nbulkentries_val[j];
2875 /* It only deletes the RW volumes */
2876 if (strncmp(vllist->name, prefix, strlen(prefix))){
2878 fprintf(STDOUT,"Omitting to delete %s due to prefix %s mismatch\n",
2879 vllist->name, prefix);
2886 if (as->parms[4].items) { /* -noexecute */
2887 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", vllist->name);
2892 /* Only matches the RW volume name */
2893 avolid = vllist->volumeId[RWVOL];
2894 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
2896 fprintf(STDOUT,"Could not delete VDLB entry for %s\n",vllist->name);
2898 PrintError("",vcode);
2903 fprintf(STDOUT,"Deleted VLDB entry for %s \n",vllist->name);
2908 fprintf(STDOUT,"----------------------\n");
2909 fprintf(STDOUT,"Total VLDB entries deleted: %u; failed to delete: %u\n",totalBack,totalFail);
2910 if (arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
2915 static int CompareVldbEntryByName(p1,p2)
2918 struct nvldbentry *arg1,*arg2;
2920 arg1 = (struct nvldbentry *)p1;
2921 arg2 = (struct nvldbentry *)p2;
2922 return(strcmp(arg1->name,arg2->name));
2926 static int CompareVldbEntry(p1,p2)
2929 struct nvldbentry *arg1,*arg2;
2932 char comp1[100],comp2[100];
2933 char temp1[20],temp2[20];
2935 arg1 = (struct nvldbentry *)p1;
2936 arg2 = (struct nvldbentry *)p2;
2940 for(i = 0; i < arg1->nServers; i++)
2941 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
2942 for(i = 0; i < arg2->nServers; i++)
2943 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
2944 if(pos1 == -1 || pos2 == -1){
2948 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
2949 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
2950 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
2951 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
2952 strcat(comp1,temp1);
2953 strcat(comp2,temp2);
2954 strcat(comp1,arg1->name);
2955 strcat(comp1,arg2->name);
2956 return(strcmp(comp1,comp2));
2962 struct cmd_syndesc *as;
2965 afs_int32 aserver,code;
2967 struct VldbListByAttributes attributes;
2968 nbulkentries arrayEntries;
2969 struct nvldbentry *vllist, *tarray=0, *ttarray;
2970 afs_int32 centries, nentries = 0, tarraysize, parraysize;
2973 int quiet, sort, lock;
2974 afs_int32 thisindex, nextindex;
2979 attributes.Mask = 0;
2980 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
2981 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
2982 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
2984 /* If the volume name is given, Use VolumeInfoCmd to look it up
2985 * and not ListAttributes.
2987 if (as->parms[0].items) {
2989 fprintf(STDERR,"vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
2992 code = VolumeInfoCmd(as->parms[0].items->data);
2994 PrintError("",code);
3000 /* Server specified */
3001 if (as->parms[1].items) {
3002 aserver = GetServer(as->parms[1].items->data);
3004 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3007 attributes.server = ntohl(aserver);
3008 attributes.Mask |= VLLIST_SERVER;
3011 /* Partition specified */
3012 if (as->parms[2].items) {
3013 apart = volutil_GetPartitionID(as->parms[2].items->data);
3015 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3018 attributes.partition = apart;
3019 attributes.Mask |= VLLIST_PARTITION;
3023 attributes.Mask |= VLLIST_FLAG;
3024 attributes.flag = VLOP_ALLOPERS;
3027 /* Print header information */
3029 MapPartIdIntoName(apart, pname);
3030 fprintf(STDOUT,"VLDB entries for %s %s%s%s %s\n",
3031 (as->parms[1].items ? "server" : "all" ),
3032 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3033 (as->parms[2].items ? " partition " : ""),
3034 (as->parms[2].items ? pname : ""),
3035 (lock ? "which are locked:" : ""));
3038 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3039 bzero(&arrayEntries, sizeof(arrayEntries));
3043 vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex,
3044 ¢ries, &arrayEntries, &nextindex);
3045 if (vcode == RXGEN_OPCODE) {
3046 /* Vlserver not running with ListAttributesN2. Fall back */
3047 vcode = VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3051 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3052 PrintError("",vcode);
3055 nentries += centries;
3057 /* We don't sort, so just print the entries now */
3059 for (j = 0; j < centries; j++) { /* process each entry */
3060 vllist = &arrayEntries.nbulkentries_val[j];
3061 MapHostToNetwork(vllist);
3062 EnumerateEntry(vllist);
3064 if(vllist->flags & VLOP_ALLOPERS)
3065 fprintf(STDOUT," Volume is currently LOCKED \n");
3069 /* So we sort. First we must collect all the entries and keep
3072 else if (centries > 0) {
3074 /* steal away the first bulk entries array */
3075 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3076 tarraysize = centries * sizeof(struct nvldbentry);
3077 arrayEntries.nbulkentries_val = 0;
3079 /* Grow the tarray to keep the extra entries */
3080 parraysize = (centries * sizeof(struct nvldbentry));
3081 ttarray = (struct nvldbentry *) realloc(tarray, tarraysize + parraysize);
3083 fprintf(STDERR,"Could not allocate enough space for the VLDB entries\n");
3089 bcopy((char *)arrayEntries.nbulkentries_val,
3090 ((char *)tarray)+tarraysize, parraysize);
3091 tarraysize += parraysize;
3095 /* Free the bulk array */
3096 if (arrayEntries.nbulkentries_val) {
3097 free(arrayEntries.nbulkentries_val);
3098 arrayEntries.nbulkentries_val = 0;
3102 /* Here is where we now sort all the entries and print them */
3103 if (sort && (nentries > 0)) {
3104 qsort((char *)tarray, nentries, sizeof(struct nvldbentry), CompareVldbEntryByName);
3105 for (vllist=tarray, j=0; j<nentries; j++, vllist++) {
3106 MapHostToNetwork(vllist);
3107 EnumerateEntry(vllist);
3109 if(vllist->flags & VLOP_ALLOPERS)
3110 fprintf(STDOUT," Volume is currently LOCKED \n");
3115 if (!quiet) fprintf(STDOUT,"\nTotal entries: %u\n", nentries);
3116 if (tarray) free(tarray);
3121 register struct cmd_syndesc *as;
3123 afs_int32 apart=0, avolid;
3124 afs_int32 aserver=0, code, aserver1, apart1;
3126 struct VldbListByAttributes attributes;
3127 nbulkentries arrayEntries;
3128 register struct nvldbentry *vllist;
3132 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3133 afs_int32 totalBack=0;
3134 afs_int32 totalFail=0;
3135 int previdx=-1, error, same;
3138 struct cmd_item *ti;
3142 bzero(&attributes,sizeof(struct VldbListByAttributes));
3143 attributes.Mask = 0;
3145 seenprefix = (as->parms[0].items ? 1 : 0);
3146 exclude = (as->parms[3].items ? 1 : 0);
3147 seenxprefix = (as->parms[4].items ? 1 : 0);
3148 noaction = (as->parms[5].items ? 1 : 0);
3150 if (as->parms[1].items) { /* -server */
3151 aserver = GetServer(as->parms[1].items->data);
3153 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3156 attributes.server = ntohl(aserver);
3157 attributes.Mask |= VLLIST_SERVER;
3160 if (as->parms[2].items) { /* -partition */
3161 apart = volutil_GetPartitionID(as->parms[2].items->data);
3163 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3166 attributes.partition = apart;
3167 attributes.Mask |= VLLIST_PARTITION;
3170 /* Check to make sure the prefix and xprefix expressions compile ok */
3172 for (ti=as->parms[0].items; ti; ti=ti->next) {
3173 if (strncmp(ti->data,"^",1) == 0) {
3174 ccode = (char *)re_comp(ti->data);
3176 fprintf(STDERR,"Unrecognizable -prefix regular expression: '%s': %s\n",
3184 for (ti=as->parms[4].items; ti; ti=ti->next) {
3185 if (strncmp(ti->data,"^",1) == 0) {
3186 ccode = (char *)re_comp(ti->data);
3188 fprintf(STDERR,"Unrecognizable -xprefix regular expression: '%s': %s\n",
3196 bzero(&arrayEntries, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3197 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3199 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3200 PrintError("",vcode);
3204 if (as->parms[1].items || as->parms[2].items || verbose) {
3205 fprintf(STDOUT,"%s up volumes", (noaction?"Would have backed":"Backing"));
3207 if (as->parms[1].items) {
3208 fprintf(STDOUT," on server %s", as->parms[1].items->data);
3209 } else if (as->parms[2].items) {
3210 fprintf(STDOUT," for all servers");
3213 if (as->parms[2].items) {
3214 MapPartIdIntoName(apart, pname);
3215 fprintf(STDOUT," partition %s", pname);
3218 if (seenprefix || (!seenprefix && seenxprefix)) {
3219 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3220 ex = (seenprefix ? exclude : !exclude);
3221 exp = (strncmp(ti->data,"^",1) == 0);
3222 fprintf(STDOUT," which %smatch %s '%s'", (ex ? "do not " : ""),
3223 (exp?"expression":"prefix"), ti->data);
3224 for (ti=ti->next; ti; ti=ti->next) {
3225 exp = (strncmp(ti->data,"^",1) == 0);
3226 printf(" %sor %s '%s'", (ex ? "n" : ""),
3227 (exp?"expression":"prefix"), ti->data);
3231 if (seenprefix && seenxprefix) {
3232 ti = as->parms[4].items;
3233 exp = (strncmp(ti->data,"^",1) == 0);
3234 fprintf(STDOUT," %swhich match %s '%s'",
3235 (exclude?"adding those ":"removing those "),
3236 (exp?"expression":"prefix"), ti->data);
3237 for (ti=ti->next; ti; ti=ti->next) {
3238 exp = (strncmp(ti->data,"^",1) == 0);
3239 printf(" or %s '%s'", (exp?"expression":"prefix"), ti->data);
3242 fprintf(STDOUT," .. ");
3243 if (verbose) fprintf(STDOUT,"\n");
3247 for (j=0; j<nentries; j++) { /* process each vldb entry */
3248 vllist = &arrayEntries.nbulkentries_val[j];
3251 for (ti=as->parms[0].items; ti; ti=ti->next) {
3252 if (strncmp(ti->data,"^",1) == 0) {
3253 ccode = (char *)re_comp(ti->data);
3255 fprintf(STDERR,"Error in -prefix regular expression: '%s': %s\n",
3259 match = (re_exec(vllist->name) == 1);
3261 match = (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0);
3269 /* Without the -exclude flag: If it matches the prefix, then
3270 * check if we want to exclude any from xprefix.
3271 * With the -exclude flag: If it matches the prefix, then
3272 * check if we want to add any from xprefix.
3274 if (match && seenxprefix) {
3275 for (ti=as->parms[4].items; ti; ti=ti->next) {
3276 if (strncmp(ti->data,"^",1) == 0) {
3277 ccode = (char *)re_comp(ti->data);
3279 fprintf(STDERR,"Error in -xprefix regular expression: '%s': %s\n",
3283 if (re_exec(vllist->name) == 1) {
3288 if (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0) {
3296 if (exclude) match = !match; /* -exclude will reverse the match */
3297 if (!match) continue; /* Skip if no match */
3299 /* Print list of volumes to backup */
3301 fprintf(STDOUT," %s\n", vllist->name);
3305 if(!(vllist->flags & RW_EXISTS)){
3307 fprintf(STDOUT,"Omitting to backup %s since RW volume does not exist \n", vllist->name);
3308 fprintf(STDOUT,"\n");
3314 avolid = vllist->volumeId[RWVOL];
3315 MapHostToNetwork(vllist);
3316 GetServerAndPart(vllist,RWVOL,&aserver1,&apart1,&previdx);
3317 if(aserver1 == -1 || apart1 == -1){
3318 fprintf(STDOUT,"could not backup %s, invalid VLDB entry\n",vllist->name);
3323 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
3325 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3331 if ((aserver && !same) || (apart && (apart != apart1))) {
3333 fprintf(STDOUT, "Omitting to backup %s since the RW is in a different location\n", vllist->name);
3338 time_t now = time(0);
3339 fprintf(STDOUT,"Creating backup volume for %s on %s",vllist->name, ctime(&now));
3343 code = UV_BackupVolume(aserver1, apart1, avolid);
3345 fprintf(STDOUT,"Could not backup %s\n",vllist->name);
3351 if (verbose) fprintf(STDOUT,"\n");
3353 } /* process each vldb entry */
3354 fprintf(STDOUT,"done\n");
3355 fprintf(STDOUT,"Total volumes backed up: %u; failed to backup: %u\n",totalBack,totalFail);
3357 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3361 static UnlockVLDB(as)
3362 register struct cmd_syndesc *as;
3365 afs_int32 aserver,code;
3367 struct VldbListByAttributes attributes;
3368 nbulkentries arrayEntries;
3369 register struct nvldbentry *vllist;
3378 attributes.Mask = 0;
3380 if(as->parms[0].items) {/* server specified */
3381 aserver = GetServer(as->parms[0].items->data);
3383 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3386 attributes.server = ntohl(aserver);
3387 attributes.Mask |= VLLIST_SERVER;
3389 if(as->parms[1].items) {/* partition specified */
3390 apart = volutil_GetPartitionID(as->parms[1].items->data);
3392 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3395 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3396 if(code) PrintError("",code);
3397 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3400 attributes.partition = apart;
3401 attributes.Mask |= VLLIST_PARTITION;
3403 attributes.flag = VLOP_ALLOPERS;
3404 attributes.Mask |= VLLIST_FLAG;
3405 bzero(&arrayEntries, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
3406 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3408 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3409 PrintError("",vcode);
3412 for(j=0;j<nentries;j++) { /* process each entry */
3413 vllist = &arrayEntries.nbulkentries_val[j];
3414 volid = vllist->volumeId[RWVOL];
3415 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid,-1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3417 fprintf(STDERR,"Could not unlock entry for volume %s\n",vllist->name);
3418 PrintError("",vcode);
3423 MapPartIdIntoName(apart,pname);
3424 if(totalE) fprintf(STDOUT,"Could not lock %u VLDB entries of %u locked entries\n",totalE,nentries);
3426 if(as->parms[0].items) {
3427 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on server %s ",as->parms[0].items->data);
3428 if(as->parms[1].items){
3429 MapPartIdIntoName(apart,pname);
3430 fprintf(STDOUT,"partition %s\n",pname);
3432 else fprintf(STDOUT,"\n");
3435 else if(as->parms[1].items){
3436 MapPartIdIntoName(apart,pname);
3437 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on partition %s on all servers\n",pname);
3441 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3445 static PartitionInfo(as)
3446 register struct cmd_syndesc *as;
3449 afs_int32 aserver,code;
3451 struct diskPartition partition;
3452 struct partList dummyPartList;
3456 aserver = GetServer(as->parms[0].items->data);
3458 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3461 if(as->parms[1].items){
3462 apart = volutil_GetPartitionID(as->parms[1].items->data);
3464 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3467 dummyPartList.partId[0] = apart;
3468 dummyPartList.partFlags[0] = PARTVALID;
3472 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3473 if(code) PrintError("",code);
3474 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3479 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
3481 PrintDiagnostics("listpart", code);
3485 for(i = 0 ; i < cnt ; i++){
3486 if(dummyPartList.partFlags[i] & PARTVALID){
3487 MapPartIdIntoName(dummyPartList.partId[i],pname);
3488 code = UV_PartitionInfo(aserver,pname,&partition);
3490 fprintf(STDERR,"Could not get information on partition %s\n",pname);
3491 PrintError("",code);
3494 fprintf(STDOUT,"Free space on partition %s: %d K blocks out of total %d\n",pname,partition.free,partition.minFree);
3500 static ChangeAddr(as)
3501 register struct cmd_syndesc *as;
3504 afs_int32 ip1, ip2, vcode;
3507 ip1 = GetServer(as->parms[0].items->data);
3509 fprintf(STDERR, "vos: invalid host address\n");
3513 if ( ( as->parms[1].items && as->parms[2].items) ||
3514 (!as->parms[1].items && !as->parms[2].items) ) {
3515 fprintf(STDERR, "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
3519 if (as->parms[1].items) {
3520 ip2 = GetServer(as->parms[1].items->data);
3522 fprintf(STDERR, "vos: invalid host address\n");
3526 /* Play a trick here. If we are removing an address, ip1 will be -1
3527 * and ip2 will be the original address. This switch prevents an
3528 * older revision vlserver from removing the IP address.
3535 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2) );
3538 fprintf(STDERR,"Could not remove server %s from the VLDB\n",
3539 as->parms[0].items->data);
3540 if (vcode == VL_NOENT) {
3541 fprintf(STDERR, "vlserver does not support the remove flag or ");
3544 fprintf(STDERR,"Could not change server %s to server %s\n",
3545 as->parms[0].items->data, as->parms[1].items->data);
3547 PrintError("",vcode);
3552 fprintf(STDOUT,"Removed server %s from the VLDB\n",
3553 as->parms[0].items->data);
3555 fprintf(STDOUT,"Changed server %s to server %s\n",
3556 as->parms[0].items->data, as->parms[1].items->data);
3561 static ListAddrs(as)
3562 register struct cmd_syndesc *as;
3567 struct VLCallBack unused;
3568 afs_int32 nentries, *addrp;
3569 bulkaddrs addrs, m_addrs;
3570 ListAddrByAttributes m_attrs;
3572 afs_int32 m_unique, m_nentries, *m_addrp;
3573 afs_int32 base, index;
3575 /* Get the list of non multihomed fileservers */
3576 addrs.bulkaddrs_val = 0;
3577 addrs.bulkaddrs_len = 0;
3578 vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0,
3579 0, 0, &unused, &nentries, &addrs);
3581 fprintf(STDERR,"vos: could not list the server addresses\n");
3582 PrintError("",vcode);
3586 /* print out the list of all the server */
3587 addrp = (afs_int32 *)addrs.bulkaddrs_val;
3588 for (i=0; i<nentries; i++, addrp++) {
3589 /* If it is a multihomed address, then we will need to
3590 * get the addresses for this multihomed server from
3591 * the vlserver and print them.
3593 if ( ((*addrp & 0xff000000) == 0xff000000) && ((*addrp)&0xffff) ) {
3594 /* Get the list of multihomed fileservers */
3595 base = (*addrp>>16) & 0xff;
3596 index = (*addrp) & 0xffff;
3598 if ( (base >= 0) && (base <= VL_MAX_ADDREXTBLKS) &&
3599 (index >= 1) && (index <= VL_MHSRV_PERBLK) ) {
3600 m_attrs.Mask = VLADDR_INDEX;
3601 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
3603 m_addrs.bulkaddrs_val = 0;
3604 m_addrs.bulkaddrs_len = 0;
3605 vcode = ubik_Call(VL_GetAddrsU, cstruct, 0,
3606 &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs);
3608 fprintf(STDERR,"vos: could not list the multi-homed server addresses\n");
3609 PrintError("",vcode);
3612 /* Print the list */
3613 m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val;
3614 for (j=0; j<m_nentries; j++, m_addrp++) {
3615 *m_addrp = htonl(*m_addrp);
3616 printf("%s ", hostutil_GetNameByINet(*m_addrp));
3619 printf("<unknown>\n");
3628 /* Otherwise, it is a non-multihomed entry and contains
3629 * the IP address of the server - print it.
3631 printf ("%s\n", hostutil_GetNameByINet(htonl(*addrp)));
3634 if (addrs.bulkaddrs_val) {
3635 free (addrs.bulkaddrs_val);
3640 static LockEntry(as)
3641 register struct cmd_syndesc *as;
3644 afs_int32 avolid,vcode, err;
3646 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3648 if (err) PrintError("", err);
3649 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
3652 vcode = ubik_Call(VL_SetLock,cstruct, 0, avolid, -1, VLOP_DELETE);
3654 fprintf(STDERR,"Could not lock VLDB entry for volume %s\n",as->parms[0].items->data);
3655 PrintError("",vcode);
3658 fprintf(STDOUT,"Locked VLDB entry for volume %s\n",as->parms[0].items->data);
3662 PrintDiagnostics(astring, acode)
3666 if (acode == EACCES) {
3667 fprintf(STDERR,"You are not authorized to perform the 'vos %s' command (%d)\n",
3671 fprintf(STDERR,"Error in vos %s command.\n", astring);
3672 PrintError("", acode);
3678 static MyBeforeProc(as, arock)
3679 struct cmd_syndesc *as;
3681 register char *tcell;
3682 register afs_int32 code;
3683 register afs_int32 sauth;
3685 /* Initialize the ubik_client connection */
3686 rx_SetRxDeadTime(90);
3687 cstruct = (struct ubik_client *)0;
3691 if (as->parms[12].items) /* if -cell specified */
3692 tcell = as->parms[12].items->data;
3693 if(as->parms[14].items) /* -serverauth specified */
3695 if (code = vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
3696 &cstruct, UV_SetSecurity)) {
3697 fprintf(STDERR,"could not initialize VLDB library (code=%u) \n",code);
3701 if(as->parms[15].items) /* -verbose flag set */
3710 /* this sucks but it works for now.
3715 #include "AFS_component_version_number.c"
3720 register afs_int32 code;
3722 register struct cmd_syndesc *ts;
3724 #ifdef AFS_AIX32_ENV
3726 * The following signal action for AIX is necessary so that in case of a
3727 * crash (i.e. core is generated) we can include the user's data section
3728 * in the core dump. Unfortunately, by default, only a partial core is
3729 * generated which, in many cases, isn't too useful.
3731 struct sigaction nsa;
3733 sigemptyset(&nsa.sa_mask);
3734 nsa.sa_handler = SIG_DFL;
3735 nsa.sa_flags = SA_FULLDUMP;
3736 sigaction(SIGSEGV, &nsa, NULL);
3739 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
3741 cmd_SetBeforeProc(MyBeforeProc, (char *) 0);
3743 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
3744 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3745 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3746 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
3747 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "initial quota (KB)");
3749 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
3753 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
3754 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3755 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
3756 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3760 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
3761 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3762 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
3763 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source");
3764 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination");
3765 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination");
3768 ts = cmd_CreateSyntax("backup", BackupVolume, 0, "make backup of a volume");
3769 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3772 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
3773 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3774 cmd_AddParm(ts, "-f", CMD_FLAG, CMD_OPTIONAL, "force a complete release");
3777 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
3778 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3779 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
3780 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
3781 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
3782 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
3785 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
3786 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3787 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3788 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
3789 cmd_AddParm(ts, "-file", CMD_SINGLE,CMD_OPTIONAL, "dump file");
3790 cmd_AddParm(ts, "-id", CMD_SINGLE,CMD_OPTIONAL, "volume ID");
3791 cmd_AddParm(ts, "-overwrite", CMD_SINGLE,CMD_OPTIONAL, "abort | full | incremental");
3794 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, "release lock on VLDB entry for a volume");
3795 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3798 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
3799 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
3800 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new site");
3801 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3804 ts = cmd_CreateSyntax("remsite", RemoveSite, 0, "remove a replication site");
3805 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3806 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3807 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3810 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
3811 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3814 ts = cmd_CreateSyntax("listvol", ListVolumes, 0, "list volumes on server (bypass VLDB)");
3815 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3816 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3817 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
3818 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
3819 "list all normal volume fields");
3820 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3821 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3822 "list extended volume fields");
3825 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, "synchronize VLDB with server");
3826 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3827 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3828 cmd_AddParm(ts, "-volume", CMD_SINGLE,CMD_OPTIONAL , "volume name or ID");
3831 ts = cmd_CreateSyntax("syncserv", SyncServer, 0, "synchronize server with VLDB");
3832 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3833 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3836 ts = cmd_CreateSyntax("examine", ExamineVolume, 0, "everything about the volume");
3837 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3838 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3839 "list extended volume fields");
3841 cmd_CreateAlias (ts, "volinfo");
3843 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *) CMD_HIDDEN);
3844 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3845 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3846 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3847 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
3848 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
3851 ts = cmd_CreateSyntax("online", volOnline, 0, (char *) CMD_HIDDEN);
3852 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3853 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3854 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3857 ts = cmd_CreateSyntax("zap", VolumeZap, 0, "delete the volume, don't bother with VLDB");
3858 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3859 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3860 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
3861 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force deletion of bad volumes");
3862 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, "also delete backup volume if one is found");
3865 ts = cmd_CreateSyntax("status", VolserStatus, 0, "report on volser status");
3866 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3869 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
3870 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
3871 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
3874 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, "list volumes in the VLDB");
3875 cmd_AddParm(ts, "-name", CMD_SINGLE,CMD_OPTIONAL, "volume name or ID");
3876 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3877 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3878 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
3879 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3880 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, "do not alphabetically sort the volume names");
3883 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
3884 cmd_AddParm(ts, "-prefix", CMD_LIST,CMD_OPTIONAL, "common prefix on volume(s)");
3885 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3886 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3887 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, "exclude common prefix volumes");
3888 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, "negative prefix on volume(s)");
3889 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
3892 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, "delete VLDB entry for a volume");
3893 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
3894 cmd_AddParm(ts, "-prefix", CMD_SINGLE,CMD_OPTIONAL, "prefix of the volume whose VLDB entry is to be deleted");
3895 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3896 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3897 cmd_AddParm(ts, "-noexecute", CMD_FLAG,CMD_OPTIONAL|CMD_HIDE, "no execute");
3900 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, "list partition information");
3901 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3902 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3905 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, "unlock all the locked entries in the VLDB");
3906 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3907 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3910 ts = cmd_CreateSyntax("lock", LockEntry, 0, "lock VLDB entry for a volume");
3911 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3914 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, "change the IP address of a file server");
3915 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
3916 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
3917 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, "remove the IP address from the VLDB");
3920 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB");
3923 code = cmd_Dispatch(argc, argv);
3925 /* Shut down the ubik_client and rx connections */
3927 ubik_ClientDestroy (cstruct);