2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
24 #include <WINNT/afsevent.h>
26 #ifdef HAVE_SYS_TIME_H
29 #ifdef HAVE_SYS_FILE_H
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
42 #include <afs/afsutil.h>
45 #include <rx/rx_globals.h>
47 #include <afs/cellconfig.h>
54 void fill_listattributes_entry(struct VldbListByAttributes *, char **, int);
55 void display_listattributes_entry(struct VldbListByAttributes *,int);
56 void display_entry(struct vldbentry *, int);
57 void display_entryN(struct nvldbentry *, int);
58 void display_update_entry(struct VldbUpdateEntry *, int);
59 void dump_stats(vldstats *, vital_vlheader *);
60 void GetArgs(char *, char **, int *);
61 void print_usage(void);
62 void fill_entry(struct vldbentry *, char **, int);
63 void fill_update_entry(struct VldbUpdateEntry *, char **, int);
65 #define VL_NUMBER_OPCODESX 34
66 static char *opcode_names[VL_NUMBER_OPCODESX] = {
112 #define ALLOCNT 50000
113 struct Vlent *VLa[NVOLS];
114 #define VHash(avol) ((avol)&(NVOLS-1))
115 struct Vlent *VL, *SVL;
117 struct ubik_client *cstruct;
118 struct rx_connection *serverconns[MAXSERVERS];
119 char confdir[AFSDIR_PATH_MAX];
123 GetVolume(int vol, struct vldbentry *entry)
126 register struct Vlent *vl;
131 for (vl = VLa[i]; vl; vl = vl->next) {
132 if ((vl->rwid == vol && vol != entry->volumeId[0])
133 || (vl->roid == vol && vol != entry->volumeId[1])
134 || (vl->baid == vol && vol != entry->volumeId[2])) {
138 VL->rwid = entry->volumeId[0];
139 VL->roid = entry->volumeId[1];
140 VL->baid = entry->volumeId[2];
141 strcpy(entry->name, VL->name);
144 if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */
145 printf("Too many entries (> %d)\n", ALLOCNT);
152 /* Almost identical's to pr_Initialize in vlserver/pruser.c */
154 vl_Initialize(int auth, char *confDir, int server, char *cellp)
156 return ugen_ClientInit(auth?0:1, confDir, cellp, 0,
157 &cstruct, NULL, "vl_Initialize", rxkad_clear,
158 MAXSERVERS, AFSCONF_VLDBSERVICE, 50, server,
159 htons(AFSCONF_VLDBPORT), USER_SERVICE_ID);
162 /* return host address in network byte order */
164 GetServer(char *aname)
166 register struct hostent *th;
169 register afs_int32 code;
171 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
173 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
174 return htonl(addr); /* convert to network order (128 in byte 0) */
176 th = gethostbyname(aname);
179 memcpy(&addr, th->h_addr, sizeof(addr));
185 handleit(struct cmd_syndesc *as, void *arock)
187 register struct cmd_item *ti;
188 register afs_int32 code, server = 0, sawserver = 0;
189 afs_int32 id, voltype;
190 struct vldbentry entry;
192 struct VldbUpdateEntry updateentry;
193 struct VldbListByAttributes listbyattributes;
194 int noAuth = 1; /* Default is authenticated connections */
196 if ((ti = as->parms[0].items)) /* -cellpath <dir> */
197 strcpy(confdir, ti->data);
198 if (as->parms[1].items) /* -server */
199 strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH);
200 if (as->parms[2].items) /* -noauth */
202 if ((ti = as->parms[3].items)) { /* -host */
203 server = GetServer(ti->data);
205 printf("server '%s' not found in host table\n", ti->data);
210 if (!sawserver && noAuth && (!(ti = as->parms[4].items))) {
212 ("Must also specify the -cell' option along with -host for authenticated conns\n");
215 if ((ti = as->parms[4].items)) { /* -cell */
218 if ((code = vl_Initialize(noAuth, confdir, server, cellp))) {
219 printf("Couldn't initialize vldb library (code=%d).\n", code);
223 if (as->parms[5].items) { /* -gstats */
225 vital_vlheader vital_header;
226 code = ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
228 dump_stats(&stats, &vital_header);
234 int nargs, releasetype;
235 memset(&entry, 0, sizeof(entry));
236 memset(&updateentry, 0, sizeof(updateentry));
237 memset(&listbyattributes, 0, sizeof(listbyattributes));
239 if (fgets(line, 499, stdin) == NULL) {
244 register char **argp = args;
245 GetArgs(line, argp, &nargs);
248 if (!strcmp(oper, "cr")) {
249 fill_entry(&entry, argp, nargs);
250 display_entry(&entry, 0);
251 code = ubik_VL_CreateEntry(cstruct, 0, &entry);
252 printf("return code is %d\n", code);
253 } else if (!strcmp(oper, "rm")) {
254 sscanf(&(*argp)[0], "%d", &id);
256 sscanf(&(*argp)[0], "%d", &voltype);
257 code = ubik_VL_DeleteEntry(cstruct, 0, id, voltype);
258 printf("return code is %d\n", code);
259 } else if (!strcmp(oper, "re")) {
260 sscanf(&(*argp)[0], "%d", &id);
262 sscanf(&(*argp)[0], "%d", &voltype);
264 sscanf(&(*argp)[0], "%d", &releasetype);
266 fill_entry(&entry, argp, nargs);
267 display_entry(&entry, 0);
269 ubik_VL_ReplaceEntry(
270 cstruct, 0, id, voltype,
271 &entry, releasetype);
272 printf("return code is %d\n", code);
273 } else if (!strcmp(oper, "up")) {
274 sscanf(&(*argp)[0], "%d", &id);
276 sscanf(&(*argp)[0], "%d", &voltype);
278 sscanf(&(*argp)[0], "%d", &releasetype);
280 fill_update_entry(&updateentry, argp, nargs);
281 display_update_entry(&updateentry, 0);
283 ubik_VL_UpdateEntry(cstruct, 0, id, voltype,
284 &updateentry, releasetype);
285 printf("return code is %d\n", code);
286 } else if (!strcmp(oper, "ls")) {
287 afs_int32 index, count, next_index;
288 for (index = 0; 1; index = next_index) {
289 memset(&entry, 0, sizeof(entry));
291 ubik_VL_ListEntry(cstruct, 0, index, &count,
292 &next_index, &entry);
294 printf("VL_ListEntry returned code = %d\n", code);
299 display_entry(&entry, 0);
301 } else if (!strcmp(oper, "ldups")) {
302 afs_int32 index, count, num = 0, num1 = 0, next_index;
306 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
308 printf("Can't allocate memory...\n");
311 printf("Enumerating all entries in vldb...\n");
312 for (index = 0; 1; index = next_index) {
313 memset(&entry, 0, sizeof(entry));
315 ubik_VL_ListEntry(cstruct, 0, index, &count,
316 &next_index, &entry);
318 printf("VL_ListEntry returned code = %d\n", code);
324 if ((vl1 = GetVolume(entry.volumeId[0], &entry))) {
327 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
328 entry.volumeId[0], vl1->rwid, vl1->roid,
329 vl1->baid, vl1->name);
331 if ((vl1 = GetVolume(entry.volumeId[1], &entry))) {
334 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
335 entry.volumeId[1], vl1->rwid, vl1->roid,
336 vl1->baid, vl1->name);
338 if ((vl1 = GetVolume(entry.volumeId[2], &entry))) {
341 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
342 entry.volumeId[2], vl1->rwid, vl1->roid,
343 vl1->baid, vl1->name);
345 /*display_entry(&entry, 0); */
347 printf("(%d vldb entries found - %d duplicates)\n", num,
349 } else if (!strcmp(oper, "checkhash")) {
350 int index, count, num = 0, num1 = 0, num2 = 0, num3 =
351 0, num31 = 0, num4 = 0, num41 = 0, next_index;
352 struct vldbentry tentry;
355 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
357 printf("Can't allocate memory...\n");
360 printf("Volumes not found in main hash tables in vldb...\n");
361 for (index = 0; 1; index = next_index) {
362 memset(&entry, 0, sizeof(entry));
364 ubik_VL_ListEntry(cstruct, 0, index, &count,
365 &next_index, &entry);
367 printf("VL_ListEntry returned code = %d\n", code);
374 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
376 if (code == VL_NOENT) {
378 printf("\tVolume %s %d (not in namehash)\n",
379 entry.name, entry.volumeId[RWVOL]);
382 ubik_VL_GetEntryByID(cstruct, 0,
383 entry.volumeId[RWVOL], RWVOL, &tentry);
384 if (code == VL_NOENT) {
386 printf("\tVolume %s %d (not in rwid hash)\n",
387 entry.name, entry.volumeId[RWVOL]);
389 if (entry.volumeId[BACKVOL]) {
391 ubik_VL_GetEntryByID(cstruct, 0,
392 entry.volumeId[BACKVOL], BACKVOL,
395 if (code == VL_NOENT) {
397 printf("\tVolume %s %d (not in backup id hash)\n",
398 entry.name, entry.volumeId[BACKVOL]);
401 if (entry.volumeId[ROVOL]) {
403 ubik_VL_GetEntryByID(cstruct, 0,
404 entry.volumeId[ROVOL], ROVOL, &tentry);
406 if (code == VL_NOENT) {
408 printf("\tVolume %s %d (not in RO id hash)\n",
409 entry.name, entry.volumeId[ROVOL]);
414 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
415 num, num + num31 + num41, num, num31, num41);
417 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
420 ("\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",
421 num3, num31, num4, num41);
422 } else if (!strcmp(oper, "fixhash")) {
423 int index, count, num = 0, num1 = 0, num2 = 0, next_index, x =
425 struct vldbentry tentry;
428 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
430 printf("Can't allocate memory...\n");
434 ("Volumes not found in main hash tables in vldb will be fixed...\n");
435 memset(&updateentry, 0, sizeof(updateentry));
436 for (index = 0; 1; index = next_index) {
437 /* FIXME: n2 is never changed for some reason */
438 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
439 memset(&entry, 0, sizeof(entry));
441 ubik_VL_ListEntry(cstruct, 0, index, &count,
442 &next_index, &entry);
444 printf("VL_ListEntry returned code = %d\n", code);
451 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
453 if (code == VL_NOENT) {
456 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
457 printf("\tVolume %s %d (not in namehash)\n",
458 entry.name, entry.volumeId[RWVOL]);
460 ubik_VL_UpdateEntry(cstruct, 0,
461 entry.volumeId[RWVOL], -1, &updateentry,
465 printf("\tFailed to update volume %s (err=%d)\n",
470 ubik_VL_GetEntryByID(cstruct, 0,
471 entry.volumeId[RWVOL], RWVOL, &tentry);
472 if (code == VL_NOENT) {
475 updateentry.Mask = VLUPDATE_RWID;
476 updateentry.spares3 = entry.volumeId[RWVOL];
477 printf("\tVolume %s %d (not in rw id hash)\n",
478 entry.name, entry.volumeId[RWVOL]);
480 ubik_VL_UpdateEntryByName(cstruct, 0,
481 entry.name, &updateentry, 0);
483 printf("\tFailed to update volume %s (err=%d)\n",
489 if (entry.volumeId[BACKVOL] && !n2) {
491 ubik_VL_GetEntryByID(cstruct, 0,
492 entry.volumeId[BACKVOL], BACKVOL,
494 if (code == VL_NOENT) {
497 updateentry.Mask = VLUPDATE_BACKUPID;
498 updateentry.BackupId = entry.volumeId[BACKVOL];
499 printf("\tVolume %s %d (not in backup id hash)\n",
500 entry.name, entry.volumeId[BACKVOL]);
502 ubik_VL_UpdateEntry(cstruct, 0,
503 entry.volumeId[RWVOL], -1,
507 ("\tFailed to update volume %s (err=%d)\n",
513 if (entry.volumeId[ROVOL && !n2]) {
515 ubik_VL_GetEntryByID(cstruct, 0,
516 entry.volumeId[ROVOL], ROVOL, &tentry);
517 if (code == VL_NOENT) {
520 updateentry.Mask = VLUPDATE_READONLYID;
521 updateentry.ReadOnlyId = entry.volumeId[ROVOL];
522 printf("\tVolume %s %d (not in RO id hash)\n",
523 entry.name, entry.volumeId[ROVOL]);
525 ubik_VL_UpdateEntry(cstruct, 0,
526 entry.volumeId[RWVOL], -1,
530 ("\tFailed to update volume %s (err=%d)\n",
538 ("\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",
540 } else if (!strcmp(oper, "la")) {
543 struct vldbentry *entry;
545 memset(&entries, 0, sizeof(entries));
546 fill_listattributes_entry(&listbyattributes, argp, nargs);
547 display_listattributes_entry(&listbyattributes, 0);
549 ubik_VL_ListAttributes(cstruct, 0,
550 &listbyattributes, &nentries, &entries);
552 printf("VL_ListAttributes returned code = %d\n", code);
555 entry = (struct vldbentry *)entries.bulkentries_val;
556 for (i = 0; i < nentries; i++, entry++)
557 display_entry(entry, 0);
558 if (entries.bulkentries_val)
559 free((char *)entries.bulkentries_val);
560 } else if (!strcmp(oper, "lan2")) {
561 int nentries, i, si, nsi, t = 0;
562 nbulkentries entries;
563 struct nvldbentry *entry;
566 /* The volume name to search for (supports wildcarding) */
568 strcpy(name, argp[0]);
574 fill_listattributes_entry(&listbyattributes, argp, nargs);
575 display_listattributes_entry(&listbyattributes, 0);
576 printf("Wildcard VolName: '%s'\n", name);
578 for (si = 0; si != -1; si = nsi) {
580 memset(&entries, 0, sizeof(entries));
582 ubik_VL_ListAttributesN2(cstruct, 0,
583 &listbyattributes, name, si, &nentries,
586 printf("VL_ListAttributesN2 returned code = %d\n",
592 entry = (struct nvldbentry *)entries.nbulkentries_val;
593 for (i = 0; i < nentries; i++, entry++)
594 display_entryN(entry, 0);
595 if (entries.nbulkentries_val)
596 free((char *)entries.nbulkentries_val);
598 printf("--- %d volumes ---\n", t);
599 } else if (!strcmp(oper, "ln")) {
601 vldb_list linkedvldbs;
602 vldblist vllist, vllist1;
604 fill_listattributes_entry(&listbyattributes, argp, nargs);
605 display_listattributes_entry(&listbyattributes, 0);
606 memset(&linkedvldbs, 0, sizeof(vldb_list));
608 ubik_VL_LinkedList(cstruct, 0, &listbyattributes,
609 &netries, &linkedvldbs);
611 printf("VL_LinkedList returned code = %d\n", code);
614 printf("Found %d entr%s\n", netries,
615 (netries == 1 ? "y" : "ies"));
616 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
617 vllist1 = vllist->next_vldb;
618 display_entry((struct vldbentry *) &vllist->VldbEntry, 0);
621 } else if (!strcmp(oper, "lnn")) {
623 nvldb_list linkedvldbs;
624 nvldblist vllist, vllist1;
626 fill_listattributes_entry(&listbyattributes, argp, nargs);
627 display_listattributes_entry(&listbyattributes, 0);
628 memset(&linkedvldbs, 0, sizeof(vldb_list));
630 ubik_VL_LinkedListN(cstruct, 0, &listbyattributes,
631 &netries, &linkedvldbs);
633 printf("VL_LinkedList returned code = %d\n", code);
636 printf("Found %d entr%s\n", netries,
637 (netries == 1 ? "y" : "ies"));
638 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
639 vllist1 = vllist->next_vldb;
640 display_entry((struct vldbentry *)&vllist->VldbEntry, 0);
641 free((char *)vllist);
643 } else if (!strcmp(oper, "di")) {
644 sscanf(&(*argp)[0], "%d", &id);
646 sscanf(&(*argp)[0], "%d", &voltype);
648 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
650 display_entry(&entry, code);
651 printf("return code is %d.\n", code);
652 } else if (!strcmp(oper, "rmnh")) {
653 sscanf(&(*argp)[0], "%d", &id);
655 sscanf(&(*argp)[0], "%d", &voltype);
657 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
659 display_entry(&entry, code);
660 memset(&updateentry, 0, sizeof(updateentry));
661 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
662 printf("\tRehashing namehash table for %s (%d)\n", entry.name,
663 entry.volumeId[RWVOL]);
665 ubik_VL_UpdateEntry(cstruct, 0,
666 entry.volumeId[RWVOL], -1, &updateentry, 0);
668 printf("\tFailed to update volume %s (err=%d)\n",
671 printf("return code is %d.\n", code);
672 } else if (!strcmp(oper, "undelete")) {
673 afs_int32 index, count, next_index;
675 memset(&updateentry, 0, sizeof(updateentry));
676 sscanf(&(*argp)[0], "%d", &id);
678 sscanf(&(*argp)[0], "%d", &voltype);
679 if (voltype < 0 && voltype > 2) {
680 printf("Illegal voltype; must be 0, 1 or 2\n");
683 printf("Searching vldb for volume %d...\n", id);
684 for (index = 0; 1; index = next_index) {
685 memset(&entry, 0, sizeof(entry));
687 ubik_VL_ListEntry(cstruct, 0, index, &count,
688 &next_index, &entry);
690 printf("VL_ListEntry returned code = %d\n", code);
695 if (entry.volumeId[voltype] == id) {
696 printf("\nThe current contents of the vldb for %d:\n",
698 display_entry(&entry, 0);
700 if (entry.flags & VLDELETED) {
701 updateentry.Mask = VLUPDATE_FLAGS;
702 updateentry.flags = entry.flags;
703 updateentry.flags &= ~VLDELETED;
705 ("\tUndeleting vldb entry for vol %d (%s)\n",
708 ubik_VL_UpdateEntry(cstruct, 0, id, -1,
712 ("\tFailed to update volume %s (err=%d)\n",
716 printf("Entry not deleted; ignored\n");
721 } else if (!strcmp(oper, "dn")) {
724 ubik_VL_GetEntryByNameO(cstruct, 0, vname, &entry);
725 display_entry(&entry, code);
726 printf("return code is %d.\n", code);
727 } else if (!strcmp(oper, "nv")) {
728 unsigned int newvolid;
729 sscanf(&(*argp)[0], "%d", &id);
731 ubik_VL_GetNewVolumeId(cstruct, 0, id, &newvolid);
733 printf("Current Max volid is (in hex):0x%x\n", newvolid);
734 printf("return code is %d\n", code);
735 } else if (!strcmp(oper, "gs")) {
737 vital_vlheader vital_header;
739 ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
741 dump_stats(&stats, &vital_header);
742 printf("return code is %d.\n", code);
743 } else if (!strcmp(oper, "ga")) {
747 struct VLCallBack vlcb;
749 addrs.bulkaddrs_val = 0;
750 addrs.bulkaddrs_len = 0;
751 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
752 0 /*spare2 */ , &vlcb,
755 printf("VL_GetAddrs returned code = %d\n", code);
758 addrp = addrs.bulkaddrs_val;
759 for (i = 0; i < nentries; i++, addrp++) {
760 if ((*addrp & 0xff000000) == 0xff000000)
761 printf("[0x%x %u] (special multi-homed entry)\n",
764 printf("[0x%x %u] %s\n", *addrp, *addrp,
765 hostutil_GetNameByINet(ntohl(*addrp)));
767 free((char *)addrs.bulkaddrs_val);
768 } else if (!strcmp(oper, "gau")) {
772 struct VLCallBack vlcb;
774 addrs.bulkaddrs_val = 0;
775 addrs.bulkaddrs_len = 0;
776 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
777 0 /*spare2 */ , &vlcb,
780 printf("VL_GetAddrs returned code = %d\n", code);
783 addrp = addrs.bulkaddrs_val;
784 for (i = 0; i < nentries; i++, addrp++) {
785 if ((*addrp & 0xff000000) == 0xff000000) {
786 int mhnentries, unique;
787 struct in_addr hostAddr;
790 ListAddrByAttributes attrs;
793 printf("[0x%x %u] (special multi-homed entry)\n",
795 attrs.Mask = VLADDR_INDEX;
796 mhaddrs.bulkaddrs_val = 0;
797 mhaddrs.bulkaddrs_len = 0;
798 attrs.index = *addrp & 0x00ffffff;
801 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
802 &unique, &mhnentries, &mhaddrs);
804 printf("VL_GetAddrsU returned code = %d\n", code);
808 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
809 attrs.index, uuid.time_low, uuid.time_mid,
810 uuid.time_hi_and_version,
811 uuid.clock_seq_hi_and_reserved,
812 uuid.clock_seq_low, uuid.node[0], uuid.node[1],
813 uuid.node[2], uuid.node[3], uuid.node[4],
814 uuid.node[5], unique);
815 mhaddrp = mhaddrs.bulkaddrs_val;
816 for (j = 0; j < mhnentries; j++) {
817 mhaddrp[j] = ntohl(mhaddrp[j]);
818 hostAddr.s_addr = mhaddrp[j];
819 printf("\t%s (%s)\n", inet_ntoa(hostAddr),
820 hostutil_GetNameByINet(mhaddrp[j]));
822 if (mhaddrs.bulkaddrs_val)
823 free((char *)mhaddrs.bulkaddrs_val);
825 printf("[0x%x %u] %s\n", *addrp, *addrp,
826 hostutil_GetNameByINet(ntohl(*addrp)));
829 free((char *)addrs.bulkaddrs_val);
830 } else if (!strcmp(oper, "mhc")) {
831 afs_int32 serveraddrs[MAXSERVERID + 1][VL_MAXIPADDRS_PERMH];
832 afs_int32 serveraddrtype[MAXSERVERID + 1];
833 int nentries1, nentries2, i, j, x, y, unique, found;
834 afs_uint32 *addrp1, *addrp2;
835 bulkaddrs addrs1, addrs2;
836 struct VLCallBack vlcb;
837 ListAddrByAttributes attrs;
839 afs_int32 base, index;
841 for (i = 0; i < MAXSERVERID + 1; i++) {
842 serveraddrtype[i] = 0;
843 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
844 serveraddrs[i][j] = 0;
847 /* Collect a list of all registered IP addresses */
848 addrs1.bulkaddrs_val = 0;
849 addrs1.bulkaddrs_len = 0;
851 ubik_VL_GetAddrs(cstruct, 0, 0, 0, &vlcb,
852 &nentries1, &addrs1);
854 printf("VL_GetAddrs returned code = %d\n", code);
857 addrp1 = addrs1.bulkaddrs_val;
858 for (i = 0; i < nentries1; i++, addrp1++) {
859 if ((*addrp1 & 0xff000000) != 0xff000000) {
860 serveraddrs[i][0] = ntohl(*addrp1);
861 serveraddrtype[i] = 1;
863 /* It's multihomed. Get all of its addresses */
864 serveraddrtype[i] = 2;
865 base = (*addrp1 >> 16) & 0xff;
866 index = *addrp1 & 0xffff;
868 addrs2.bulkaddrs_val = 0;
869 addrs2.bulkaddrs_len = 0;
870 attrs.Mask = VLADDR_INDEX;
871 attrs.index = (base * VL_MHSRV_PERBLK) + index;
873 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
874 &unique, &nentries2, &addrs2);
876 printf("VL_GetAddrsU returned code = %d\n", code);
880 addrp2 = addrs2.bulkaddrs_val;
881 for (j = 0; j < nentries2; j++) {
882 serveraddrs[i][j] = ntohl(addrp2[j]);
884 free((char *)addrs2.bulkaddrs_val);
888 if (serveraddrtype[i] == 1) {
889 printf("%u\n", serveraddrs[i][0]);
892 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
893 if (serveraddrs[i][j])
894 printf(" %u", serveraddrs[i][j]);
899 free((char *)addrs1.bulkaddrs_val);
901 /* Look for any duplicates */
902 for (i = 0; i < MAXSERVERID + 1; i++) {
903 if (!serveraddrtype[i])
905 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
906 if (!serveraddrs[i][j])
910 for (x = i + 1; x < MAXSERVERID + 1; x++) {
911 if (!serveraddrtype[x])
913 for (y = 0; y < VL_MAXIPADDRS_PERMH; y++) {
914 if (!serveraddrs[x][y])
916 if (serveraddrs[i][j] == serveraddrs[x][y]) {
917 serveraddrs[x][y] = 0;
924 ("Found %d entries of IP address %u (0x%x)\n",
925 found + 1, serveraddrs[i][j],
931 /*----------------------------------------*/
933 } else if (!strcmp(oper, "regaddr")) {
935 afs_uint32 *addrp, tad;
939 memset(&uuid, 0, sizeof(uuid));
940 sscanf(&(*argp)[0], "%d", &i);
942 memcpy(uuid.node, &i, sizeof(i));
944 if (nargs < 0 || nargs > 16) {
945 printf("Illegal # entries = %d\n", nargs);
948 addrp = (afs_uint32 *) malloc(20 * 4);
949 addrs.bulkaddrs_val = addrp;
950 addrs.bulkaddrs_len = nargs;
952 sscanf(&(*argp)[0], "%d", &tad);
957 ubik_VL_RegisterAddrs(cstruct, 0, &uuid,
958 0 /*spare */ , &addrs);
960 printf("VL_RegisterAddrs returned code = %d\n", code);
963 } else if (!strcmp(oper, "ca")) {
964 struct hostent *h1, *h2;
967 printf("changing %s", *argp);
968 h1 = hostutil_GetHostByName(&(*argp)[0]);
970 printf("cmdebug: can't resolve address for host %s",
974 memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32));
977 printf(" to %s\n", *argp);
978 h2 = hostutil_GetHostByName(&(*argp)[0]);
980 printf("cmdebug: can't resolve address for host %s",
984 memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32));
986 printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2));
988 ubik_VL_ChangeAddr(cstruct, 0, ntohl(a1),
991 printf("VL_ChangeAddr returned code = %d\n", code);
994 } else if (!strcmp(oper, "caid")) {
997 sscanf(&(*argp)[0], "%d", &a1);
998 printf("changing %d (0x%x)", a1, a1);
1000 sscanf(&(*argp)[0], "%d", &a2);
1001 printf(" to %d (0x%x)\n", a2, a2);
1002 code = ubik_VL_ChangeAddr(cstruct, 0, a1, a2);
1004 printf("VL_ChangeAddr returned code = %d\n", code);
1007 } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h"))
1009 else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
1012 printf("Unknown oper!\n");
1019 #include "AFS_component_version_number.c"
1022 main(int argc, char **argv)
1024 register struct cmd_syndesc *ts;
1027 strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
1028 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "initialize the program");
1029 cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL,
1030 "Cell configuration directory");
1031 cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL,
1032 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1033 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1034 "Run it without authentication");
1035 cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL,
1036 "vldb server to talk to");
1037 cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL,
1038 "cellname '-host' belongs to (required for auth conns)");
1039 cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL,
1040 "print vldb statistics (non interactive)");
1041 code = cmd_Dispatch(argc, argv);
1047 fill_entry(struct vldbentry *entry, char **argp, int nargs)
1054 sscanf(&(*argp)[0], "%d", &entry->spares3);
1056 sscanf(&(*argp)[0], "%d", &entry->nServers);
1057 strcpy(entry->name, name);
1058 for (i = 0; i < entry->nServers; i++) {
1060 sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]);
1062 for (i = 0; i < entry->nServers; i++) {
1064 sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]);
1066 for (i = 0; i < entry->nServers; i++) {
1068 sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]);
1070 for (i = 0; i < MAXTYPES; i++) {
1072 sscanf(&(*argp)[0], "%u", &entry->volumeId[i]);
1075 sscanf(&(*argp)[0], "%d", &entry->flags);
1077 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1081 fill_update_entry(struct VldbUpdateEntry *entry, char **argp, int nargs)
1088 if (strcmp(name, "null")) {
1089 strcpy(entry->name, name);
1090 entry->Mask |= VLUPDATE_VOLUMENAME;
1093 sscanf(&(*argp)[0], "%d", &entry->flags);
1094 if (entry->flags != -1)
1095 entry->Mask |= VLUPDATE_FLAGS;
1097 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1098 if (entry->flags != -1)
1099 entry->Mask |= VLUPDATE_CLONEID;
1101 sscanf(&(*argp)[0], "%u", &entry->ReadOnlyId);
1102 if (entry->ReadOnlyId != -1)
1103 entry->Mask |= VLUPDATE_READONLYID;
1105 sscanf(&(*argp)[0], "%u", &entry->BackupId);
1106 if (entry->BackupId != -1)
1107 entry->Mask |= VLUPDATE_BACKUPID;
1109 sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites);
1110 if (entry->nModifiedRepsites != -1)
1111 entry->Mask |= VLUPDATE_REPSITES;
1112 for (i = 0; i < entry->nModifiedRepsites; i++) {
1114 sscanf(&(*argp)[0], "%x", &Mask);
1116 sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]);
1118 sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]);
1119 if (Mask & VLUPDATE_REPS_DELETE)
1120 entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE;
1121 if (Mask & VLUPDATE_REPS_MODSERV) {
1123 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1124 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV;
1125 } else if (Mask & VLUPDATE_REPS_MODPART) {
1127 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1128 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART;
1129 } else if (Mask & VLUPDATE_REPS_MODFLAG) {
1131 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1132 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG;
1133 } else if (Mask & VLUPDATE_REPS_ADD) {
1135 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1137 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1139 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1140 entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD;
1146 fill_listattributes_entry(struct VldbListByAttributes *entry, char **argp,
1153 entry->server = ntohl(GetServer(argp[0]));
1154 sscanf(&(*argp)[0], "%d", &entry->server);
1155 if (entry->server != 0)
1156 entry->Mask |= VLLIST_SERVER;
1161 sscanf(&(*argp)[0], "%d", &entry->partition);
1162 if (entry->partition != -1)
1163 entry->Mask |= VLLIST_PARTITION;
1168 sscanf(&(*argp)[0], "%d", &entry->volumeid);
1169 if (entry->volumeid != -1)
1170 entry->Mask |= VLLIST_VOLUMEID;
1175 sscanf(&(*argp)[0], "%d", &entry->flag);
1176 if (entry->flag != -1)
1177 entry->Mask |= VLLIST_FLAG;
1181 display_listattributes_entry(struct VldbListByAttributes *entry, int error)
1185 printf("\nList entry values (Mask=%x)\n", entry->Mask);
1186 if (entry->Mask & VLLIST_SERVER)
1187 printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff,
1188 (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff,
1189 (entry->server) & 0xff);
1190 if (entry->Mask & VLLIST_PARTITION)
1191 printf("\tPartition: %d\n", entry->partition);
1192 if (entry->Mask & VLLIST_VOLUMEID)
1193 printf("\tVolumeId: %u\n", entry->volumeid);
1194 if (entry->Mask & VLLIST_FLAG)
1195 printf("\tFlag: %x\n", entry->flag);
1199 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1202 display_entry(struct vldbentry *entry, int error)
1208 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1209 entry->name, entry->volumeId[RWVOL], entry->flags);
1210 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1211 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1213 printf("nServers=%d\n", entry->nServers);
1214 printf("ServerNumber\tServerPart\tserverFlag\n");
1215 for (i = 0; i < entry->nServers; i++)
1216 printf("%12u\t%10d\t%10x\n", entry->serverNumber[i],
1217 entry->serverPartition[i], entry->serverFlags[i]);
1221 display_entryN(struct nvldbentry *entry, int error)
1227 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1228 entry->name, entry->volumeId[RWVOL], entry->flags);
1229 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1230 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1232 printf("nServers=%d\n", entry->nServers);
1233 printf("ServerNumber\tServerPart\tserverFlag\n");
1234 ei = entry->matchindex & 0xffff;
1235 et = (entry->matchindex >> 16) & 0xffff;
1236 for (i = 0; i < entry->nServers; i++) {
1237 printf("%12u\t%10d\t%10x", entry->serverNumber[i],
1238 entry->serverPartition[i], entry->serverFlags[i]);
1240 printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO"));
1247 display_update_entry(struct VldbUpdateEntry *entry, int error)
1253 printf("\nUpdate entry values (Mask=%x)\n", entry->Mask);
1254 if (entry->Mask & VLUPDATE_VOLUMENAME)
1255 printf("\tNew name: %s\n", entry->name);
1256 if (entry->Mask & VLUPDATE_FLAGS)
1257 printf("\tNew flags: %X\n", entry->flags);
1258 if (entry->Mask & VLUPDATE_CLONEID)
1259 printf("\tNew CloneId: %X\n", entry->cloneId);
1260 if (entry->Mask & VLUPDATE_READONLYID)
1261 printf("\tNew RO id: %d\n", entry->ReadOnlyId);
1262 if (entry->Mask & VLUPDATE_BACKUPID)
1263 printf("\tNew BACKUP id: %d\n", entry->BackupId);
1264 if (entry->Mask & VLUPDATE_REPSITES) {
1265 printf("\tRepsites info:\n");
1266 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1267 for (i = 0; i < entry->nModifiedRepsites; i++) {
1268 printf("\t%4x\t%7u\t%5d", entry->RepsitesMask[i],
1269 entry->RepsitesTargetServer[i],
1270 entry->RepsitesTargetPart[i]);
1271 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1272 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV))
1273 printf("\t%7u", entry->RepsitesNewServer[i]);
1275 printf("\t-------");
1276 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1277 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART))
1278 printf("\t%5d", entry->RepsitesNewPart[i]);
1281 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1282 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG))
1283 printf("\t%5x\n", entry->RepsitesNewFlags[i]);
1285 printf("\t-----\n");
1291 dump_stats(vldstats *stats, vital_vlheader *vital_header)
1295 time_t start_time = stats->start_time;
1297 afs_ctime(&start_time, strg, sizeof(strg));
1298 strg[strlen(strg) - 1] = 0;
1299 printf("Dynamic statistics stats (starting time: %s):\n", strg);
1300 printf("OpcodeName\t# Requests\t# Aborts\n");
1301 for (i = 0; i < VL_NUMBER_OPCODESX; i++)
1302 printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i],
1304 printf("\nVldb header stats (version=%d)\n",
1305 ntohl(vital_header->vldbversion));
1306 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1307 ntohl(vital_header->headersize), ntohl(vital_header->allocs),
1308 ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId));
1309 for (i = 0; i < MAXTYPES; i++)
1310 printf("total %s entries=%d\n", volumetype_string(i),
1311 ntohl(vital_header->totalEntries[i]));
1315 GetArgs(char *line, char **args, int *nargs)
1319 register char *last = line;
1320 while (isspace(*line))
1326 *args++ = line, (*nargs)++;
1327 while (*line && !isspace(*line))
1335 printf("Valid Commands:\n");
1337 printf(" CreateEntry:\n");
1339 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1341 printf(" DeleteEntry:\n");
1342 printf("\trm <volid> <voltype>\n");
1344 printf(" ReplaceEntry:\n");
1345 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1347 printf(" UpdateEntry:\n");
1349 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1351 printf(" ListEntry:\n");
1354 printf(" Find duplicate entries of a volume\n");
1355 printf("\tldups\n");
1357 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1358 printf("\tcheckhash\n");
1361 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1362 printf("\tfixhash\n");
1364 printf(" ListAttributes:\n");
1365 printf("\tla [server] [partition] [volumeid] [flag]\n");
1367 printf(" ListAttributesN2:\n");
1368 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1370 printf(" GetEntryByID:\n");
1371 printf("\tdi <volid> <voltype>\n");
1373 printf(" UpdateEntry (refresh namehash table):\n");
1374 printf("\trmnh <volid> <voltype>\n");
1376 printf(" GetEntryByName:\n");
1377 printf("\tdn <volname> <voltype>\n");
1379 printf(" UpdateEntry (undelete a vol entry):\n");
1380 printf("\tundelete <volid> <voltype>\n");
1382 * printf(" LinkedList\n");
1383 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1385 * printf(" LinkedListN\n");
1386 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1388 printf(" GetNewVoumeId:\n");
1389 printf("\tnv <bump-count>\n");
1391 printf(" GetStats:\n");
1394 printf(" ChangeAddr:\n");
1395 printf("\tca <oldmachname> <newmachname>\n");
1398 * printf(" ChangeAddr\n");
1399 * printf("\t:caid <oldaddr> <newaddr>\n");
1401 printf(" GetAddrs:\n");
1404 printf(" GetAddrsU:\n");
1407 printf(" RegisterAddrs:\n");
1408 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1410 printf("\tmisc: q, quit, ?, h\n");