2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
26 #include <WINNT/afsevent.h>
28 #ifdef HAVE_SYS_TIME_H
31 #ifdef HAVE_SYS_FILE_H
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
43 #include <afs/afsutil.h>
46 #include <rx/rx_globals.h>
48 #include <afs/cellconfig.h>
56 void fill_listattributes_entry();
57 void display_listattributes_entry();
59 void display_entryN();
60 void display_update_entry();
65 void fill_update_entry();
67 #define VL_NUMBER_OPCODESX 34
68 static char *opcode_names[VL_NUMBER_OPCODESX] = {
114 #define ALLOCNT 50000
115 struct Vlent *VLa[NVOLS];
116 #define VHash(avol) ((avol)&(NVOLS-1))
117 struct Vlent *VL, *SVL;
119 struct ubik_client *cstruct;
120 struct rx_connection *serverconns[MAXSERVERS];
121 char confdir[AFSDIR_PATH_MAX];
125 GetVolume(vol, entry)
126 struct vldbentry *entry;
129 register struct Vlent *vl;
134 for (vl = VLa[i]; vl; vl = vl->next) {
135 if ((vl->rwid == vol && vol != entry->volumeId[0])
136 || (vl->roid == vol && vol != entry->volumeId[1])
137 || (vl->baid == vol && vol != entry->volumeId[2])) {
141 VL->rwid = entry->volumeId[0];
142 VL->roid = entry->volumeId[1];
143 VL->baid = entry->volumeId[2];
144 strcpy(entry->name, VL->name);
147 if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */
148 printf("Too many entries (> %d)\n", ALLOCNT);
155 /* Almost identical's to pr_Initialize in vlserver/pruser.c */
157 vl_Initialize(int auth, char *confDir, int server, char *cellp)
159 return ugen_ClientInit(auth?0:1, confDir, cellp, 0,
160 &cstruct, NULL, "vl_Initialize", rxkad_clear,
161 MAXSERVERS, AFSCONF_VLDBSERVICE, 50, server,
162 htons(AFSCONF_VLDBPORT), USER_SERVICE_ID);
165 /* return host address in network byte order */
167 GetServer(char *aname)
169 register struct hostent *th;
172 register afs_int32 code;
174 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
176 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
177 return htonl(addr); /* convert to network order (128 in byte 0) */
179 th = gethostbyname(aname);
182 memcpy(&addr, th->h_addr, sizeof(addr));
189 struct cmd_syndesc *as;
191 register struct cmd_item *ti;
192 register afs_int32 code, server = 0, sawserver = 0;
193 afs_int32 id, voltype;
194 struct vldbentry entry;
195 char *cmd = 0, *cellp = 0;
196 struct VldbUpdateEntry updateentry;
197 struct VldbListByAttributes listbyattributes;
198 int noAuth = 1; /* Default is authenticated connections */
200 if (ti = as->parms[0].items) /* -cellpath <dir> */
201 strcpy(confdir, ti->data);
202 if (as->parms[1].items) /* -server */
203 strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH);
204 if (as->parms[2].items) /* -noauth */
206 if (ti = as->parms[3].items) { /* -host */
207 server = GetServer(ti->data);
209 printf("server '%s' not found in host table\n", ti->data);
214 if (!sawserver && noAuth && (!(ti = as->parms[4].items))) {
216 ("Must also specify the -cell' option along with -host for authenticated conns\n");
219 if (ti = as->parms[4].items) { /* -cell */
222 if (code = vl_Initialize(noAuth, confdir, server, cellp)) {
223 printf("Couldn't initialize vldb library (code=%d).\n", code);
227 if (as->parms[5].items) { /* -gstats */
229 vital_vlheader vital_header;
230 code = ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header);
232 dump_stats(&stats, &vital_header);
238 int nargs, releasetype;
239 memset(&entry, 0, sizeof(entry));
240 memset(&updateentry, 0, sizeof(updateentry));
241 memset(&listbyattributes, 0, sizeof(listbyattributes));
243 if (fgets(line, 499, stdin) == NULL) {
248 register char **argp = args;
249 GetArgs(line, argp, &nargs);
252 if (!strcmp(oper, "cr")) {
253 fill_entry(&entry, argp, nargs);
254 display_entry(&entry, 0);
255 code = ubik_Call(VL_CreateEntry, cstruct, 0, &entry);
256 printf("return code is %d\n", code);
257 } else if (!strcmp(oper, "rm")) {
258 sscanf(&(*argp)[0], "%d", &id);
260 sscanf(&(*argp)[0], "%d", &voltype);
261 code = ubik_Call(VL_DeleteEntry, cstruct, 0, id, voltype);
262 printf("return code is %d\n", code);
263 } else if (!strcmp(oper, "re")) {
264 sscanf(&(*argp)[0], "%d", &id);
266 sscanf(&(*argp)[0], "%d", &voltype);
268 sscanf(&(*argp)[0], "%d", &releasetype);
270 fill_entry(&entry, argp, nargs);
271 display_entry(&entry, 0);
273 ubik_Call(VL_ReplaceEntry, cstruct, 0, id, voltype,
274 &entry, releasetype);
275 printf("return code is %d\n", code);
276 } else if (!strcmp(oper, "up")) {
277 sscanf(&(*argp)[0], "%d", &id);
279 sscanf(&(*argp)[0], "%d", &voltype);
281 sscanf(&(*argp)[0], "%d", &releasetype);
283 fill_update_entry(&updateentry, argp, nargs);
284 display_update_entry(&updateentry, 0);
286 ubik_Call(VL_UpdateEntry, cstruct, 0, id, voltype,
287 &updateentry, releasetype);
288 printf("return code is %d\n", code);
289 } else if (!strcmp(oper, "ls")) {
290 afs_int32 index, count, next_index;
291 for (index = 0; 1; index = next_index) {
292 memset(&entry, 0, sizeof(entry));
294 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
295 &next_index, &entry);
297 printf("VL_ListEntry returned code = %d\n", code);
302 display_entry(&entry, 0);
304 } else if (!strcmp(oper, "ldups")) {
305 afs_int32 index, count, num = 0, num1 = 0, next_index;
309 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
311 printf("Can't allocate memory...\n");
314 printf("Enumerating all entries in vldb...\n");
315 for (index = 0; 1; index = next_index) {
316 memset(&entry, 0, sizeof(entry));
318 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
319 &next_index, &entry);
321 printf("VL_ListEntry returned code = %d\n", code);
327 if (vl1 = GetVolume(entry.volumeId[0], &entry)) {
330 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
331 entry.volumeId[0], vl1->rwid, vl1->roid,
332 vl1->baid, vl1->name);
334 if (vl1 = GetVolume(entry.volumeId[1], &entry)) {
337 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
338 entry.volumeId[1], vl1->rwid, vl1->roid,
339 vl1->baid, vl1->name);
341 if (vl1 = GetVolume(entry.volumeId[2], &entry)) {
344 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
345 entry.volumeId[2], vl1->rwid, vl1->roid,
346 vl1->baid, vl1->name);
348 /*display_entry(&entry, 0); */
350 printf("(%d vldb entries found - %d duplicates)\n", num,
352 } else if (!strcmp(oper, "checkhash")) {
353 int index, count, num = 0, num1 = 0, num2 = 0, num3 =
354 0, num31 = 0, num4 = 0, num41 = 0, next_index;
355 struct vldbentry tentry;
358 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
360 printf("Can't allocate memory...\n");
363 printf("Volumes not found in main hash tables in vldb...\n");
364 for (index = 0; 1; index = next_index) {
365 memset(&entry, 0, sizeof(entry));
367 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
368 &next_index, &entry);
370 printf("VL_ListEntry returned code = %d\n", code);
377 ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name,
379 if (code == VL_NOENT) {
381 printf("\tVolume %s %d (not in namehash)\n",
382 entry.name, entry.volumeId[RWVOL]);
385 ubik_Call(VL_GetEntryByID, cstruct, 0,
386 entry.volumeId[RWVOL], RWVOL, &tentry);
387 if (code == VL_NOENT) {
389 printf("\tVolume %s %d (not in rwid hash)\n",
390 entry.name, entry.volumeId[RWVOL]);
392 if (entry.volumeId[BACKVOL]) {
394 ubik_Call(VL_GetEntryByID, cstruct, 0,
395 entry.volumeId[BACKVOL], BACKVOL,
398 if (code == VL_NOENT) {
400 printf("\tVolume %s %d (not in backup id hash)\n",
401 entry.name, entry.volumeId[BACKVOL]);
404 if (entry.volumeId[ROVOL]) {
406 ubik_Call(VL_GetEntryByID, cstruct, 0,
407 entry.volumeId[ROVOL], ROVOL, &tentry);
409 if (code == VL_NOENT) {
411 printf("\tVolume %s %d (not in RO id hash)\n",
412 entry.name, entry.volumeId[ROVOL]);
417 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
418 num, num + num31 + num41, num, num31, num41);
420 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
423 ("\t%d didn't hash properly by backup volid (out of %d)\n\t%d didn't hash properly by ro volid (out of %d)\n",
424 num3, num31, num4, num41);
425 } else if (!strcmp(oper, "fixhash")) {
426 int index, count, num = 0, num1 = 0, num2 = 0, next_index, x =
428 struct vldbentry tentry;
431 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
433 printf("Can't allocate memory...\n");
437 ("Volumes not found in main hash tables in vldb will be fixed...\n");
438 memset(&updateentry, 0, sizeof(updateentry));
439 for (index = 0; 1; index = next_index) {
440 /* FIXME: n2 is never changed for some reason */
441 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
442 memset(&entry, 0, sizeof(entry));
444 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
445 &next_index, &entry);
447 printf("VL_ListEntry returned code = %d\n", code);
454 ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name,
456 if (code == VL_NOENT) {
459 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
460 printf("\tVolume %s %d (not in namehash)\n",
461 entry.name, entry.volumeId[RWVOL]);
463 ubik_Call(VL_UpdateEntry, cstruct, 0,
464 entry.volumeId[RWVOL], -1, &updateentry,
468 printf("\tFailed to update volume %s (err=%d)\n",
473 ubik_Call(VL_GetEntryByID, cstruct, 0,
474 entry.volumeId[RWVOL], RWVOL, &tentry);
475 if (code == VL_NOENT) {
478 updateentry.Mask = VLUPDATE_RWID;
479 updateentry.spares3 = entry.volumeId[RWVOL];
480 printf("\tVolume %s %d (not in rw id hash)\n",
481 entry.name, entry.volumeId[RWVOL]);
483 ubik_Call(VL_UpdateEntryByName, cstruct, 0,
484 entry.name, &updateentry, 0);
486 printf("\tFailed to update volume %s (err=%d)\n",
492 if (entry.volumeId[BACKVOL] && !n2) {
494 ubik_Call(VL_GetEntryByID, cstruct, 0,
495 entry.volumeId[BACKVOL], BACKVOL,
497 if (code == VL_NOENT) {
500 updateentry.Mask = VLUPDATE_BACKUPID;
501 updateentry.BackupId = entry.volumeId[BACKVOL];
502 printf("\tVolume %s %d (not in backup id hash)\n",
503 entry.name, entry.volumeId[BACKVOL]);
505 ubik_Call(VL_UpdateEntry, cstruct, 0,
506 entry.volumeId[RWVOL], -1,
510 ("\tFailed to update volume %s (err=%d)\n",
516 if (entry.volumeId[ROVOL && !n2]) {
518 ubik_Call(VL_GetEntryByID, cstruct, 0,
519 entry.volumeId[ROVOL], ROVOL, &tentry);
520 if (code == VL_NOENT) {
523 updateentry.Mask = VLUPDATE_READONLYID;
524 updateentry.ReadOnlyId = entry.volumeId[ROVOL];
525 printf("\tVolume %s %d (not in RO id hash)\n",
526 entry.name, entry.volumeId[ROVOL]);
528 ubik_Call(VL_UpdateEntry, cstruct, 0,
529 entry.volumeId[RWVOL], -1,
533 ("\tFailed to update volume %s (err=%d)\n",
541 ("\nTotal vldb entries found %d:\n\t%d entries didn't hash properly and are fixed except %d that need to be handled manually\n",
543 } else if (!strcmp(oper, "la")) {
546 struct vldbentry *entry;
548 memset(&entries, 0, sizeof(entries));
549 fill_listattributes_entry(&listbyattributes, argp, nargs);
550 display_listattributes_entry(&listbyattributes, 0);
552 ubik_Call(VL_ListAttributes, cstruct, 0,
553 &listbyattributes, &nentries, &entries);
555 printf("VL_ListAttributes returned code = %d\n", code);
558 entry = (struct vldbentry *)entries.bulkentries_val;
559 for (i = 0; i < nentries; i++, entry++)
560 display_entry(entry, 0);
561 if (entries.bulkentries_val)
562 free((char *)entries.bulkentries_val);
563 } else if (!strcmp(oper, "lan2")) {
564 int nentries, i, si, nsi, t = 0;
565 nbulkentries entries;
566 struct nvldbentry *entry;
569 /* The volume name to search for (supports wildcarding) */
571 strcpy(name, argp[0]);
577 fill_listattributes_entry(&listbyattributes, argp, nargs);
578 display_listattributes_entry(&listbyattributes, 0);
579 printf("Wildcard VolName: '%s'\n", name);
581 for (si = 0; si != -1; si = nsi) {
583 memset(&entries, 0, sizeof(entries));
585 ubik_Call(VL_ListAttributesN2, cstruct, 0,
586 &listbyattributes, name, si, &nentries,
589 printf("VL_ListAttributesN2 returned code = %d\n",
595 entry = (struct nvldbentry *)entries.nbulkentries_val;
596 for (i = 0; i < nentries; i++, entry++)
597 display_entryN(entry, 0);
598 if (entries.nbulkentries_val)
599 free((char *)entries.nbulkentries_val);
601 printf("--- %d volumes ---\n", t);
602 } else if (!strcmp(oper, "ln")) {
604 vldb_list linkedvldbs;
605 vldblist vllist, vllist1;
607 fill_listattributes_entry(&listbyattributes, argp, nargs);
608 display_listattributes_entry(&listbyattributes, 0);
609 memset(&linkedvldbs, 0, sizeof(vldb_list));
611 ubik_Call(VL_LinkedList, cstruct, 0, &listbyattributes,
612 &netries, &linkedvldbs);
614 printf("VL_LinkedList returned code = %d\n", code);
617 printf("Found %d entr%s\n", netries,
618 (netries == 1 ? "y" : "ies"));
619 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
620 vllist1 = vllist->next_vldb;
621 display_entry(&vllist->VldbEntry, 0);
622 free((char *)vllist);
624 } else if (!strcmp(oper, "lnn")) {
626 nvldb_list linkedvldbs;
627 nvldblist vllist, vllist1;
629 fill_listattributes_entry(&listbyattributes, argp, nargs);
630 display_listattributes_entry(&listbyattributes, 0);
631 memset(&linkedvldbs, 0, sizeof(vldb_list));
633 ubik_Call(VL_LinkedListN, cstruct, 0, &listbyattributes,
634 &netries, &linkedvldbs);
636 printf("VL_LinkedList returned code = %d\n", code);
639 printf("Found %d entr%s\n", netries,
640 (netries == 1 ? "y" : "ies"));
641 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
642 vllist1 = vllist->next_vldb;
643 display_entry(&vllist->VldbEntry, 0);
644 free((char *)vllist);
646 } else if (!strcmp(oper, "di")) {
647 sscanf(&(*argp)[0], "%d", &id);
649 sscanf(&(*argp)[0], "%d", &voltype);
651 ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype,
653 display_entry(&entry, code);
654 printf("return code is %d.\n", code);
655 } else if (!strcmp(oper, "rmnh")) {
656 sscanf(&(*argp)[0], "%d", &id);
658 sscanf(&(*argp)[0], "%d", &voltype);
660 ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype,
662 display_entry(&entry, code);
663 memset(&updateentry, 0, sizeof(updateentry));
664 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
665 printf("\tRehashing namehash table for %s (%d)\n", entry.name,
666 entry.volumeId[RWVOL]);
668 ubik_Call(VL_UpdateEntry, cstruct, 0,
669 entry.volumeId[RWVOL], -1, &updateentry, 0);
671 printf("\tFailed to update volume %s (err=%d)\n",
674 printf("return code is %d.\n", code);
675 } else if (!strcmp(oper, "undelete")) {
676 afs_int32 index, count, next_index;
678 memset(&updateentry, 0, sizeof(updateentry));
679 sscanf(&(*argp)[0], "%d", &id);
681 sscanf(&(*argp)[0], "%d", &voltype);
682 if (voltype < 0 && voltype > 2) {
683 printf("Illegal voltype; must be 0, 1 or 2\n");
686 printf("Searching vldb for volume %d...\n", id);
687 for (index = 0; 1; index = next_index) {
688 memset(&entry, 0, sizeof(entry));
690 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
691 &next_index, &entry);
693 printf("VL_ListEntry returned code = %d\n", code);
698 if (entry.volumeId[voltype] == id) {
699 printf("\nThe current contents of the vldb for %d:\n",
701 display_entry(&entry, 0);
703 if (entry.flags & VLDELETED) {
704 updateentry.Mask = VLUPDATE_FLAGS;
705 updateentry.flags = entry.flags;
706 updateentry.flags &= ~VLDELETED;
708 ("\tUndeleting vldb entry for vol %d (%s)\n",
711 ubik_Call(VL_UpdateEntry, cstruct, 0, id, -1,
715 ("\tFailed to update volume %s (err=%d)\n",
719 printf("Entry not deleted; ignored\n");
724 } else if (!strcmp(oper, "dn")) {
727 ubik_Call(VL_GetEntryByNameO, cstruct, 0, vname, &entry);
728 display_entry(&entry, code);
729 printf("return code is %d.\n", code);
730 } else if (!strcmp(oper, "nv")) {
732 sscanf(&(*argp)[0], "%d", &id);
734 ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &newvolid);
736 printf("Current Max volid is (in hex):%X\n", newvolid);
737 printf("return code is %d\n", code);
738 } else if (!strcmp(oper, "gs")) {
740 vital_vlheader vital_header;
742 ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header);
744 dump_stats(&stats, &vital_header);
745 printf("return code is %d.\n", code);
746 } else if (!strcmp(oper, "ga")) {
750 struct VLCallBack vlcb;
752 addrs.bulkaddrs_val = 0;
753 addrs.bulkaddrs_len = 0;
754 code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ ,
755 0 /*spare2 */ , &vlcb,
758 printf("VL_GetAddrs returned code = %d\n", code);
761 addrp = addrs.bulkaddrs_val;
762 for (i = 0; i < nentries; i++, addrp++) {
763 if ((*addrp & 0xff000000) == 0xff000000)
764 printf("[0x%x %u] (special multi-homed entry)\n",
767 printf("[0x%x %u] %s\n", *addrp, *addrp,
768 hostutil_GetNameByINet(ntohl(*addrp)));
770 free((char *)addrs.bulkaddrs_val);
771 } else if (!strcmp(oper, "gau")) {
775 struct VLCallBack vlcb;
777 addrs.bulkaddrs_val = 0;
778 addrs.bulkaddrs_len = 0;
779 code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ ,
780 0 /*spare2 */ , &vlcb,
783 printf("VL_GetAddrs returned code = %d\n", code);
786 addrp = addrs.bulkaddrs_val;
787 for (i = 0; i < nentries; i++, addrp++) {
788 if ((*addrp & 0xff000000) == 0xff000000) {
789 int mhnentries, unique;
790 struct in_addr hostAddr;
793 ListAddrByAttributes attrs;
796 printf("[0x%x %u] (special multi-homed entry)\n",
798 attrs.Mask = VLADDR_INDEX;
799 mhaddrs.bulkaddrs_val = 0;
800 mhaddrs.bulkaddrs_len = 0;
801 attrs.index = *addrp & 0x00ffffff;
804 ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid,
805 &unique, &mhnentries, &mhaddrs);
807 printf("VL_GetAddrsU returned code = %d\n", code);
811 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
812 attrs.index, uuid.time_low, uuid.time_mid,
813 uuid.time_hi_and_version,
814 uuid.clock_seq_hi_and_reserved,
815 uuid.clock_seq_low, uuid.node[0], uuid.node[1],
816 uuid.node[2], uuid.node[3], uuid.node[4],
817 uuid.node[5], unique);
818 mhaddrp = mhaddrs.bulkaddrs_val;
819 for (j = 0; j < mhnentries; j++) {
820 mhaddrp[j] = ntohl(mhaddrp[j]);
821 hostAddr.s_addr = mhaddrp[j];
822 printf("\t%s (%s)\n", inet_ntoa(hostAddr),
823 hostutil_GetNameByINet(mhaddrp[j]));
825 if (mhaddrs.bulkaddrs_val)
826 free((char *)mhaddrs.bulkaddrs_val);
828 printf("[0x%x %u] %s\n", *addrp, *addrp,
829 hostutil_GetNameByINet(ntohl(*addrp)));
832 free((char *)addrs.bulkaddrs_val);
833 } else if (!strcmp(oper, "mhc")) {
834 afs_int32 serveraddrs[MAXSERVERID + 1][VL_MAXIPADDRS_PERMH];
835 afs_int32 serveraddrtype[MAXSERVERID + 1];
836 int nentries1, nentries2, i, j, x, y, unique, found;
837 afs_uint32 *addrp1, *addrp2;
838 bulkaddrs addrs1, addrs2;
839 struct VLCallBack vlcb;
840 ListAddrByAttributes attrs;
842 afs_int32 base, index;
844 for (i = 0; i < MAXSERVERID + 1; i++) {
845 serveraddrtype[i] = 0;
846 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
847 serveraddrs[i][j] = 0;
850 /* Collect a list of all registered IP addresses */
851 addrs1.bulkaddrs_val = 0;
852 addrs1.bulkaddrs_len = 0;
854 ubik_Call(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb,
855 &nentries1, &addrs1);
857 printf("VL_GetAddrs returned code = %d\n", code);
860 addrp1 = addrs1.bulkaddrs_val;
861 for (i = 0; i < nentries1; i++, addrp1++) {
862 if ((*addrp1 & 0xff000000) != 0xff000000) {
863 serveraddrs[i][0] = ntohl(*addrp1);
864 serveraddrtype[i] = 1;
866 /* It's multihomed. Get all of its addresses */
867 serveraddrtype[i] = 2;
868 base = (*addrp1 >> 16) & 0xff;
869 index = *addrp1 & 0xffff;
871 addrs2.bulkaddrs_val = 0;
872 addrs2.bulkaddrs_len = 0;
873 attrs.Mask = VLADDR_INDEX;
874 attrs.index = (base * VL_MHSRV_PERBLK) + index;
876 ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid,
877 &unique, &nentries2, &addrs2);
879 printf("VL_GetAddrsU returned code = %d\n", code);
883 addrp2 = addrs2.bulkaddrs_val;
884 for (j = 0; j < nentries2; j++) {
885 serveraddrs[i][j] = ntohl(addrp2[j]);
887 free((char *)addrs2.bulkaddrs_val);
891 if (serveraddrtype[i] == 1) {
892 printf("%u\n", serveraddrs[i][0]);
895 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
896 if (serveraddrs[i][j])
897 printf(" %u", serveraddrs[i][j]);
902 free((char *)addrs1.bulkaddrs_val);
904 /* Look for any duplicates */
905 for (i = 0; i < MAXSERVERID + 1; i++) {
906 if (!serveraddrtype[i])
908 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
909 if (!serveraddrs[i][j])
913 for (x = i + 1; x < MAXSERVERID + 1; x++) {
914 if (!serveraddrtype[x])
916 for (y = 0; y < VL_MAXIPADDRS_PERMH; y++) {
917 if (!serveraddrs[x][y])
919 if (serveraddrs[i][j] == serveraddrs[x][y]) {
920 serveraddrs[x][y] = 0;
927 ("Found %d entries of IP address %u (0x%x)\n",
928 found + 1, serveraddrs[i][j],
934 /*----------------------------------------*/
936 } else if (!strcmp(oper, "regaddr")) {
938 afs_uint32 *addrp, tad;
942 memset(&uuid, 0, sizeof(uuid));
943 sscanf(&(*argp)[0], "%d", &i);
945 memcpy(uuid.node, &i, sizeof(i));
947 if (nargs < 0 || nargs > 16) {
948 printf("Illegal # entries = %d\n", nargs);
951 addrp = (afs_uint32 *) malloc(20 * 4);
952 addrs.bulkaddrs_val = addrp;
953 addrs.bulkaddrs_len = nargs;
955 sscanf(&(*argp)[0], "%d", &tad);
960 ubik_Call(VL_RegisterAddrs, cstruct, 0, &uuid,
961 0 /*spare */ , &addrs);
963 printf("VL_RegisterAddrs returned code = %d\n", code);
966 } else if (!strcmp(oper, "ca")) {
967 extern struct hostent *hostutil_GetHostByName();
968 struct hostent *h1, *h2;
971 printf("changing %s", *argp);
972 h1 = hostutil_GetHostByName(&(*argp)[0]);
974 printf("cmdebug: can't resolve address for host %s",
978 memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32));
981 printf(" to %s\n", *argp);
982 h2 = hostutil_GetHostByName(&(*argp)[0]);
984 printf("cmdebug: can't resolve address for host %s",
988 memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32));
990 printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2));
992 ubik_Call(VL_ChangeAddr, cstruct, 0, ntohl(a1),
995 printf("VL_ChangeAddr returned code = %d\n", code);
998 } else if (!strcmp(oper, "caid")) {
1001 sscanf(&(*argp)[0], "%d", &a1);
1002 printf("changing %d (0x%x)", a1, a1);
1004 sscanf(&(*argp)[0], "%d", &a2);
1005 printf(" to %d (0x%x)\n", a2, a2);
1006 code = ubik_Call(VL_ChangeAddr, cstruct, 0, a1, a2);
1008 printf("VL_ChangeAddr returned code = %d\n", code);
1011 } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h"))
1013 else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
1016 printf("Unknown oper!\n");
1023 #include "AFS_component_version_number.c"
1029 register struct cmd_syndesc *ts;
1032 strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
1033 ts = cmd_CreateSyntax("initcmd", handleit, 0, "initialize the program");
1034 cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL,
1035 "Cell configuration directory");
1036 cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL,
1037 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1038 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1039 "Run it without authentication");
1040 cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL,
1041 "vldb server to talk to");
1042 cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL,
1043 "cellname '-host' belongs to (required for auth conns)");
1044 cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL,
1045 "print vldb statistics (non interactive)");
1046 code = cmd_Dispatch(argc, argv);
1052 fill_entry(entry, argp, nargs)
1053 struct vldbentry *entry;
1062 sscanf(&(*argp)[0], "%d", &entry->spares3);
1064 sscanf(&(*argp)[0], "%d", &entry->nServers);
1065 strcpy(entry->name, name);
1066 for (i = 0; i < entry->nServers; i++) {
1068 sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]);
1070 for (i = 0; i < entry->nServers; i++) {
1072 sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]);
1074 for (i = 0; i < entry->nServers; i++) {
1076 sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]);
1078 for (i = 0; i < MAXTYPES; i++) {
1080 sscanf(&(*argp)[0], "%d", &entry->volumeId[i]);
1083 sscanf(&(*argp)[0], "%d", &entry->flags);
1085 sscanf(&(*argp)[0], "%d", &entry->cloneId);
1089 fill_update_entry(entry, argp, nargs)
1090 struct VldbUpdateEntry *entry;
1099 if (strcmp(name, "null")) {
1100 strcpy(entry->name, name);
1101 entry->Mask |= VLUPDATE_VOLUMENAME;
1104 sscanf(&(*argp)[0], "%d", &entry->flags);
1105 if (entry->flags != -1)
1106 entry->Mask |= VLUPDATE_FLAGS;
1108 sscanf(&(*argp)[0], "%d", &entry->cloneId);
1109 if (entry->flags != -1)
1110 entry->Mask |= VLUPDATE_CLONEID;
1112 sscanf(&(*argp)[0], "%d", &entry->ReadOnlyId);
1113 if (entry->ReadOnlyId != -1)
1114 entry->Mask |= VLUPDATE_READONLYID;
1116 sscanf(&(*argp)[0], "%d", &entry->BackupId);
1117 if (entry->BackupId != -1)
1118 entry->Mask |= VLUPDATE_BACKUPID;
1120 sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites);
1121 if (entry->nModifiedRepsites != -1)
1122 entry->Mask |= VLUPDATE_REPSITES;
1123 for (i = 0; i < entry->nModifiedRepsites; i++) {
1125 sscanf(&(*argp)[0], "%x", &Mask);
1127 sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]);
1129 sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]);
1130 if (Mask & VLUPDATE_REPS_DELETE)
1131 entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE;
1132 if (Mask & VLUPDATE_REPS_MODSERV) {
1134 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1135 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV;
1136 } else if (Mask & VLUPDATE_REPS_MODPART) {
1138 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1139 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART;
1140 } else if (Mask & VLUPDATE_REPS_MODFLAG) {
1142 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1143 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG;
1144 } else if (Mask & VLUPDATE_REPS_ADD) {
1146 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1148 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1150 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1151 entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD;
1157 fill_listattributes_entry(entry, argp, nargs)
1158 struct VldbListByAttributes *entry;
1166 entry->server = ntohl(GetServer(argp[0]));
1167 sscanf(&(*argp)[0], "%d", &entry->server);
1168 if (entry->server != 0)
1169 entry->Mask |= VLLIST_SERVER;
1174 sscanf(&(*argp)[0], "%d", &entry->partition);
1175 if (entry->partition != -1)
1176 entry->Mask |= VLLIST_PARTITION;
1181 sscanf(&(*argp)[0], "%d", &entry->volumeid);
1182 if (entry->volumeid != -1)
1183 entry->Mask |= VLLIST_VOLUMEID;
1188 sscanf(&(*argp)[0], "%d", &entry->flag);
1189 if (entry->flag != -1)
1190 entry->Mask |= VLLIST_FLAG;
1194 display_listattributes_entry(entry, error)
1195 struct VldbListByAttributes *entry;
1200 printf("\nList entry values (Mask=%x)\n", entry->Mask);
1201 if (entry->Mask & VLLIST_SERVER)
1202 printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff,
1203 (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff,
1204 (entry->server) & 0xff);
1205 if (entry->Mask & VLLIST_PARTITION)
1206 printf("\tPartition: %d\n", entry->partition);
1207 if (entry->Mask & VLLIST_VOLUMEID)
1208 printf("\tVolumeId: %u\n", entry->volumeid);
1209 if (entry->Mask & VLLIST_FLAG)
1210 printf("\tFlag: %x\n", entry->flag);
1214 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1217 display_entry(entry, error)
1218 struct vldbentry *entry;
1225 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1226 entry->name, entry->volumeId[RWVOL], entry->flags);
1227 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1228 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1230 printf("nServers=%d\n", entry->nServers);
1231 printf("ServerNumber\tServerPart\tserverFlag\n");
1232 for (i = 0; i < entry->nServers; i++)
1233 printf("%12u\t%10d\t%10x\n", entry->serverNumber[i],
1234 entry->serverPartition[i], entry->serverFlags[i]);
1238 display_entryN(entry, error)
1239 struct nvldbentry *entry;
1246 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1247 entry->name, entry->volumeId[RWVOL], entry->flags);
1248 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1249 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1251 printf("nServers=%d\n", entry->nServers);
1252 printf("ServerNumber\tServerPart\tserverFlag\n");
1253 ei = entry->matchindex & 0xffff;
1254 et = (entry->matchindex >> 16) & 0xffff;
1255 for (i = 0; i < entry->nServers; i++) {
1256 printf("%12u\t%10d\t%10x", entry->serverNumber[i],
1257 entry->serverPartition[i], entry->serverFlags[i]);
1259 printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO"));
1266 display_update_entry(entry, error)
1267 struct VldbUpdateEntry *entry;
1274 printf("\nUpdate entry values (Mask=%x)\n", entry->Mask);
1275 if (entry->Mask & VLUPDATE_VOLUMENAME)
1276 printf("\tNew name: %s\n", entry->name);
1277 if (entry->Mask & VLUPDATE_FLAGS)
1278 printf("\tNew flags: %X\n", entry->flags);
1279 if (entry->Mask & VLUPDATE_CLONEID)
1280 printf("\tNew CloneId: %X\n", entry->cloneId);
1281 if (entry->Mask & VLUPDATE_READONLYID)
1282 printf("\tNew RO id: %D\n", entry->ReadOnlyId);
1283 if (entry->Mask & VLUPDATE_BACKUPID)
1284 printf("\tNew BACKUP id: %D\n", entry->BackupId);
1285 if (entry->Mask & VLUPDATE_REPSITES) {
1286 printf("\tRepsites info:\n");
1287 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1288 for (i = 0; i < entry->nModifiedRepsites; i++) {
1289 printf("\t%4x\t%7U\t%5d", entry->RepsitesMask[i],
1290 entry->RepsitesTargetServer[i],
1291 entry->RepsitesTargetPart[i]);
1292 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1293 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV))
1294 printf("\t%7U", entry->RepsitesNewServer[i]);
1296 printf("\t-------");
1297 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1298 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART))
1299 printf("\t%5d", entry->RepsitesNewPart[i]);
1302 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1303 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG))
1304 printf("\t%5x\n", entry->RepsitesNewFlags[i]);
1306 printf("\t-----\n");
1312 dump_stats(stats, vital_header)
1314 vital_vlheader *vital_header;
1318 time_t start_time = stats->start_time;
1320 strncpy(strg, ctime(&start_time), sizeof(strg));
1321 strg[strlen(strg) - 1] = 0;
1322 printf("Dynamic statistics stats (starting time: %s):\n", strg);
1323 printf("OpcodeName\t# Requests\t# Aborts\n");
1324 for (i = 0; i < VL_NUMBER_OPCODESX; i++)
1325 printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i],
1327 printf("\nVldb header stats (version=%d)\n",
1328 ntohl(vital_header->vldbversion));
1329 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1330 ntohl(vital_header->headersize), ntohl(vital_header->allocs),
1331 ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId));
1332 for (i = 0; i < MAXTYPES; i++)
1333 printf("total %s entries=%d\n", volumetype_string(i),
1334 ntohl(vital_header->totalEntries[i]));
1338 GetArgs(line, args, nargs)
1339 register char *line;
1340 register char **args;
1341 register int *nargs;
1345 register char *last = line;
1346 while (*line == ' ')
1352 *args++ = line, (*nargs)++;
1353 while (*line && *line != ' ')
1361 printf("Valid Commands:\n");
1363 printf(" CreateEntry:\n");
1365 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1367 printf(" DeleteEntry:\n");
1368 printf("\trm <volid> <voltype>\n");
1370 printf(" ReplaceEntry:\n");
1371 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1373 printf(" UpdateEntry:\n");
1375 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1377 printf(" ListEntry:\n");
1380 printf(" Find duplicate entries of a volume\n");
1381 printf("\tldups\n");
1383 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1384 printf("\tcheckhash\n");
1387 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1388 printf("\tfixhash\n");
1390 printf(" ListAttributes:\n");
1391 printf("\tla [server] [partition] [volumeid] [flag]\n");
1393 printf(" ListAttributesN2:\n");
1394 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1396 printf(" GetEntryByID:\n");
1397 printf("\tdi <volid> <voltype>\n");
1399 printf(" UpdateEntry (refresh namehash table):\n");
1400 printf("\trmnh <volid> <voltype>\n");
1402 printf(" GetEntryByName:\n");
1403 printf("\tdn <volname> <voltype>\n");
1405 printf(" UpdateEntry (undelete a vol entry):\n");
1406 printf("\tundelete <volid> <voltype>\n");
1408 * printf(" LinkedList\n");
1409 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1411 * printf(" LinkedListN\n");
1412 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1414 printf(" GetNewVoumeId:\n");
1415 printf("\tnv <bump-count>\n");
1417 printf(" GetStats:\n");
1420 printf(" ChangeAddr:\n");
1421 printf("\tca <oldmachname> <newmachname>\n");
1424 * printf(" ChangeAddr\n");
1425 * printf("\t:caid <oldaddr> <newaddr>\n");
1427 printf(" GetAddrs:\n");
1430 printf(" GetAddrsU:\n");
1433 printf(" RegisterAddrs:\n");
1434 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1436 printf("\tmisc: q, quit, ?, h\n");