2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
11 #include <sys/types.h>
20 #include <netinet/in.h>
24 #include <sys/statfs.h>
31 #include <rx/rx_globals.h>
33 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
37 #include <afs/afsutil.h>
39 #include <afs/afsint.h>
61 #define COMMONPARMS cmd_Seek(ts, 12);\
62 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
63 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
64 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
65 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
67 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
71 struct rx_connection *tconn;
73 extern struct ubik_client *cstruct;
75 extern struct rx_connection *UV_Bind();
76 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
77 extern int UV_SetSecurity();
79 extern VL_ReleaseLock();
80 extern VL_DeleteEntry();
81 extern VL_ListEntry();
83 extern VL_GetAddrsU();
84 extern VL_ChangeAddr();
86 extern int vsu_ExtractName();
88 extern int MapPartIdIntoName();
89 extern int MapHostToNetwork();
90 extern int MapNetworkToHost();
91 extern void EnumerateEntry();
92 extern void SubEnumerateEntry();
95 static struct tqHead busyHead, notokHead;
97 static void qInit(ahead)
100 bzero((char *)ahead, sizeof(struct tqHead));
105 static void qPut(ahead,volid)
106 struct tqHead *ahead;
111 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
112 elem->next = ahead->next;
119 static void qGet(ahead,volid)
120 struct tqHead *ahead;
125 if(ahead->count <= 0) return;
126 *volid = ahead->next->volid;
128 ahead->next = tmp->next;
134 /* returns 1 if <filename> exists else 0 */
135 static FileExists(filename)
142 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
146 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
154 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
155 static VolNameOK(name)
161 total = strlen(name);
162 if(!strcmp(&name[total - 9],".readonly")) {
165 else if(!strcmp(&name[total - 7 ],".backup")) {
173 /* return 1 if name is a number else 0 */
174 static IsNumeric(name)
183 for(i = 0; i < len ; i++){
184 if(*ptr < '0' || *ptr > '9'){
198 * Parse a server name/address and return the address in HOST BYTE order
200 afs_int32 GetServer(aname)
202 register struct hostent *th;
205 register afs_int32 code;
206 char hostname[MAXHOSTCHARS];
208 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
210 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
211 addr = ntohl(addr); /* convert to host order */
213 th = gethostbyname(aname);
215 bcopy(th->h_addr, &addr, sizeof(addr));
218 if (addr == htonl(0x7f000001)) { /* local host */
219 code = gethostname(hostname, MAXHOSTCHARS);
221 th = gethostbyname(hostname); /* returns host byte order */
223 bcopy(th->h_addr, &addr, sizeof(addr));
229 afs_int32 GetVolumeType(aname)
233 if(!strcmp(aname,"ro"))
235 else if(!strcmp(aname, "rw"))
237 else if(!strcmp(aname,"bk"))
242 int IsPartValid(partId, server, code)
243 afs_int32 server, partId,*code;
246 struct partList dummyPartList;
254 *code = UV_ListPartitions(server,&dummyPartList, &cnt);
255 if(*code) return success;
256 for(i = 0 ; i < cnt ; i++) {
257 if(dummyPartList.partFlags[i] & PARTVALID)
258 if(dummyPartList.partId[i] == partId)
266 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
267 * associated with <call> */
268 SendFile(ufd, call, blksize)
270 register struct rx_call *call;
273 char *buffer = (char*) 0;
278 buffer = (char *)malloc(blksize);
280 fprintf(STDERR,"malloc failed\n");
284 while (!error && !done) {
285 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
288 FD_SET((int)(ufd->handle), &in);
289 /* don't timeout if read blocks */
290 IOMGR_Select(((int)(ufd->handle))+1, &in, 0, 0, 0);
292 error = USD_READ(ufd, buffer, blksize, &nbytes);
294 fprintf(STDERR, "File system read failed\n");
301 if (rx_Write(call, buffer, nbytes) != nbytes){
306 if (buffer) free(buffer);
310 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
311 * writes it out to the volume. */
312 afs_int32 WriteData(call,rock)
313 struct rx_call *call;
319 afs_int32 error,code;
325 if(!filename || !*filename) {
326 usd_StandardInput(&ufd);
330 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
333 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
336 fprintf(STDERR,"Could not access file '%s'\n", filename);
341 code = SendFile(ufd,call,blksize);
348 code = USD_CLOSE(ufd);
350 fprintf(STDERR,"Could not close dump file %s\n",
351 (filename && *filename)?filename:"STDOUT");
352 if(!error) error = code;
358 /* Receive data from <call> stream into file associated
359 * with <fd> <blksize>
361 int ReceiveFile(ufd, call, blksize)
363 struct rx_call *call;
366 char *buffer = (char *) 0;
368 afs_uint32 bytesleft, w;
371 buffer = (char *)malloc(blksize);
373 fprintf(STDERR,"memory allocation failed\n");
377 while ((bytesread=rx_Read(call,buffer,blksize)) > 0) {
378 for (bytesleft=bytesread; bytesleft; bytesleft-=w) {
379 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
382 FD_SET((int)(ufd->handle), &out);
383 /* don't timeout if write blocks */
384 IOMGR_Select(((int)(ufd->handle))+1, 0, &out, 0, 0);
386 error = USD_WRITE(ufd, &buffer[bytesread-bytesleft], bytesleft, &w);
388 fprintf(STDERR,"File system write failed\n");
395 if (buffer) free(buffer);
399 afs_int32 DumpFunction(call, filename)
400 struct rx_call *call;
403 usd_handle_t ufd; /* default is to stdout */
404 afs_int32 error=0, code;
409 /* Open the output file */
410 if (!filename || !*filename) {
411 usd_StandardOutput(&ufd);
415 code = usd_Open(filename, USD_OPEN_CREATE|USD_OPEN_RDWR, 0666, &ufd);
419 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
422 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
425 fprintf(STDERR, "Could not create file '%s'\n", filename);
426 ERROR_EXIT(VOLSERBADOP);
430 code = ReceiveFile(ufd, call, blksize);
431 if (code) ERROR_EXIT(code);
434 /* Close the output file */
436 code = USD_CLOSE(ufd);
438 fprintf(STDERR,"Could not close dump file %s\n",
439 (filename && *filename)?filename:"STDIN");
440 if (!error) error = code;
447 static void DisplayFormat(pntr,server,part,totalOK,totalNotOK,totalBusy,fast,longlist,disp)
449 afs_int32 server,part;
450 int *totalOK,*totalNotOK,*totalBusy;
451 int fast,longlist, disp;
456 fprintf(STDOUT,"%-10u\n",pntr->volid);
459 if(pntr->status == VOK){
460 fprintf(STDOUT,"%-32s ",pntr->name);
461 fprintf(STDOUT,"%10u ",pntr->volid);
462 if(pntr->type == 0) fprintf(STDOUT,"RW ");
463 if(pntr->type == 1) fprintf(STDOUT,"RO ");
464 if(pntr->type == 2) fprintf(STDOUT,"BK ");
465 fprintf(STDOUT,"%10d K ",pntr->size);
466 if(pntr->inUse == 1) {
467 fprintf(STDOUT,"On-line");
470 fprintf(STDOUT,"Off-line");
473 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
474 fprintf(STDOUT,"\n");
475 MapPartIdIntoName(part,pname);
476 fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname);
477 fprintf(STDOUT," RWrite %10u ROnly %10u Backup %10u \n", pntr->parentID,pntr->cloneID, pntr->backupID);
478 fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota);
479 fprintf(STDOUT," Creation %s",
480 ctime((time_t *)&pntr->creationDate));
481 if(pntr->updateDate < pntr->creationDate)
482 fprintf(STDOUT," Last Update %s",
483 ctime((time_t *)&pntr->creationDate));
485 fprintf(STDOUT," Last Update %s",
486 ctime((time_t *)&pntr->updateDate));
487 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
490 else if (pntr->status == VBUSY) {
492 qPut(&busyHead,pntr->volid);
493 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
497 qPut(¬okHead,pntr->volid);
498 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
500 fprintf(STDOUT,"\n");
502 else {/* default listing */
503 if(pntr->status == VOK){
504 fprintf(STDOUT,"%-32s ",pntr->name);
505 fprintf(STDOUT,"%10u ",pntr->volid);
506 if(pntr->type == 0) fprintf(STDOUT,"RW ");
507 if(pntr->type == 1) fprintf(STDOUT,"RO ");
508 if(pntr->type == 2) fprintf(STDOUT,"BK ");
509 fprintf(STDOUT,"%10d K ",pntr->size);
510 if(pntr->inUse == 1) {
511 fprintf(STDOUT,"On-line");
514 fprintf(STDOUT,"Off-line");
517 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
518 fprintf(STDOUT,"\n");
520 else if (pntr->status == VBUSY) {
522 qPut(&busyHead,pntr->volid);
523 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
527 qPut(¬okHead,pntr->volid);
528 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
533 /*------------------------------------------------------------------------
534 * PRIVATE XDisplayFormat
537 * Display the contents of one extended volume info structure.
540 * a_xInfoP : Ptr to extended volume info struct to print.
541 * a_servID : Server ID to print.
542 * a_partID : Partition ID to print.
543 * a_totalOKP : Ptr to total-OK counter.
544 * a_totalNotOKP : Ptr to total-screwed counter.
545 * a_totalBusyP : Ptr to total-busy counter.
546 * a_fast : Fast listing?
547 * a_int32 : Int32 listing?
548 * a_showProblems : Show volume problems?
554 * Nothing interesting.
558 *------------------------------------------------------------------------*/
560 static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP,
561 a_totalNotOKP, a_totalBusyP, a_fast, a_int32,
563 volintXInfo *a_xInfoP;
581 fprintf(STDOUT, "%-10u\n", a_xInfoP->volid);
586 * Fully-detailed listing.
588 if (a_xInfoP->status == VOK) {
590 * Volume's status is OK - all the fields are valid.
592 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
593 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
594 if (a_xInfoP->type == 0) fprintf(STDOUT,"RW ");
595 if (a_xInfoP->type == 1) fprintf(STDOUT,"RO ");
596 if (a_xInfoP->type == 2) fprintf(STDOUT,"BK ");
597 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
598 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
599 if(a_xInfoP->inUse == 1) {
600 fprintf(STDOUT, "On-line");
604 fprintf(STDOUT, "Off-line");
607 fprintf(STDOUT, "\n");
608 MapPartIdIntoName(a_partID, pname);
609 fprintf(STDOUT, " %s %s \n",
610 hostutil_GetNameByINet(a_servID),
612 fprintf(STDOUT, " RWrite %10u ROnly %10u Backup %10u \n",
613 a_xInfoP->parentID, a_xInfoP->cloneID, a_xInfoP->backupID);
614 fprintf(STDOUT, " MaxQuota %10d K \n",
616 fprintf(STDOUT, " Creation %s",
617 ctime((time_t *)&a_xInfoP->creationDate));
618 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
619 fprintf(STDOUT, " Last Update %s",
620 ctime((time_t *)&a_xInfoP->creationDate));
622 fprintf(STDOUT, " Last Update %s",
623 ctime((time_t *)&a_xInfoP->updateDate));
624 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
628 * Print all the read/write and authorship stats.
631 "\n Raw Read/Write Stats\n");
633 " |-------------------------------------------|\n");
635 " | Same Network | Diff Network |\n");
637 " |----------|----------|----------|----------|\n");
639 " | Total | Auth | Total | Auth |\n");
641 " |----------|----------|----------|----------|\n");
643 "Reads | %8d | %8d | %8d | %8d |\n",
644 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
645 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
646 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
647 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
649 "Writes | %8d | %8d | %8d | %8d |\n",
650 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
651 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
652 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
653 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
655 " |-------------------------------------------|\n\n");
658 " Writes Affecting Authorship\n");
660 " |-------------------------------------------|\n");
662 " | File Authorship | Directory Authorship|\n");
664 " |----------|----------|----------|----------|\n");
666 " | Same | Diff | Same | Diff |\n");
668 " |----------|----------|----------|----------|\n");
670 "0-60 sec | %8d | %8d | %8d | %8d |\n",
671 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
672 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
673 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
674 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
676 "1-10 min | %8d | %8d | %8d | %8d |\n",
677 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
678 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
679 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
680 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
682 "10min-1hr | %8d | %8d | %8d | %8d |\n",
683 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
684 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
685 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
686 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
688 "1hr-1day | %8d | %8d | %8d | %8d |\n",
689 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
690 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
691 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
692 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
694 "1day-1wk | %8d | %8d | %8d | %8d |\n",
695 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
696 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
697 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
698 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
700 "> 1wk | %8d | %8d | %8d | %8d |\n",
701 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
702 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
703 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
704 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
706 " |-------------------------------------------|\n");
707 } /*Volume status OK*/
709 if (a_xInfoP->status == VBUSY) {
711 qPut(&busyHead, a_xInfoP->volid);
713 fprintf(STDOUT, "**** Volume %u is busy ****\n",
718 qPut(¬okHead, a_xInfoP->volid);
720 fprintf(STDOUT, "**** Could not attach volume %u ****\n",
723 fprintf(STDOUT,"\n");
729 if (a_xInfoP->status == VOK) {
730 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
731 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
732 if (a_xInfoP->type == 0) fprintf(STDOUT, "RW ");
733 if (a_xInfoP->type == 1) fprintf(STDOUT, "RO ");
734 if (a_xInfoP->type == 2) fprintf(STDOUT, "BK ");
735 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
736 if(a_xInfoP->inUse == 1) {
737 fprintf(STDOUT, "On-line");
740 fprintf(STDOUT, "Off-line");
743 fprintf(STDOUT, "\n");
746 if (a_xInfoP->status == VBUSY) {
748 qPut(&busyHead, a_xInfoP->volid);
750 fprintf(STDOUT,"**** Volume %u is busy ****\n",
755 qPut(¬okHead, a_xInfoP->volid);
757 fprintf(STDOUT,"**** Could not attach volume %u ****\n",
760 } /*Default listing*/
763 static void DisplayVolumes(server,part,pntr,count,longlist,fast,quiet)
764 afs_int32 server,part;
766 afs_int32 count,longlist,fast;
769 int totalOK,totalNotOK,totalBusy, i;
777 for(i = 0; i < count; i++){
778 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,fast,longlist,0);
782 while(busyHead.count){
783 qGet(&busyHead,&volid);
784 fprintf(STDOUT,"**** Volume %u is busy ****\n",volid);
788 while(notokHead.count){
789 qGet(¬okHead,&volid);
790 fprintf(STDOUT,"**** Could not attach volume %u ****\n",volid);
794 fprintf(STDOUT,"\n");
796 fprintf(STDOUT,"Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",totalOK,totalNotOK,totalBusy);
801 /*------------------------------------------------------------------------
802 * PRIVATE XDisplayVolumes
805 * Display extended volume information.
808 * a_servID : Pointer to the Rx call we're performing.
809 * a_partID : Partition for which we want the extended list.
810 * a_xInfoP : Ptr to extended volume info.
811 * a_count : Number of volume records contained above.
812 * a_int32 : Int32 listing generated?
813 * a_fast : Fast listing generated?
814 * a_quiet : Quiet listing generated?
820 * Nothing interesting.
824 *------------------------------------------------------------------------*/
826 static void XDisplayVolumes(a_servID, a_partID, a_xInfoP,
827 a_count, a_int32, a_fast, a_quiet)
830 volintXInfo *a_xInfoP;
836 { /*XDisplayVolumes*/
838 int totalOK; /*Total OK volumes*/
839 int totalNotOK; /*Total screwed volumes*/
840 int totalBusy; /*Total busy volumes*/
841 int i; /*Loop variable*/
842 afs_int32 volid; /*Current volume ID*/
845 * Initialize counters and (global!!) queues.
854 * Display each volume in the list.
856 for(i = 0; i < a_count; i++) {
857 XDisplayFormat(a_xInfoP,
870 * If any volumes were found to be busy or screwed, display them.
873 while (busyHead.count) {
874 qGet(&busyHead, &volid);
875 fprintf(STDOUT, "**** Volume %u is busy ****\n", volid);
879 while (notokHead.count) {
880 qGet(¬okHead, &volid);
881 fprintf(STDOUT, "**** Could not attach volume %u ****\n", volid);
886 fprintf(STDOUT, "\n");
889 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
890 totalOK, totalNotOK, totalBusy);
894 } /*XDisplayVolumes*/
896 /* set <server> and <part> to the correct values depending on
897 * <voltype> and <entry> */
898 static void GetServerAndPart (entry, voltype, server, part, previdx)
899 struct nvldbentry *entry;
900 afs_int32 *server,*part;
904 int i, istart, vtype;
909 /* Doesn't check for non-existance of backup volume */
910 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
912 istart = 0; /* seach the entire entry */
915 /* Seach from beginning of entry or pick up where we left off */
916 istart = ((*previdx < 0) ? 0 : *previdx+1);
919 for (i = istart; i < entry->nServers; i++) {
920 if (entry->serverFlags[i] & vtype) {
921 *server = entry->serverNumber[i];
922 *part = entry->serverPartition[i];
928 /* Didn't find any, return -1 */
933 static void PostVolumeStats(entry)
934 struct nvldbentry *entry;
936 SubEnumerateEntry(entry);
937 /* Check for VLOP_ALLOPERS */
938 if (entry->flags & VLOP_ALLOPERS)
939 fprintf(STDOUT," Volume is currently LOCKED \n");
943 /*------------------------------------------------------------------------
944 * PRIVATE XVolumeStats
947 * Display extended volume information.
950 * a_xInfoP : Ptr to extended volume info.
951 * a_entryP : Ptr to the volume's VLDB entry.
952 * a_srvID : Server ID.
953 * a_partID : Partition ID.
954 * a_volType : Type of volume to print.
960 * Nothing interesting.
964 *------------------------------------------------------------------------*/
966 static void XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
967 volintXInfo *a_xInfoP;
968 struct nvldbentry *a_entryP;
975 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here*/
977 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info*/
978 a_srvID, /*Server ID to print*/
979 a_partID, /*Partition ID to print*/
980 &totalOK, /*Ptr to total-OK counter*/
981 &totalNotOK, /*Ptr to total-screwed counter*/
982 &totalBusy, /*Ptr to total-busy counter*/
983 0, /*Don't do a fast listing*/
984 1, /*Do a long listing*/
985 1); /*Show volume problems*/
990 static void VolumeStats(pntr,entry,server,part,voltype)
992 struct nvldbentry *entry;
994 afs_int32 server,part;
996 int totalOK,totalNotOK,totalBusy;
997 afs_int32 vcode,vcode2;
999 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,0,1,1);
1003 /* command to forcibly remove a volume */
1004 static NukeVolume(as)
1005 register struct cmd_syndesc *as; {
1006 register afs_int32 code;
1007 afs_int32 volID, err;
1012 server = GetServer(tp = as->parms[0].items->data);
1014 fprintf(STDERR,"vos: server '%s' not found in host table\n", tp);
1018 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1020 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1024 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1026 if (err) PrintError("", err);
1027 else fprintf(STDERR, "vos: could not parse '%s' as a numeric volume ID", tp);
1031 fprintf(STDOUT, "vos: forcibly removing all traces of volume %d, please wait...", volID);
1033 code = UV_NukeVolume(server, partID, volID);
1035 fprintf(STDOUT, "done.\n");
1037 fprintf(STDOUT, "failed with code %d.\n", code);
1042 /*------------------------------------------------------------------------
1043 * PRIVATE ExamineVolume
1046 * Routine used to examine a single volume, contacting the VLDB as
1047 * well as the Volume Server.
1050 * as : Ptr to parsed command line arguments.
1053 * 0 for a successful operation,
1054 * Otherwise, one of the ubik or VolServer error values.
1057 * Nothing interesting.
1061 *------------------------------------------------------------------------
1063 static ExamineVolume(as)
1064 register struct cmd_syndesc *as;
1066 struct nvldbentry entry;
1067 afs_int32 vcode = 0;
1068 volintInfo *pntr = (volintInfo *)0;
1069 volintXInfo *xInfoP = (volintXInfo *)0;
1071 afs_int32 code, err, error = 0;
1072 int voltype, foundserv = 0, foundentry = 0;
1073 afs_int32 aserver, apart;
1075 int wantExtendedInfo; /*Do we want extended vol info?*/
1077 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1079 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1081 if (err) PrintError("", err);
1082 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1087 fprintf(STDOUT, "Fetching VLDB entry for %u .. ", volid);
1090 vcode = VLDB_GetEntryByID (volid, -1, &entry);
1092 fprintf(STDERR, "Could not fetch the entry for volume number %u from VLDB \n",volid);
1096 fprintf(STDOUT, "done\n");
1097 MapHostToNetwork(&entry);
1099 if (entry.volumeId[RWVOL] == volid)
1101 else if (entry.volumeId[BACKVOL] == volid)
1103 else /* (entry.volumeId[ROVOL] == volid) */
1106 do { /* do {...} while (voltype == ROVOL) */
1107 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1108 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1109 * If its a RO vol, get the next RO entry.
1111 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart, &previdx);
1112 if (previdx == -1) { /* searched all entries */
1114 fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data);
1121 /* Get information about the volume from the server */
1123 fprintf(STDOUT,"Getting volume listing from the server %s .. ",
1124 hostutil_GetNameByINet(aserver));
1127 if (wantExtendedInfo)
1128 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1130 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1132 fprintf(STDOUT,"done\n");
1136 if (code == ENODEV) {
1137 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1138 /* The VLDB says there is no backup volume and its not on disk */
1139 fprintf(STDERR, "Volume %s does not exist\n", as->parms[0].items->data);
1142 fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n",
1143 hostutil_GetNameByINet(aserver));
1146 PrintDiagnostics("examine", code);
1148 fprintf(STDOUT, "\n");
1151 if (wantExtendedInfo)
1152 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1154 VolumeStats(pntr, &entry, aserver, apart, voltype);
1156 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1157 /* The VLDB says there is no backup volume yet we found one on disk */
1158 fprintf(STDERR, "Volume %s does not exist in VLDB\n", as->parms[0].items->data);
1163 if (pntr) free(pntr);
1164 if (xInfoP) free(xInfoP);
1165 } while (voltype == ROVOL);
1168 fprintf(STDERR,"Dump only information from VLDB\n\n");
1169 fprintf(STDOUT,"%s \n", entry.name); /* PostVolumeStats doesn't print name */
1171 PostVolumeStats(&entry);
1176 /*------------------------------------------------------------------------
1180 * Brings a volume online.
1183 * as : Ptr to parsed command line arguments.
1186 * 0 for a successful operation,
1189 * Nothing interesting.
1193 *------------------------------------------------------------------------
1195 static volOnline(as)
1196 register struct cmd_syndesc *as;
1198 afs_int32 server, partition, volid;
1199 afs_int32 code, err=0;
1201 server = GetServer(as->parms[0].items->data);
1203 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1207 partition = volutil_GetPartitionID(as->parms[1].items->data);
1208 if (partition < 0) {
1209 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1213 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1215 if (err) PrintError("", err);
1216 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1220 code = UV_SetVolume(server, partition, volid, ITOffline, 0/*online*/, 0/*sleep*/);
1222 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1229 /*------------------------------------------------------------------------
1230 * PRIVATE volOffline
1233 * Brings a volume offline.
1236 * as : Ptr to parsed command line arguments.
1239 * 0 for a successful operation,
1242 * Nothing interesting.
1246 *------------------------------------------------------------------------
1248 static volOffline(as)
1249 register struct cmd_syndesc *as;
1251 afs_int32 server, partition, volid;
1252 afs_int32 code, err=0;
1253 afs_int32 transflag, sleeptime, transdone;
1255 server = GetServer(as->parms[0].items->data);
1257 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1261 partition = volutil_GetPartitionID(as->parms[1].items->data);
1262 if (partition < 0) {
1263 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1267 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1269 if (err) PrintError("", err);
1270 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1274 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1275 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1276 transdone = (sleeptime ? 0/*online*/ : VTOutOfService);
1277 if (as->parms[4].items && !as->parms[3].items) {
1278 fprintf(STDERR,"-sleep option must be used with -busy flag\n");
1282 code = UV_SetVolume(server, partition, volid, transflag, transdone, sleeptime);
1284 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1291 static CreateVolume(as)
1292 register struct cmd_syndesc *as;
1296 afs_int32 volid,code;
1297 struct nvldbentry entry;
1302 tserver = GetServer(as->parms[0].items->data);
1304 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
1307 pname = volutil_GetPartitionID(as->parms[1].items->data);
1309 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1312 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
1313 if(code) PrintError("",code);
1314 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1317 if(!ISNAMEVALID(as->parms[2].items->data)) {
1318 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);
1321 if(!VolNameOK(as->parms[2].items->data)){
1322 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[2].items->data);
1325 if(IsNumeric(as->parms[2].items->data)){
1326 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[2].items->data);
1329 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1331 fprintf(STDERR,"Volume %s already exists\n",as->parms[2].items->data);
1332 PrintDiagnostics("create", code);
1336 if (as->parms[3].items) {
1337 if (!IsNumeric(as->parms[3].items->data)){
1338 fprintf(STDERR,"Initial quota %s should be numeric.\n", as->parms[3].items->data);
1342 code = util_GetInt32(as->parms[3].items->data, "a);
1344 fprintf(STDERR,"vos: bad integer specified for quota.\n");
1349 code = UV_CreateVolume2(tserver, pname,as->parms[2].items->data,
1350 quota, 0, 0, 0, 0, &volid);
1352 PrintDiagnostics("create", code);
1355 MapPartIdIntoName(pname, part);
1356 fprintf(STDOUT,"Volume %u created on partition %s of %s\n", volid, part,as->parms[0].items->data );
1361 static afs_int32 DeleteAll(entry)
1362 struct nvldbentry *entry;
1365 afs_int32 error, code, curserver, curpart, volid;
1367 MapHostToNetwork(entry);
1369 for(i=0; i < entry->nServers; i++){
1370 curserver = entry->serverNumber[i];
1371 curpart = entry->serverPartition[i];
1372 if(entry->serverFlags[i] & ITSROVOL){
1373 volid = entry->volumeId[ROVOL];
1376 volid = entry->volumeId[RWVOL];
1378 code = UV_DeleteVolume(curserver,curpart,volid);
1385 static DeleteVolume(as)
1386 struct cmd_syndesc *as;
1388 afs_int32 err, code = 0;
1389 afs_int32 server = 0, partition = -1, volid;
1393 if (as->parms[0].items) {
1394 server = GetServer(as->parms[0].items->data);
1396 fprintf(STDERR,"vos: server '%s' not found in host table\n",
1397 as->parms[0].items->data);
1402 if (as->parms[1].items) {
1403 partition = volutil_GetPartitionID(as->parms[1].items->data);
1404 if (partition < 0) {
1405 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
1406 as->parms[1].items->data );
1410 /* Check for validity of the partition */
1411 if (!IsPartValid(partition, server, &code)) {
1413 PrintError("", code);
1415 fprintf(STDERR,"vos : partition %s does not exist on the server\n",
1416 as->parms[1].items->data);
1422 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1424 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1425 as->parms[2].items->data);
1426 if (err) PrintError("", err);
1430 /* If the server or partition option are not complete, try to fill
1431 * them in from the VLDB entry.
1433 if ((partition == -1) || !server) {
1434 struct nvldbentry entry;
1436 code = VLDB_GetEntryByID(volid, -1, &entry);
1438 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB\n",
1440 PrintError("",code);
1444 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) ||
1445 ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS)) ) {
1446 idx = Lp_GetRwIndex(&entry);
1448 (server && (server != entry.serverNumber[idx])) ||
1449 ((partition != -1) && (partition != entry.serverPartition[idx])) ) {
1450 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1454 else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
1455 for (idx=-1,j=0; j<entry.nServers; j++) {
1456 if (entry.serverFlags[j] != ITSROVOL) continue;
1458 if ( ((server == 0) || (server == entry.serverNumber[j])) &&
1459 ((partition == -1) || (partition == entry.serverPartition[j])) ) {
1461 fprintf(STDERR,"VLDB: Volume '%s' matches more than one RO\n",
1462 as->parms[2].items->data);
1469 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1474 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1478 server = htonl(entry.serverNumber[idx]);
1479 partition = entry.serverPartition[idx];
1483 code = UV_DeleteVolume(server, partition, volid);
1485 PrintDiagnostics("remove", code);
1489 MapPartIdIntoName(partition, pname);
1490 fprintf(STDOUT,"Volume %u on partition %s server %s deleted\n",
1491 volid, pname, hostutil_GetNameByINet(server));
1495 #define TESTM 0 /* set for move space tests, clear for production */
1496 static MoveVolume(as)
1497 register struct cmd_syndesc *as;
1500 afs_int32 volid, fromserver, toserver, frompart, topart,code, err;
1501 char fromPartName[10], toPartName[10];
1503 struct diskPartition partition; /* for space check */
1506 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1508 if (err) PrintError("", err);
1509 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1510 as->parms[0].items->data);
1513 fromserver = GetServer(as->parms[1].items->data);
1514 if (fromserver == 0) {
1515 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data);
1518 toserver = GetServer(as->parms[3].items->data);
1519 if (toserver == 0) {
1520 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data);
1523 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1525 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
1528 if (!IsPartValid(frompart,fromserver,&code)){/*check for validity of the partition */
1529 if(code) PrintError("",code);
1530 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data);
1533 topart = volutil_GetPartitionID(as->parms[4].items->data);
1535 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data);
1538 if (!IsPartValid(topart,toserver,&code)){/*check for validity of the partition */
1539 if(code) PrintError("",code);
1540 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data);
1545 check source partition for space to clone volume
1548 MapPartIdIntoName(topart,toPartName);
1549 MapPartIdIntoName(frompart, fromPartName);
1552 check target partition for space to move volume
1555 code=UV_PartitionInfo(toserver,toPartName,&partition);
1558 fprintf(STDERR,"vos: cannot access partition %s\n",toPartName);
1562 fprintf(STDOUT,"target partition %s free space %d\n",
1563 toPartName,partition.free);
1566 code=UV_ListOneVolume(fromserver,frompart,volid,&p);
1569 fprintf(STDERR,"vos:cannot access volume %u\n",volid);
1574 fprintf(STDOUT,"volume %u size %d\n",volid,p->size);
1575 if(partition.free<=p->size)
1577 fprintf(STDERR,"vos: no space on target partition %s to move volume %u\n",
1586 fprintf(STDOUT,"size test - don't do move\n");
1590 /* successful move still not guaranteed but shoot for it */
1592 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1594 PrintDiagnostics("move", code);
1597 MapPartIdIntoName(topart,toPartName);
1598 MapPartIdIntoName(frompart, fromPartName);
1599 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);
1603 static BackupVolume(as)
1604 register struct cmd_syndesc *as;
1606 afs_int32 avolid, aserver, apart,vtype,code, err;
1607 struct nvldbentry entry;
1609 afs_int32 buvolid,buserver,bupart,butype;
1610 struct nvldbentry buentry;
1611 struct rx_connection *conn;
1613 struct nvldbentry store;
1615 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1617 if (err) PrintError("", err);
1618 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1619 as->parms[0].items->data);
1622 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1625 /* verify this is a readwrite volume */
1629 fprintf(STDERR,"%s not RW volume\n",as->parms[0].items->data);
1633 /* is there a backup volume already? */
1635 if(entry.flags & BACK_EXISTS)
1637 /* yep, where is it? */
1639 buvolid=entry.volumeId[BACKVOL];
1640 code=GetVolumeInfo(buvolid,&buserver,&bupart,&butype,&buentry);
1644 code = VLDB_IsSameAddrs(buserver, aserver, &err);
1646 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver; aborting call!\n", buserver);
1651 fprintf(STDERR,"FATAL ERROR: backup volume %u exists on server %u\n",
1657 /* nope, carry on */
1659 code = UV_BackupVolume(aserver, apart, avolid);
1662 PrintDiagnostics("backup", code);
1665 fprintf(STDOUT,"Created backup volume for %s \n",as->parms[0].items->data);
1668 static ReleaseVolume(as)
1669 register struct cmd_syndesc *as;
1672 struct nvldbentry entry;
1673 afs_int32 avolid, aserver, apart,vtype,code, err;
1676 if(as->parms[1].items) force = 1;
1677 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1679 if (err) PrintError("", err);
1680 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1683 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1684 if(code) return code;
1686 if (vtype != RWVOL) {
1687 fprintf(STDERR,"%s not a RW volume\n", as->parms[0].items->data);
1691 if(!ISNAMEVALID(entry.name)){
1692 fprintf(STDERR,"Volume name %s is too long, rename before releasing\n",entry.name);
1696 code = UV_ReleaseVolume(avolid, aserver, apart, force);
1698 PrintDiagnostics("release", code);
1701 fprintf(STDOUT,"Released volume %s successfully\n",as->parms[0].items->data );
1704 static DumpVolume(as)
1705 register struct cmd_syndesc *as;
1708 afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i;
1709 char filename[NameLen];
1710 struct nvldbentry entry;
1712 rx_SetRxDeadTime(60 * 10);
1713 for (i = 0; i<MAXSERVERS; i++) {
1714 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct,i);
1715 if (rxConn == 0) break;
1716 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
1717 if (rxConn->service) rxConn->service->connDeadTime = rx_connDeadTime;
1720 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1722 if (err) PrintError("", err);
1723 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1727 if (as->parms[3].items || as->parms[4].items) {
1728 if (!as->parms[3].items || !as->parms[4].items) {
1729 fprintf(STDERR, "Must specify both -server and -partition options\n");
1732 aserver = GetServer(as->parms[3].items->data);
1734 fprintf(STDERR, "Invalid server name\n");
1737 apart = volutil_GetPartitionID(as->parms[4].items->data);
1739 fprintf(STDERR, "Invalid partition name\n");
1743 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
1744 if (code) return code;
1747 if (as->parms[1].items && strcmp(as->parms[1].items->data,"0")) {
1748 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
1750 fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n",
1751 as->parms[1].items->data, code);
1755 if(as->parms[2].items){
1756 strcpy(filename,as->parms[2].items->data);
1759 strcpy(filename,"");
1761 code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
1763 PrintDiagnostics("dump", code);
1766 if(strcmp(filename,""))
1767 fprintf(STDERR,"Dumped volume %s in file %s\n",as->parms[0].items->data, filename);
1769 fprintf(STDERR,"Dumped volume %s in stdout \n",as->parms[0].items->data);
1778 static RestoreVolume(as)
1779 register struct cmd_syndesc *as;
1782 afs_int32 avolid, aserver, apart, code,vcode, err;
1783 afs_int32 aoverwrite = ASK;
1786 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1],apartName[10];
1787 char volname[VOLSER_MAXVOLNAME +1];
1788 struct nvldbentry entry;
1792 if(as->parms[4].items){
1793 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
1795 if (err) PrintError("", err);
1796 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[4].items->data);
1803 if (as->parms[5].items) {
1804 if ( (strcmp(as->parms[5].items->data, "a") == 0) ||
1805 (strcmp(as->parms[5].items->data, "abort") == 0) ) {
1808 else if ( (strcmp(as->parms[5].items->data, "f") == 0) ||
1809 (strcmp(as->parms[5].items->data, "full") == 0) ) {
1812 else if ( (strcmp(as->parms[5].items->data, "i") == 0) ||
1813 (strcmp(as->parms[5].items->data, "inc") == 0) ||
1814 (strcmp(as->parms[5].items->data, "increment") == 0) ||
1815 (strcmp(as->parms[5].items->data, "incremental") == 0) ) {
1819 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
1820 as->parms[5].items->data);
1825 aserver = GetServer(as->parms[0].items->data);
1827 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1830 apart = volutil_GetPartitionID(as->parms[1].items->data);
1832 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1835 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
1836 if(code) PrintError("",code);
1837 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1840 strcpy(avolname,as->parms[2].items->data );
1841 if(!ISNAMEVALID(avolname)) {
1842 fprintf(STDERR,"vos: the name of the volume %s exceeds the size limit\n",avolname);
1845 if(!VolNameOK(avolname)){
1846 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",avolname);
1849 if(as->parms[3].items){
1850 strcpy(afilename,as->parms[3].items->data );
1851 if(!FileExists(afilename)){
1852 fprintf(STDERR,"Can't access file %s\n",afilename);
1857 strcpy(afilename,"");
1860 /* Check if volume exists or not */
1862 vsu_ExtractName(volname,avolname);
1863 vcode = VLDB_GetEntryByName(volname, &entry);
1864 if (vcode) { /* no volume - do a full restore */
1865 restoreflags = RV_FULLRST;
1866 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1867 fprintf(STDERR,"Volume does not exist; Will perform a full restore\n");
1870 else if (Lp_GetRwIndex(&entry) == -1) { /* RW volume does not exist - do a full */
1871 restoreflags = RV_FULLRST;
1872 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1873 fprintf(STDERR,"RW Volume does not exist; Will perform a full restore\n");
1876 avolid = entry.volumeId[RWVOL];
1878 else if (entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1879 avolid = entry.volumeId[RWVOL];
1883 else { /* volume exists - do we do a full incremental or abort */
1884 int Oserver, Opart, Otype, vol_elsewhere = 0;
1885 struct nvldbentry Oentry;
1889 avolid = entry.volumeId[RWVOL];
1891 else if(entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1892 avolid = entry.volumeId[RWVOL];
1895 /* A file name was specified - check if volume is on another partition */
1896 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
1899 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
1901 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1905 if (!vcode || (Opart != apart)) vol_elsewhere = 1;
1907 if (aoverwrite == ASK) {
1908 if (strcmp(afilename,"") == 0) { /* The file is from standard in */
1909 fprintf(STDERR,"Volume exists and no -overwrite option specified; Aborting restore command\n");
1913 /* Ask what to do */
1914 if (vol_elsewhere) {
1915 fprintf(STDERR,"The volume %s %u already exists on a different server/part\n",
1916 volname, entry.volumeId[RWVOL]);
1918 "Do you want to do a full restore or abort? [fa](a): ");
1922 fprintf(STDERR,"The volume %s %u already exists in the VLDB\n",
1923 volname, entry.volumeId[RWVOL]);
1925 "Do you want to do a full/incremental restore or abort? [fia](a): ");
1928 while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */
1929 if ((c == 'f') || (c == 'F')) aoverwrite = FULL;
1930 else if ((c == 'i') || (c == 'I')) aoverwrite = INC;
1931 else aoverwrite = ABORT;
1934 if (aoverwrite == ABORT) {
1935 fprintf(STDERR,"Volume exists; Aborting restore command\n");
1938 else if (aoverwrite == FULL) {
1939 restoreflags = RV_FULLRST;
1940 fprintf(STDERR,"Volume exists; Will delete and perform full restore\n");
1942 else if (aoverwrite == INC) {
1944 if (vol_elsewhere) {
1946 "RW volume %u already exists on a different server/part; not allowed\n",
1952 code = UV_RestoreVolume(aserver, apart, avolid, avolname,
1953 restoreflags, WriteData, afilename);
1955 PrintDiagnostics("restore", code);
1958 MapPartIdIntoName(apart,apartName);
1961 patch typo here - originally "parms[1]", should be "parms[0]"
1964 fprintf(STDOUT,"Restored volume %s on %s %s\n",
1965 avolname, as->parms[0].items->data, apartName);
1968 static LockReleaseCmd(as)
1969 register struct cmd_syndesc *as;
1972 afs_int32 avolid,code, err;
1974 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1976 if (err) PrintError("", err);
1977 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1981 code = UV_LockRelease(avolid);
1983 PrintDiagnostics("unlock", code);
1986 fprintf(STDOUT,"Released lock on vldb entry for volume %s\n",as->parms[0].items->data);
1990 register struct cmd_syndesc *as;
1992 afs_int32 avolid, aserver, apart,code, err;
1995 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1997 if (err) PrintError("", err);
1998 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2001 aserver = GetServer(as->parms[0].items->data);
2003 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2006 apart = volutil_GetPartitionID(as->parms[1].items->data);
2008 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2011 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2012 if(code) PrintError("",code);
2013 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2016 code = UV_AddSite(aserver, apart, avolid);
2018 PrintDiagnostics("addsite", code);
2021 MapPartIdIntoName(apart,apartName);
2022 fprintf(STDOUT,"Added replication site %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data);
2026 static RemoveSite(as)
2027 register struct cmd_syndesc *as;
2030 afs_int32 avolid, aserver, apart, code, err;
2033 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2035 if (err) PrintError("", err);
2036 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2039 aserver = GetServer(as->parms[0].items->data);
2041 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2044 apart = volutil_GetPartitionID(as->parms[1].items->data);
2046 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2050 *skip the partition validity check, since it is possible that the partition
2051 *has since been decomissioned.
2054 if (!IsPartValid(apart,aserver,&code)){
2055 if(code) PrintError("",code);
2056 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2060 code = UV_RemoveSite(aserver, apart, avolid);
2062 PrintDiagnostics("remsite", code);
2065 MapPartIdIntoName(apart,apartName);
2066 fprintf(STDOUT,"Removed replication site %s %s for volume %s\n",as->parms[0].items->data,apartName,as->parms[2].items->data);
2070 static ListPartitions(as)
2071 register struct cmd_syndesc *as;
2073 afs_int32 aserver,code;
2074 struct partList dummyPartList;
2079 aserver = GetServer(as->parms[0].items->data);
2081 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2086 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2088 PrintDiagnostics("listpart", code);
2092 fprintf(STDOUT,"The partitions on the server are:\n");
2093 for(i = 0 ; i < cnt ; i++){
2094 if(dummyPartList.partFlags[i] & PARTVALID){
2095 bzero(pname,sizeof(pname));
2096 MapPartIdIntoName(dummyPartList.partId[i],pname);
2097 fprintf(STDOUT," %10s ",pname);
2099 if( (i % 5) == 0 && (i != 0)) fprintf(STDOUT,"\n");
2102 fprintf(STDOUT,"\n");
2103 fprintf(STDOUT,"Total: %d\n",total);
2108 static int CompareVolName(p1,p2)
2111 volintInfo *arg1,*arg2;
2113 arg1 = (volintInfo *)p1;
2114 arg2 = (volintInfo *)p2;
2115 return(strcmp(arg1->name,arg2->name));
2119 /*------------------------------------------------------------------------
2120 * PRIVATE XCompareVolName
2123 * Comparison routine for volume names coming from an extended
2127 * a_obj1P : Char ptr to first extended vol info object
2128 * a_obj1P : Char ptr to second extended vol info object
2131 * The value of strcmp() on the volume names within the passed
2132 * objects (i,e., -1, 0, or 1).
2135 * Passed to qsort() as the designated comparison routine.
2139 *------------------------------------------------------------------------*/
2141 static int XCompareVolName(a_obj1P, a_obj2P)
2142 char *a_obj1P, *a_obj2P;
2144 { /*XCompareVolName*/
2146 return(strcmp(((struct volintXInfo *)(a_obj1P))->name,
2147 ((struct volintXInfo *)(a_obj2P))->name));
2149 } /*XCompareVolName*/
2151 static int CompareVolID(p1,p2)
2154 volintInfo *arg1,*arg2;
2156 arg1 = (volintInfo *)p1;
2157 arg2 = (volintInfo *)p2;
2158 if(arg1->volid == arg2->volid) return 0;
2159 if(arg1->volid > arg2->volid) return 1;
2164 /*------------------------------------------------------------------------
2165 * PRIVATE XCompareVolID
2168 * Comparison routine for volume IDs coming from an extended
2172 * a_obj1P : Char ptr to first extended vol info object
2173 * a_obj1P : Char ptr to second extended vol info object
2176 * The value of strcmp() on the volume names within the passed
2177 * objects (i,e., -1, 0, or 1).
2180 * Passed to qsort() as the designated comparison routine.
2184 *------------------------------------------------------------------------*/
2186 static int XCompareVolID(a_obj1P, a_obj2P)
2187 char *a_obj1P, *a_obj2P;
2191 afs_int32 id1, id2; /*Volume IDs we're comparing*/
2193 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2194 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2205 /*------------------------------------------------------------------------
2206 * PRIVATE ListVolumes
2209 * Routine used to list volumes, contacting the Volume Server
2210 * directly, bypassing the VLDB.
2213 * as : Ptr to parsed command line arguments.
2216 * 0 Successful operation
2219 * Nothing interesting.
2223 *------------------------------------------------------------------------*/
2225 static ListVolumes(as)
2226 register struct cmd_syndesc *as;
2228 afs_int32 apart,int32list,fast;
2229 afs_int32 aserver,code;
2230 volintInfo *pntr,*oldpntr;
2234 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info*/
2235 int wantExtendedInfo; /*Do we want extended vol info?*/
2238 struct partList dummyPartList;
2246 if(as->parms[3].items) int32list = 1;
2247 if(as->parms[4].items) quiet = 1;
2249 if(as->parms[2].items) fast = 1;
2252 if (as->parms[5].items) {
2254 * We can't coexist with the fast flag.
2258 "vos: Can't use the -fast and -extended flags together\n");
2263 * We need to turn on ``long'' listings to get the full effect.
2265 wantExtendedInfo = 1;
2269 wantExtendedInfo = 0;
2270 if(as->parms[1].items){
2271 apart = volutil_GetPartitionID(as->parms[1].items->data);
2273 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
2276 dummyPartList.partId[0] = apart;
2277 dummyPartList.partFlags[0] = PARTVALID;
2280 aserver = GetServer(as->parms[0].items->data);
2282 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
2287 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2288 if(code) PrintError("",code);
2289 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2294 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2296 PrintDiagnostics("listvol", code);
2300 for(i = 0 ; i < cnt ; i++){
2301 if(dummyPartList.partFlags[i] & PARTVALID){
2302 if (wantExtendedInfo)
2303 code = UV_XListVolumes(aserver,
2304 dummyPartList.partId[i],
2309 code = UV_ListVolumes(aserver,
2310 dummyPartList.partId[i],
2315 PrintDiagnostics("listvol", code);
2316 if(pntr) free(pntr);
2319 if (wantExtendedInfo) {
2320 origxInfoP = xInfoP;
2321 base = (char *)xInfoP;
2324 base = (char *)pntr;
2328 if (wantExtendedInfo)
2329 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2331 qsort(base, count, sizeof(volintInfo), CompareVolName);
2333 if (wantExtendedInfo)
2334 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2336 qsort(base, count, sizeof(volintInfo), CompareVolID);
2338 MapPartIdIntoName(dummyPartList.partId[i],pname);
2340 fprintf(STDOUT,"Total number of volumes on server %s partition %s: %u \n",as->parms[0].items->data,pname,count);
2341 if (wantExtendedInfo) {
2342 XDisplayVolumes(aserver,
2343 dummyPartList.partId[i],
2351 xInfoP = (volintXInfo *)0;
2354 DisplayVolumes(aserver,
2355 dummyPartList.partId[i],
2363 pntr = (volintInfo *)0;
2371 register struct cmd_syndesc *as;
2373 afs_int32 pname, code; /* part name */
2379 if (as->parms[0].items) {
2380 tserver = GetServer(as->parms[0].items->data);
2382 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2387 if (as->parms[1].items) {
2388 pname = volutil_GetPartitionID(as->parms[1].items->data);
2390 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2393 if (!IsPartValid(pname,tserver,&code)) { /*check for validity of the partition */
2394 if(code) PrintError("",code);
2395 else fprintf(STDERR,"vos: partition %s does not exist on the server\n",
2396 as->parms[1].items->data);
2402 fprintf(STDERR,"The -partition option requires a -server option\n");
2407 if (as->parms[2].items) {
2408 /* Synchronize an individual volume */
2409 volname = as->parms[2].items->data;
2410 code = UV_SyncVolume(tserver, pname, volname, flags);
2413 fprintf(STDERR,"Without a -volume option, the -server option is required\n");
2416 code = UV_SyncVldb(tserver, pname, flags, 0/*unused*/);
2420 PrintDiagnostics("syncvldb", code);
2424 /* Print a summary of what we did */
2425 if (volname) fprintf(STDOUT,"VLDB volume %s synchronized", volname);
2426 else fprintf(STDOUT,"VLDB synchronized");
2428 fprintf(STDOUT," with state of server %s", as->parms[0].items->data);
2431 MapPartIdIntoName(pname,part);
2432 fprintf(STDOUT," partition %s\n", part);
2434 fprintf(STDOUT, "\n");
2439 static SyncServer(as)
2440 register struct cmd_syndesc *as;
2443 afs_int32 pname,code; /* part name */
2448 tserver = GetServer(as->parms[0].items->data);
2450 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2453 if(as->parms[1].items){
2454 pname = volutil_GetPartitionID(as->parms[1].items->data);
2456 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data);
2459 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
2460 if(code) PrintError("",code);
2461 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2467 code = UV_SyncServer(tserver, pname, flags, 0/*unused*/);
2469 PrintDiagnostics("syncserv", code);
2473 MapPartIdIntoName(pname,part);
2474 fprintf(STDOUT,"Server %s partition %s synchronized with VLDB\n",as->parms[0].items->data,part);
2476 else fprintf(STDOUT,"Server %s synchronized with VLDB\n",as->parms[0].items->data);
2481 static VolumeInfoCmd(name)
2484 struct nvldbentry entry;
2487 /* The vlserver will handle names with the .readonly
2488 * and .backup extension as well as volume ids.
2490 vcode = VLDB_GetEntryByName(name, &entry);
2492 PrintError("", vcode);
2495 MapHostToNetwork(&entry);
2496 EnumerateEntry(&entry);
2498 /* Defect #3027: grubby check to handle locked volume.
2499 * If VLOP_ALLOPERS is set, the entry is locked.
2500 * Leave this routine as is, but put in correct check.
2502 if (entry.flags & VLOP_ALLOPERS)
2503 fprintf(STDOUT," Volume is currently LOCKED \n");
2508 static VolumeZap(as)
2509 register struct cmd_syndesc *as;
2512 struct nvldbentry entry;
2513 afs_int32 volid,code,server,part, zapbackupid=0, backupid=0, err;
2515 if (as->parms[3].items) {
2516 /* force flag is on, use the other version */
2517 return NukeVolume(as);
2520 if (as->parms[4].items) {
2524 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2526 if (err) PrintError("", err);
2527 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2530 part = volutil_GetPartitionID(as->parms[1].items->data);
2532 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2535 server = GetServer(as->parms[0].items->data);
2537 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2540 if (!IsPartValid(part,server,&code)){/*check for validity of the partition */
2541 if(code) PrintError("",code);
2542 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2545 code = VLDB_GetEntryByID(volid,-1, &entry);
2547 if (volid == entry.volumeId[RWVOL])
2548 backupid = entry.volumeId[BACKVOL];
2549 fprintf(STDERR,"Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n",
2553 volintInfo *pntr = (volintInfo *)0;
2556 code = UV_ListOneVolume(server, part, volid, &pntr);
2558 if (volid == pntr->parentID)
2559 backupid = pntr->backupID;
2560 if (pntr) free(pntr);
2564 code = UV_VolumeZap(server,part, backupid);
2566 PrintDiagnostics("zap", code);
2569 fprintf(STDOUT,"Backup Volume %u deleted\n", backupid);
2572 code = UV_VolumeZap(server,part,volid);
2574 PrintDiagnostics("zap", code);
2577 fprintf(STDOUT,"Volume %u deleted\n",volid);
2582 static VolserStatus(as)
2583 register struct cmd_syndesc *as;
2586 afs_int32 server, code;
2587 transDebugInfo *pntr,*oldpntr;
2592 server = GetServer(as->parms[0].items->data);
2594 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2597 code = UV_VolserStatus(server,&pntr,&count);
2599 PrintDiagnostics("status",code);
2604 fprintf(STDOUT,"No active transactions on %s\n",as->parms[0].items->data);
2606 fprintf(STDOUT,"Total transactions: %d\n",count);
2608 for(i = 0; i < count ; i++){
2609 /*print out the relevant info */
2610 fprintf(STDOUT,"--------------------------------------\n");
2611 fprintf(STDOUT,"transaction: %u created: %s",pntr->tid,
2612 ctime((time_t *)&pntr->time));
2613 if(pntr->returnCode){
2614 fprintf(STDOUT,"returnCode: %u\n",pntr->returnCode);
2617 fprintf(STDOUT,"attachFlags: ");
2618 switch(pntr->iflags){
2619 case ITOffline: fprintf(STDOUT,"offline ");
2621 case ITBusy: fprintf(STDOUT,"busy ");
2623 case ITReadOnly: fprintf(STDOUT,"readonly ");
2625 case ITCreate: fprintf(STDOUT,"create ");
2627 case ITCreateVolID: fprintf(STDOUT,"create volid ");
2630 fprintf(STDOUT,"\n");
2633 fprintf(STDOUT,"volumeStatus: ");
2634 switch(pntr->vflags){
2635 case VTDeleteOnSalvage: fprintf(STDOUT,"deleteOnSalvage ");
2636 case VTOutOfService: fprintf(STDOUT,"outOfService ");
2637 case VTDeleted: fprintf(STDOUT,"deleted ");
2639 fprintf(STDOUT,"\n");
2642 fprintf(STDOUT,"transactionFlags: ");
2643 fprintf(STDOUT,"delete\n");
2645 MapPartIdIntoName(pntr->partition ,pname);
2646 fprintf(STDOUT,"volume: %u partition: %s procedure: %s\n",pntr->volid,pname, pntr->lastProcName);
2647 if(pntr->callValid){
2648 fprintf(STDOUT,"packetRead: %u lastReceiveTime: %d packetSend: %u lastSendTime: %d\n",pntr->readNext,pntr->lastReceiveTime,pntr->transmitNext, pntr->lastSendTime);
2651 fprintf(STDOUT,"--------------------------------------\n");
2652 fprintf(STDOUT,"\n");
2654 if(oldpntr) free(oldpntr);
2658 static RenameVolume(as)
2659 register struct cmd_syndesc *as;
2661 afs_int32 code1,code2,code;
2662 struct nvldbentry entry;
2664 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
2666 fprintf(STDERR,"vos: Could not find entry for volume %s\n",as->parms[0].items->data);
2669 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
2670 if((!code1) && (!code2)) { /*the newname already exists */
2671 fprintf(STDERR,"vos: volume %s already exists\n",as->parms[1].items->data);
2676 fprintf(STDERR,"vos: Could not find entry for volume %s or %s\n",as->parms[0].items->data,as->parms[1].items->data);
2679 if(!VolNameOK(as->parms[0].items->data)){
2680 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[0].items->data);
2683 if(!ISNAMEVALID(as->parms[1].items->data)) {
2684 fprintf(STDERR,"vos: the new volume name %s exceeds the size limit of %d\n",as->parms[1].items->data,VOLSER_OLDMAXVOLNAME - 10);
2687 if(!VolNameOK(as->parms[1].items->data)){
2688 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[1].items->data);
2691 if(IsNumeric(as->parms[1].items->data)){
2692 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[1].items->data);
2695 MapHostToNetwork(&entry);
2696 code = UV_RenameVolume(&entry,as->parms[0].items->data,as->parms[1].items->data);
2698 PrintDiagnostics("rename", code);
2701 fprintf(STDOUT,"Renamed volume %s to %s\n",as->parms[0].items->data,as->parms[1].items->data);
2705 GetVolumeInfo(volid, server, part, voltype,rentry)
2706 afs_int32 *server, volid, *part, *voltype;
2707 register struct nvldbentry *rentry;
2712 vcode = VLDB_GetEntryByID(volid, -1, rentry);
2714 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB \n",volid);
2715 PrintError("",vcode);
2718 MapHostToNetwork(rentry);
2719 if(volid == rentry->volumeId[ROVOL]){
2721 for (i = 0; i < rentry->nServers; i++) {
2722 if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
2723 !(rentry->serverFlags[i] & RO_DONTUSE) )
2727 fprintf(STDERR,"RO volume is not found in VLDB entry for volume %u\n", volid);
2731 *server = rentry->serverNumber[index];
2732 *part = rentry->serverPartition[index];
2736 index = Lp_GetRwIndex(rentry);
2738 fprintf(STDERR,"RW Volume is not found in VLDB entry for volume %u\n", volid);
2741 if(volid == rentry->volumeId[RWVOL]){
2743 *server = rentry->serverNumber[index];
2744 *part = rentry->serverPartition[index];
2747 if(volid == rentry->volumeId[BACKVOL]){
2749 *server = rentry->serverNumber[index];
2750 *part = rentry->serverPartition[index];
2755 static DeleteEntry(as)
2756 register struct cmd_syndesc *as;
2762 struct VldbListByAttributes attributes;
2763 nbulkentries arrayEntries;
2764 register struct nvldbentry *vllist;
2765 struct cmd_item *itp;
2768 char prefix[VOLSER_MAXVOLNAME+1];
2770 afs_int32 totalBack=0, totalFail=0, err;
2772 if (as->parms[0].items) { /* -id */
2773 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
2774 fprintf(STDERR,"You cannot use -server, -partition, or -prefix with the -id argument\n");
2777 for (itp=as->parms[0].items; itp; itp=itp->next) {
2778 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
2780 if (err) PrintError("", err);
2781 else fprintf(STDERR, "vos: can't find volume '%s'\n", itp->data);
2784 if (as->parms[4].items) { /* -noexecute */
2785 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", itp->data);
2789 vcode = ubik_Call(VL_DeleteEntry,cstruct, 0, avolid, RWVOL);
2791 fprintf(STDERR,"Could not delete entry for volume %s\n", itp->data);
2792 fprintf(STDERR,"You must specify a RW volume name or ID "
2793 "(the entire VLDB entry will be deleted)\n", itp->data);
2794 PrintError("",vcode);
2800 fprintf(STDOUT,"Deleted %d VLDB entries\n", totalBack);
2804 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
2805 fprintf(STDERR,"You must specify an option\n");
2809 /* Zero out search attributes */
2810 bzero(&attributes,sizeof(struct VldbListByAttributes));
2812 if (as->parms[1].items) { /* -prefix */
2813 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
2815 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
2816 fprintf(STDERR,"You must provide -server with the -prefix argument\n");
2821 if (as->parms[2].items) { /* -server */
2823 aserver = GetServer(as->parms[2].items->data);
2825 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[2].items->data );
2828 attributes.server = ntohl(aserver);
2829 attributes.Mask |= VLLIST_SERVER;
2832 if (as->parms[3].items) { /* -partition */
2833 if (!as->parms[2].items) {
2834 fprintf(STDERR,"You must provide -server with the -partition argument\n");
2837 apart = volutil_GetPartitionID(as->parms[3].items->data);
2839 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
2840 as->parms[3].items->data);
2843 attributes.partition = apart;
2844 attributes.Mask |= VLLIST_PARTITION;
2847 /* Print status line of what we are doing */
2848 fprintf(STDOUT,"Deleting VLDB entries for ");
2849 if (as->parms[2].items) {
2850 fprintf(STDOUT,"server %s ", as->parms[2].items->data);
2852 if (as->parms[3].items) {
2854 MapPartIdIntoName(apart, pname);
2855 fprintf(STDOUT,"partition %s ", pname);
2858 fprintf(STDOUT,"which are prefixed with %s ", prefix);
2860 fprintf(STDOUT,"\n");
2863 /* Get all the VLDB entries on a server and/or partition */
2864 bzero(&arrayEntries, sizeof(arrayEntries));
2865 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
2867 fprintf(STDERR,"Could not access the VLDB for attributes\n");
2868 PrintError("",vcode);
2872 /* Process each entry */
2873 for (j=0; j<nentries; j++) {
2874 vllist = &arrayEntries.nbulkentries_val[j];
2876 /* It only deletes the RW volumes */
2877 if (strncmp(vllist->name, prefix, strlen(prefix))){
2879 fprintf(STDOUT,"Omitting to delete %s due to prefix %s mismatch\n",
2880 vllist->name, prefix);
2887 if (as->parms[4].items) { /* -noexecute */
2888 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", vllist->name);
2893 /* Only matches the RW volume name */
2894 avolid = vllist->volumeId[RWVOL];
2895 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
2897 fprintf(STDOUT,"Could not delete VDLB entry for %s\n",vllist->name);
2899 PrintError("",vcode);
2904 fprintf(STDOUT,"Deleted VLDB entry for %s \n",vllist->name);
2909 fprintf(STDOUT,"----------------------\n");
2910 fprintf(STDOUT,"Total VLDB entries deleted: %u; failed to delete: %u\n",totalBack,totalFail);
2911 if (arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
2916 static int CompareVldbEntryByName(p1,p2)
2919 struct nvldbentry *arg1,*arg2;
2921 arg1 = (struct nvldbentry *)p1;
2922 arg2 = (struct nvldbentry *)p2;
2923 return(strcmp(arg1->name,arg2->name));
2927 static int CompareVldbEntry(p1,p2)
2930 struct nvldbentry *arg1,*arg2;
2933 char comp1[100],comp2[100];
2934 char temp1[20],temp2[20];
2936 arg1 = (struct nvldbentry *)p1;
2937 arg2 = (struct nvldbentry *)p2;
2941 for(i = 0; i < arg1->nServers; i++)
2942 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
2943 for(i = 0; i < arg2->nServers; i++)
2944 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
2945 if(pos1 == -1 || pos2 == -1){
2949 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
2950 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
2951 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
2952 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
2953 strcat(comp1,temp1);
2954 strcat(comp2,temp2);
2955 strcat(comp1,arg1->name);
2956 strcat(comp1,arg2->name);
2957 return(strcmp(comp1,comp2));
2963 struct cmd_syndesc *as;
2966 afs_int32 aserver,code;
2968 struct VldbListByAttributes attributes;
2969 nbulkentries arrayEntries;
2970 struct nvldbentry *vllist, *tarray=0, *ttarray;
2971 afs_int32 centries, nentries = 0, tarraysize, parraysize;
2974 int quiet, sort, lock;
2975 afs_int32 thisindex, nextindex;
2980 attributes.Mask = 0;
2981 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
2982 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
2983 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
2985 /* If the volume name is given, Use VolumeInfoCmd to look it up
2986 * and not ListAttributes.
2988 if (as->parms[0].items) {
2990 fprintf(STDERR,"vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
2993 code = VolumeInfoCmd(as->parms[0].items->data);
2995 PrintError("",code);
3001 /* Server specified */
3002 if (as->parms[1].items) {
3003 aserver = GetServer(as->parms[1].items->data);
3005 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3008 attributes.server = ntohl(aserver);
3009 attributes.Mask |= VLLIST_SERVER;
3012 /* Partition specified */
3013 if (as->parms[2].items) {
3014 apart = volutil_GetPartitionID(as->parms[2].items->data);
3016 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3019 attributes.partition = apart;
3020 attributes.Mask |= VLLIST_PARTITION;
3024 attributes.Mask |= VLLIST_FLAG;
3025 attributes.flag = VLOP_ALLOPERS;
3028 /* Print header information */
3030 MapPartIdIntoName(apart, pname);
3031 fprintf(STDOUT,"VLDB entries for %s %s%s%s %s\n",
3032 (as->parms[1].items ? "server" : "all" ),
3033 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3034 (as->parms[2].items ? " partition " : ""),
3035 (as->parms[2].items ? pname : ""),
3036 (lock ? "which are locked:" : ""));
3039 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3040 bzero(&arrayEntries, sizeof(arrayEntries));
3044 vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex,
3045 ¢ries, &arrayEntries, &nextindex);
3046 if (vcode == RXGEN_OPCODE) {
3047 /* Vlserver not running with ListAttributesN2. Fall back */
3048 vcode = VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3052 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3053 PrintError("",vcode);
3056 nentries += centries;
3058 /* We don't sort, so just print the entries now */
3060 for (j = 0; j < centries; j++) { /* process each entry */
3061 vllist = &arrayEntries.nbulkentries_val[j];
3062 MapHostToNetwork(vllist);
3063 EnumerateEntry(vllist);
3065 if(vllist->flags & VLOP_ALLOPERS)
3066 fprintf(STDOUT," Volume is currently LOCKED \n");
3070 /* So we sort. First we must collect all the entries and keep
3073 else if (centries > 0) {
3075 /* steal away the first bulk entries array */
3076 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3077 tarraysize = centries * sizeof(struct nvldbentry);
3078 arrayEntries.nbulkentries_val = 0;
3080 /* Grow the tarray to keep the extra entries */
3081 parraysize = (centries * sizeof(struct nvldbentry));
3082 ttarray = (struct nvldbentry *) realloc(tarray, tarraysize + parraysize);
3084 fprintf(STDERR,"Could not allocate enough space for the VLDB entries\n");
3090 bcopy((char *)arrayEntries.nbulkentries_val,
3091 ((char *)tarray)+tarraysize, parraysize);
3092 tarraysize += parraysize;
3096 /* Free the bulk array */
3097 if (arrayEntries.nbulkentries_val) {
3098 free(arrayEntries.nbulkentries_val);
3099 arrayEntries.nbulkentries_val = 0;
3103 /* Here is where we now sort all the entries and print them */
3104 if (sort && (nentries > 0)) {
3105 qsort((char *)tarray, nentries, sizeof(struct nvldbentry), CompareVldbEntryByName);
3106 for (vllist=tarray, j=0; j<nentries; j++, vllist++) {
3107 MapHostToNetwork(vllist);
3108 EnumerateEntry(vllist);
3110 if(vllist->flags & VLOP_ALLOPERS)
3111 fprintf(STDOUT," Volume is currently LOCKED \n");
3116 if (!quiet) fprintf(STDOUT,"\nTotal entries: %u\n", nentries);
3117 if (tarray) free(tarray);
3122 register struct cmd_syndesc *as;
3124 afs_int32 apart=0, avolid;
3125 afs_int32 aserver=0, code, aserver1, apart1;
3127 struct VldbListByAttributes attributes;
3128 nbulkentries arrayEntries;
3129 register struct nvldbentry *vllist;
3133 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3134 afs_int32 totalBack=0;
3135 afs_int32 totalFail=0;
3136 int previdx=-1, error, same;
3139 struct cmd_item *ti;
3143 bzero(&attributes,sizeof(struct VldbListByAttributes));
3144 attributes.Mask = 0;
3146 seenprefix = (as->parms[0].items ? 1 : 0);
3147 exclude = (as->parms[3].items ? 1 : 0);
3148 seenxprefix = (as->parms[4].items ? 1 : 0);
3149 noaction = (as->parms[5].items ? 1 : 0);
3151 if (as->parms[1].items) { /* -server */
3152 aserver = GetServer(as->parms[1].items->data);
3154 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3157 attributes.server = ntohl(aserver);
3158 attributes.Mask |= VLLIST_SERVER;
3161 if (as->parms[2].items) { /* -partition */
3162 apart = volutil_GetPartitionID(as->parms[2].items->data);
3164 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3167 attributes.partition = apart;
3168 attributes.Mask |= VLLIST_PARTITION;
3171 /* Check to make sure the prefix and xprefix expressions compile ok */
3173 for (ti=as->parms[0].items; ti; ti=ti->next) {
3174 if (strncmp(ti->data,"^",1) == 0) {
3175 ccode = (char *)re_comp(ti->data);
3177 fprintf(STDERR,"Unrecognizable -prefix regular expression: '%s': %s\n",
3185 for (ti=as->parms[4].items; ti; ti=ti->next) {
3186 if (strncmp(ti->data,"^",1) == 0) {
3187 ccode = (char *)re_comp(ti->data);
3189 fprintf(STDERR,"Unrecognizable -xprefix regular expression: '%s': %s\n",
3197 bzero(&arrayEntries, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3198 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3200 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3201 PrintError("",vcode);
3205 if (as->parms[1].items || as->parms[2].items || verbose) {
3206 fprintf(STDOUT,"%s up volumes", (noaction?"Would have backed":"Backing"));
3208 if (as->parms[1].items) {
3209 fprintf(STDOUT," on server %s", as->parms[1].items->data);
3210 } else if (as->parms[2].items) {
3211 fprintf(STDOUT," for all servers");
3214 if (as->parms[2].items) {
3215 MapPartIdIntoName(apart, pname);
3216 fprintf(STDOUT," partition %s", pname);
3219 if (seenprefix || (!seenprefix && seenxprefix)) {
3220 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3221 ex = (seenprefix ? exclude : !exclude);
3222 exp = (strncmp(ti->data,"^",1) == 0);
3223 fprintf(STDOUT," which %smatch %s '%s'", (ex ? "do not " : ""),
3224 (exp?"expression":"prefix"), ti->data);
3225 for (ti=ti->next; ti; ti=ti->next) {
3226 exp = (strncmp(ti->data,"^",1) == 0);
3227 printf(" %sor %s '%s'", (ex ? "n" : ""),
3228 (exp?"expression":"prefix"), ti->data);
3232 if (seenprefix && seenxprefix) {
3233 ti = as->parms[4].items;
3234 exp = (strncmp(ti->data,"^",1) == 0);
3235 fprintf(STDOUT," %swhich match %s '%s'",
3236 (exclude?"adding those ":"removing those "),
3237 (exp?"expression":"prefix"), ti->data);
3238 for (ti=ti->next; ti; ti=ti->next) {
3239 exp = (strncmp(ti->data,"^",1) == 0);
3240 printf(" or %s '%s'", (exp?"expression":"prefix"), ti->data);
3243 fprintf(STDOUT," .. ");
3244 if (verbose) fprintf(STDOUT,"\n");
3248 for (j=0; j<nentries; j++) { /* process each vldb entry */
3249 vllist = &arrayEntries.nbulkentries_val[j];
3252 for (ti=as->parms[0].items; ti; ti=ti->next) {
3253 if (strncmp(ti->data,"^",1) == 0) {
3254 ccode = (char *)re_comp(ti->data);
3256 fprintf(STDERR,"Error in -prefix regular expression: '%s': %s\n",
3260 match = (re_exec(vllist->name) == 1);
3262 match = (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0);
3270 /* Without the -exclude flag: If it matches the prefix, then
3271 * check if we want to exclude any from xprefix.
3272 * With the -exclude flag: If it matches the prefix, then
3273 * check if we want to add any from xprefix.
3275 if (match && seenxprefix) {
3276 for (ti=as->parms[4].items; ti; ti=ti->next) {
3277 if (strncmp(ti->data,"^",1) == 0) {
3278 ccode = (char *)re_comp(ti->data);
3280 fprintf(STDERR,"Error in -xprefix regular expression: '%s': %s\n",
3284 if (re_exec(vllist->name) == 1) {
3289 if (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0) {
3297 if (exclude) match = !match; /* -exclude will reverse the match */
3298 if (!match) continue; /* Skip if no match */
3300 /* Print list of volumes to backup */
3302 fprintf(STDOUT," %s\n", vllist->name);
3306 if(!(vllist->flags & RW_EXISTS)){
3308 fprintf(STDOUT,"Omitting to backup %s since RW volume does not exist \n", vllist->name);
3309 fprintf(STDOUT,"\n");
3315 avolid = vllist->volumeId[RWVOL];
3316 MapHostToNetwork(vllist);
3317 GetServerAndPart(vllist,RWVOL,&aserver1,&apart1,&previdx);
3318 if(aserver1 == -1 || apart1 == -1){
3319 fprintf(STDOUT,"could not backup %s, invalid VLDB entry\n",vllist->name);
3324 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
3326 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3332 if ((aserver && !same) || (apart && (apart != apart1))) {
3334 fprintf(STDOUT, "Omitting to backup %s since the RW is in a different location\n", vllist->name);
3339 time_t now = time(0);
3340 fprintf(STDOUT,"Creating backup volume for %s on %s",vllist->name, ctime(&now));
3344 code = UV_BackupVolume(aserver1, apart1, avolid);
3346 fprintf(STDOUT,"Could not backup %s\n",vllist->name);
3352 if (verbose) fprintf(STDOUT,"\n");
3354 } /* process each vldb entry */
3355 fprintf(STDOUT,"done\n");
3356 fprintf(STDOUT,"Total volumes backed up: %u; failed to backup: %u\n",totalBack,totalFail);
3358 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3362 static UnlockVLDB(as)
3363 register struct cmd_syndesc *as;
3366 afs_int32 aserver,code;
3368 struct VldbListByAttributes attributes;
3369 nbulkentries arrayEntries;
3370 register struct nvldbentry *vllist;
3379 attributes.Mask = 0;
3381 if(as->parms[0].items) {/* server specified */
3382 aserver = GetServer(as->parms[0].items->data);
3384 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3387 attributes.server = ntohl(aserver);
3388 attributes.Mask |= VLLIST_SERVER;
3390 if(as->parms[1].items) {/* partition specified */
3391 apart = volutil_GetPartitionID(as->parms[1].items->data);
3393 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3396 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3397 if(code) PrintError("",code);
3398 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3401 attributes.partition = apart;
3402 attributes.Mask |= VLLIST_PARTITION;
3404 attributes.flag = VLOP_ALLOPERS;
3405 attributes.Mask |= VLLIST_FLAG;
3406 bzero(&arrayEntries, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
3407 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3409 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3410 PrintError("",vcode);
3413 for(j=0;j<nentries;j++) { /* process each entry */
3414 vllist = &arrayEntries.nbulkentries_val[j];
3415 volid = vllist->volumeId[RWVOL];
3416 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid,-1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3418 fprintf(STDERR,"Could not unlock entry for volume %s\n",vllist->name);
3419 PrintError("",vcode);
3424 MapPartIdIntoName(apart,pname);
3425 if(totalE) fprintf(STDOUT,"Could not lock %u VLDB entries of %u locked entries\n",totalE,nentries);
3427 if(as->parms[0].items) {
3428 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on server %s ",as->parms[0].items->data);
3429 if(as->parms[1].items){
3430 MapPartIdIntoName(apart,pname);
3431 fprintf(STDOUT,"partition %s\n",pname);
3433 else fprintf(STDOUT,"\n");
3436 else if(as->parms[1].items){
3437 MapPartIdIntoName(apart,pname);
3438 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on partition %s on all servers\n",pname);
3442 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3446 static PartitionInfo(as)
3447 register struct cmd_syndesc *as;
3450 afs_int32 aserver,code;
3452 struct diskPartition partition;
3453 struct partList dummyPartList;
3457 aserver = GetServer(as->parms[0].items->data);
3459 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3462 if(as->parms[1].items){
3463 apart = volutil_GetPartitionID(as->parms[1].items->data);
3465 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3468 dummyPartList.partId[0] = apart;
3469 dummyPartList.partFlags[0] = PARTVALID;
3473 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3474 if(code) PrintError("",code);
3475 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3480 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
3482 PrintDiagnostics("listpart", code);
3486 for(i = 0 ; i < cnt ; i++){
3487 if(dummyPartList.partFlags[i] & PARTVALID){
3488 MapPartIdIntoName(dummyPartList.partId[i],pname);
3489 code = UV_PartitionInfo(aserver,pname,&partition);
3491 fprintf(STDERR,"Could not get information on partition %s\n",pname);
3492 PrintError("",code);
3495 fprintf(STDOUT,"Free space on partition %s: %d K blocks out of total %d\n",pname,partition.free,partition.minFree);
3501 static ChangeAddr(as)
3502 register struct cmd_syndesc *as;
3505 afs_int32 ip1, ip2, vcode;
3508 ip1 = GetServer(as->parms[0].items->data);
3510 fprintf(STDERR, "vos: invalid host address\n");
3514 if ( ( as->parms[1].items && as->parms[2].items) ||
3515 (!as->parms[1].items && !as->parms[2].items) ) {
3516 fprintf(STDERR, "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
3520 if (as->parms[1].items) {
3521 ip2 = GetServer(as->parms[1].items->data);
3523 fprintf(STDERR, "vos: invalid host address\n");
3527 /* Play a trick here. If we are removing an address, ip1 will be -1
3528 * and ip2 will be the original address. This switch prevents an
3529 * older revision vlserver from removing the IP address.
3536 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2) );
3539 fprintf(STDERR,"Could not remove server %s from the VLDB\n",
3540 as->parms[0].items->data);
3541 if (vcode == VL_NOENT) {
3542 fprintf(STDERR, "vlserver does not support the remove flag or ");
3545 fprintf(STDERR,"Could not change server %s to server %s\n",
3546 as->parms[0].items->data, as->parms[1].items->data);
3548 PrintError("",vcode);
3553 fprintf(STDOUT,"Removed server %s from the VLDB\n",
3554 as->parms[0].items->data);
3556 fprintf(STDOUT,"Changed server %s to server %s\n",
3557 as->parms[0].items->data, as->parms[1].items->data);
3562 static ListAddrs(as)
3563 register struct cmd_syndesc *as;
3568 struct VLCallBack unused;
3569 afs_int32 nentries, *addrp;
3570 bulkaddrs addrs, m_addrs;
3571 ListAddrByAttributes m_attrs;
3573 afs_int32 m_unique, m_nentries, *m_addrp;
3574 afs_int32 base, index;
3576 /* Get the list of non multihomed fileservers */
3577 addrs.bulkaddrs_val = 0;
3578 addrs.bulkaddrs_len = 0;
3579 vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0,
3580 0, 0, &unused, &nentries, &addrs);
3582 fprintf(STDERR,"vos: could not list the server addresses\n");
3583 PrintError("",vcode);
3587 /* print out the list of all the server */
3588 addrp = (afs_int32 *)addrs.bulkaddrs_val;
3589 for (i=0; i<nentries; i++, addrp++) {
3590 /* If it is a multihomed address, then we will need to
3591 * get the addresses for this multihomed server from
3592 * the vlserver and print them.
3594 if ( ((*addrp & 0xff000000) == 0xff000000) && ((*addrp)&0xffff) ) {
3595 /* Get the list of multihomed fileservers */
3596 base = (*addrp>>16) & 0xff;
3597 index = (*addrp) & 0xffff;
3599 if ( (base >= 0) && (base <= VL_MAX_ADDREXTBLKS) &&
3600 (index >= 1) && (index <= VL_MHSRV_PERBLK) ) {
3601 m_attrs.Mask = VLADDR_INDEX;
3602 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
3604 m_addrs.bulkaddrs_val = 0;
3605 m_addrs.bulkaddrs_len = 0;
3606 vcode = ubik_Call(VL_GetAddrsU, cstruct, 0,
3607 &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs);
3609 fprintf(STDERR,"vos: could not list the multi-homed server addresses\n");
3610 PrintError("",vcode);
3613 /* Print the list */
3614 m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val;
3615 for (j=0; j<m_nentries; j++, m_addrp++) {
3616 *m_addrp = htonl(*m_addrp);
3617 printf("%s ", hostutil_GetNameByINet(*m_addrp));
3620 printf("<unknown>\n");
3629 /* Otherwise, it is a non-multihomed entry and contains
3630 * the IP address of the server - print it.
3632 printf ("%s\n", hostutil_GetNameByINet(htonl(*addrp)));
3635 if (addrs.bulkaddrs_val) {
3636 free (addrs.bulkaddrs_val);
3641 static LockEntry(as)
3642 register struct cmd_syndesc *as;
3645 afs_int32 avolid,vcode, err;
3647 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3649 if (err) PrintError("", err);
3650 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
3653 vcode = ubik_Call(VL_SetLock,cstruct, 0, avolid, -1, VLOP_DELETE);
3655 fprintf(STDERR,"Could not lock VLDB entry for volume %s\n",as->parms[0].items->data);
3656 PrintError("",vcode);
3659 fprintf(STDOUT,"Locked VLDB entry for volume %s\n",as->parms[0].items->data);
3663 PrintDiagnostics(astring, acode)
3667 if (acode == EACCES) {
3668 fprintf(STDERR,"You are not authorized to perform the 'vos %s' command (%d)\n",
3672 fprintf(STDERR,"Error in vos %s command.\n", astring);
3673 PrintError("", acode);
3679 static MyBeforeProc(as, arock)
3680 struct cmd_syndesc *as;
3682 register char *tcell;
3683 register afs_int32 code;
3684 register afs_int32 sauth;
3686 /* Initialize the ubik_client connection */
3687 rx_SetRxDeadTime(90);
3688 cstruct = (struct ubik_client *)0;
3692 if (as->parms[12].items) /* if -cell specified */
3693 tcell = as->parms[12].items->data;
3694 if(as->parms[14].items) /* -serverauth specified */
3696 if (code = vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
3697 &cstruct, UV_SetSecurity)) {
3698 fprintf(STDERR,"could not initialize VLDB library (code=%u) \n",code);
3702 if(as->parms[15].items) /* -verbose flag set */
3711 /* this sucks but it works for now.
3716 #include "AFS_component_version_number.c"
3721 register afs_int32 code;
3723 register struct cmd_syndesc *ts;
3725 #ifdef AFS_AIX32_ENV
3727 * The following signal action for AIX is necessary so that in case of a
3728 * crash (i.e. core is generated) we can include the user's data section
3729 * in the core dump. Unfortunately, by default, only a partial core is
3730 * generated which, in many cases, isn't too useful.
3732 struct sigaction nsa;
3734 sigemptyset(&nsa.sa_mask);
3735 nsa.sa_handler = SIG_DFL;
3736 nsa.sa_flags = SA_FULLDUMP;
3737 sigaction(SIGSEGV, &nsa, NULL);
3740 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
3742 cmd_SetBeforeProc(MyBeforeProc, (char *) 0);
3744 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
3745 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3746 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3747 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
3748 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "initial quota (KB)");
3750 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
3754 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
3755 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3756 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
3757 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3761 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
3762 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3763 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
3764 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source");
3765 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination");
3766 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination");
3769 ts = cmd_CreateSyntax("backup", BackupVolume, 0, "make backup of a volume");
3770 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3773 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
3774 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3775 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force a complete release");
3778 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
3779 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3780 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
3781 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
3782 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
3783 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
3786 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
3787 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3788 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3789 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
3790 cmd_AddParm(ts, "-file", CMD_SINGLE,CMD_OPTIONAL, "dump file");
3791 cmd_AddParm(ts, "-id", CMD_SINGLE,CMD_OPTIONAL, "volume ID");
3792 cmd_AddParm(ts, "-overwrite", CMD_SINGLE,CMD_OPTIONAL, "abort | full | incremental");
3795 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, "release lock on VLDB entry for a volume");
3796 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3799 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
3800 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
3801 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new site");
3802 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3805 ts = cmd_CreateSyntax("remsite", RemoveSite, 0, "remove a replication site");
3806 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3807 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3808 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3811 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
3812 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3815 ts = cmd_CreateSyntax("listvol", ListVolumes, 0, "list volumes on server (bypass VLDB)");
3816 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3817 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3818 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
3819 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
3820 "list all normal volume fields");
3821 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3822 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3823 "list extended volume fields");
3826 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, "synchronize VLDB with server");
3827 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3828 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3829 cmd_AddParm(ts, "-volume", CMD_SINGLE,CMD_OPTIONAL , "volume name or ID");
3832 ts = cmd_CreateSyntax("syncserv", SyncServer, 0, "synchronize server with VLDB");
3833 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3834 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3837 ts = cmd_CreateSyntax("examine", ExamineVolume, 0, "everything about the volume");
3838 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3839 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3840 "list extended volume fields");
3842 cmd_CreateAlias (ts, "volinfo");
3844 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *) CMD_HIDDEN);
3845 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3846 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3847 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3848 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
3849 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
3852 ts = cmd_CreateSyntax("online", volOnline, 0, (char *) CMD_HIDDEN);
3853 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3854 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3855 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3858 ts = cmd_CreateSyntax("zap", VolumeZap, 0, "delete the volume, don't bother with VLDB");
3859 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3860 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3861 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
3862 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force deletion of bad volumes");
3863 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, "also delete backup volume if one is found");
3866 ts = cmd_CreateSyntax("status", VolserStatus, 0, "report on volser status");
3867 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3870 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
3871 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
3872 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
3875 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, "list volumes in the VLDB");
3876 cmd_AddParm(ts, "-name", CMD_SINGLE,CMD_OPTIONAL, "volume name or ID");
3877 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3878 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3879 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
3880 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3881 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, "do not alphabetically sort the volume names");
3884 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
3885 cmd_AddParm(ts, "-prefix", CMD_LIST,CMD_OPTIONAL, "common prefix on volume(s)");
3886 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3887 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3888 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, "exclude common prefix volumes");
3889 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, "negative prefix on volume(s)");
3890 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
3893 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, "delete VLDB entry for a volume");
3894 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
3895 cmd_AddParm(ts, "-prefix", CMD_SINGLE,CMD_OPTIONAL, "prefix of the volume whose VLDB entry is to be deleted");
3896 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3897 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3898 cmd_AddParm(ts, "-noexecute", CMD_FLAG,CMD_OPTIONAL|CMD_HIDE, "no execute");
3901 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, "list partition information");
3902 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3903 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3906 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, "unlock all the locked entries in the VLDB");
3907 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3908 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3911 ts = cmd_CreateSyntax("lock", LockEntry, 0, "lock VLDB entry for a volume");
3912 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3915 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, "change the IP address of a file server");
3916 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
3917 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
3918 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, "remove the IP address from the VLDB");
3921 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB");
3924 code = cmd_Dispatch(argc, argv);
3926 /* Shut down the ubik_client and rx connections */
3928 ubik_ClientDestroy (cstruct);