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 <WINNT/afsevent.h>
19 #ifdef HAVE_SYS_FILE_H
24 #include <afs/afsutil.h>
27 #include <rx/rx_globals.h>
29 #include <afs/cellconfig.h>
37 void fill_listattributes_entry(struct VldbListByAttributes *, char **, int);
38 void display_listattributes_entry(struct VldbListByAttributes *,int);
39 void display_entry(struct vldbentry *, int);
40 void display_entryN(struct nvldbentry *, int);
41 void display_update_entry(struct VldbUpdateEntry *, int);
42 void dump_stats(vldstats *, vital_vlheader *);
43 void GetArgs(char *, char **, int *);
44 void print_usage(void);
45 void fill_entry(struct vldbentry *, char **, int);
46 void fill_update_entry(struct VldbUpdateEntry *, char **, int);
48 #define VL_NUMBER_OPCODESX 34
49 static char *opcode_names[VL_NUMBER_OPCODESX] = {
96 struct Vlent *VLa[NVOLS];
97 #define VHash(avol) ((avol)&(NVOLS-1))
98 struct Vlent *VL, *SVL;
100 struct ubik_client *cstruct;
101 struct rx_connection *serverconns[MAXSERVERS];
102 char confdir[AFSDIR_PATH_MAX];
106 GetVolume(int vol, struct vldbentry *entry)
114 for (vl = VLa[i]; vl; vl = vl->next) {
115 if ((vl->rwid == vol && vol != entry->volumeId[0])
116 || (vl->roid == vol && vol != entry->volumeId[1])
117 || (vl->baid == vol && vol != entry->volumeId[2])) {
121 VL->rwid = entry->volumeId[0];
122 VL->roid = entry->volumeId[1];
123 VL->baid = entry->volumeId[2];
124 strcpy(entry->name, VL->name);
127 if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */
128 printf("Too many entries (> %d)\n", ALLOCNT);
135 /* Almost identical's to pr_Initialize in vlserver/pruser.c */
137 vl_Initialize(char *confDir, int secFlags, int server, char *cellp)
139 return ugen_ClientInitServer(confDir, cellp, secFlags, &cstruct,
140 MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
141 server, htons(AFSCONF_VLDBPORT));
144 /* return host address in network byte order */
146 GetServer(char *aname)
153 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
155 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
156 return htonl(addr); /* convert to network order (128 in byte 0) */
158 th = gethostbyname(aname);
161 memcpy(&addr, th->h_addr, sizeof(addr));
167 handleit(struct cmd_syndesc *as, void *arock)
170 afs_int32 code, server = 0, sawserver = 0;
171 afs_int32 id, voltype;
172 struct vldbentry entry;
174 struct VldbUpdateEntry updateentry;
175 struct VldbListByAttributes listbyattributes;
176 int secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
178 if ((ti = as->parms[0].items)) /* -cellpath <dir> */
179 strcpy(confdir, ti->data);
180 if (as->parms[1].items) /* -server */
181 strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH);
182 if (as->parms[2].items) /* -noauth */
183 secFlags |= AFSCONF_SECOPTS_NOAUTH;
184 if ((ti = as->parms[3].items)) { /* -host */
185 server = GetServer(ti->data);
187 printf("server '%s' not found in host table\n", ti->data);
192 if (sawserver && !as->parms[2].items && (!(ti = as->parms[4].items))) {
194 ("Must also specify the -cell' option along with -host for authenticated conns\n");
197 if ((ti = as->parms[4].items)) { /* -cell */
200 if ((code = vl_Initialize(confdir, secFlags, server, cellp))) {
201 printf("Couldn't initialize vldb library (code=%d).\n", code);
205 if (as->parms[5].items) { /* -gstats */
207 vital_vlheader vital_header;
208 code = ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
210 dump_stats(&stats, &vital_header);
216 int nargs, releasetype;
217 memset(&entry, 0, sizeof(entry));
218 memset(&updateentry, 0, sizeof(updateentry));
219 memset(&listbyattributes, 0, sizeof(listbyattributes));
221 if (fgets(line, 499, stdin) == NULL) {
228 GetArgs(line, argp, &nargs);
232 } else if (!strcmp(oper, "cr")) {
233 fill_entry(&entry, argp, nargs);
234 display_entry(&entry, 0);
235 code = ubik_VL_CreateEntry(cstruct, 0, &entry);
236 printf("return code is %d\n", code);
237 } else if (!strcmp(oper, "rm")) {
238 sscanf(&(*argp)[0], "%d", &id);
240 sscanf(&(*argp)[0], "%d", &voltype);
241 code = ubik_VL_DeleteEntry(cstruct, 0, id, voltype);
242 printf("return code is %d\n", code);
243 } else if (!strcmp(oper, "re")) {
244 sscanf(&(*argp)[0], "%d", &id);
246 sscanf(&(*argp)[0], "%d", &voltype);
248 sscanf(&(*argp)[0], "%d", &releasetype);
250 fill_entry(&entry, argp, nargs);
251 display_entry(&entry, 0);
253 ubik_VL_ReplaceEntry(
254 cstruct, 0, id, voltype,
255 &entry, releasetype);
256 printf("return code is %d\n", code);
257 } else if (!strcmp(oper, "up")) {
258 sscanf(&(*argp)[0], "%d", &id);
260 sscanf(&(*argp)[0], "%d", &voltype);
262 sscanf(&(*argp)[0], "%d", &releasetype);
264 fill_update_entry(&updateentry, argp, nargs);
265 display_update_entry(&updateentry, 0);
267 ubik_VL_UpdateEntry(cstruct, 0, id, voltype,
268 &updateentry, releasetype);
269 printf("return code is %d\n", code);
270 } else if (!strcmp(oper, "ls")) {
271 afs_int32 index, count, next_index;
272 for (index = 0; 1; index = next_index) {
273 memset(&entry, 0, sizeof(entry));
275 ubik_VL_ListEntry(cstruct, 0, index, &count,
276 &next_index, &entry);
278 printf("VL_ListEntry returned code = %d\n", code);
283 display_entry(&entry, 0);
285 } else if (!strcmp(oper, "ldups")) {
286 afs_int32 index, count, num = 0, num1 = 0, next_index;
289 VL = SVL = malloc(ALLOCNT * sizeof(struct Vlent));
291 printf("Can't allocate memory...\n");
294 printf("Enumerating all entries in vldb...\n");
295 for (index = 0; 1; index = next_index) {
296 memset(&entry, 0, sizeof(entry));
298 ubik_VL_ListEntry(cstruct, 0, index, &count,
299 &next_index, &entry);
301 printf("VL_ListEntry returned code = %d\n", code);
307 if ((vl1 = GetVolume(entry.volumeId[0], &entry))) {
310 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
311 entry.volumeId[0], vl1->rwid, vl1->roid,
312 vl1->baid, vl1->name);
314 if ((vl1 = GetVolume(entry.volumeId[1], &entry))) {
317 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
318 entry.volumeId[1], vl1->rwid, vl1->roid,
319 vl1->baid, vl1->name);
321 if ((vl1 = GetVolume(entry.volumeId[2], &entry))) {
324 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
325 entry.volumeId[2], vl1->rwid, vl1->roid,
326 vl1->baid, vl1->name);
328 /*display_entry(&entry, 0); */
330 printf("(%d vldb entries found - %d duplicates)\n", num,
332 } else if (!strcmp(oper, "checkhash")) {
333 int index, count, num = 0, num1 = 0, num2 = 0, num3 =
334 0, num31 = 0, num4 = 0, num41 = 0, next_index;
335 struct vldbentry tentry;
337 VL = SVL = malloc(ALLOCNT * sizeof(struct Vlent));
339 printf("Can't allocate memory...\n");
342 printf("Volumes not found in main hash tables in vldb...\n");
343 for (index = 0; 1; index = next_index) {
344 memset(&entry, 0, sizeof(entry));
346 ubik_VL_ListEntry(cstruct, 0, index, &count,
347 &next_index, &entry);
349 printf("VL_ListEntry returned code = %d\n", code);
356 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
358 if (code == VL_NOENT) {
360 printf("\tVolume %s %d (not in namehash)\n",
361 entry.name, entry.volumeId[RWVOL]);
364 ubik_VL_GetEntryByID(cstruct, 0,
365 entry.volumeId[RWVOL], RWVOL, &tentry);
366 if (code == VL_NOENT) {
368 printf("\tVolume %s %d (not in rwid hash)\n",
369 entry.name, entry.volumeId[RWVOL]);
371 if (entry.volumeId[BACKVOL]) {
373 ubik_VL_GetEntryByID(cstruct, 0,
374 entry.volumeId[BACKVOL], BACKVOL,
377 if (code == VL_NOENT) {
379 printf("\tVolume %s %d (not in backup id hash)\n",
380 entry.name, entry.volumeId[BACKVOL]);
383 if (entry.volumeId[ROVOL]) {
385 ubik_VL_GetEntryByID(cstruct, 0,
386 entry.volumeId[ROVOL], ROVOL, &tentry);
388 if (code == VL_NOENT) {
390 printf("\tVolume %s %d (not in RO id hash)\n",
391 entry.name, entry.volumeId[ROVOL]);
396 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
397 num, num + num31 + num41, num, num31, num41);
399 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
402 ("\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",
403 num3, num31, num4, num41);
404 } else if (!strcmp(oper, "fixhash")) {
405 int index, count, num = 0, num1 = 0, num2 = 0, next_index, x =
407 struct vldbentry tentry;
409 VL = SVL = malloc(ALLOCNT * sizeof(struct Vlent));
411 printf("Can't allocate memory...\n");
415 ("Volumes not found in main hash tables in vldb will be fixed...\n");
416 memset(&updateentry, 0, sizeof(updateentry));
417 for (index = 0; 1; index = next_index) {
418 memset(&entry, 0, sizeof(entry));
420 ubik_VL_ListEntry(cstruct, 0, index, &count,
421 &next_index, &entry);
423 printf("VL_ListEntry returned code = %d\n", code);
430 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
432 if (code == VL_NOENT) {
434 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
435 printf("\tVolume %s %d (not in namehash)\n",
436 entry.name, entry.volumeId[RWVOL]);
438 ubik_VL_UpdateEntry(cstruct, 0,
439 entry.volumeId[RWVOL], -1, &updateentry,
443 printf("\tFailed to update volume %s (err=%d)\n",
448 ubik_VL_GetEntryByID(cstruct, 0,
449 entry.volumeId[RWVOL], RWVOL, &tentry);
450 if (code == VL_NOENT) {
453 updateentry.Mask = VLUPDATE_RWID;
454 updateentry.spares3 = entry.volumeId[RWVOL];
455 printf("\tVolume %s %d (not in rw id hash)\n",
456 entry.name, entry.volumeId[RWVOL]);
458 ubik_VL_UpdateEntryByName(cstruct, 0,
459 entry.name, &updateentry, 0);
461 printf("\tFailed to update volume %s (err=%d)\n",
467 if (entry.volumeId[BACKVOL]) {
469 ubik_VL_GetEntryByID(cstruct, 0,
470 entry.volumeId[BACKVOL], BACKVOL,
472 if (code == VL_NOENT) {
474 updateentry.Mask = VLUPDATE_BACKUPID;
475 updateentry.BackupId = entry.volumeId[BACKVOL];
476 printf("\tVolume %s %d (not in backup id hash)\n",
477 entry.name, entry.volumeId[BACKVOL]);
479 ubik_VL_UpdateEntry(cstruct, 0,
480 entry.volumeId[RWVOL], -1,
484 ("\tFailed to update volume %s (err=%d)\n",
490 if (entry.volumeId[ROVOL]) {
492 ubik_VL_GetEntryByID(cstruct, 0,
493 entry.volumeId[ROVOL], ROVOL, &tentry);
494 if (code == VL_NOENT) {
496 updateentry.Mask = VLUPDATE_READONLYID;
497 updateentry.ReadOnlyId = entry.volumeId[ROVOL];
498 printf("\tVolume %s %d (not in RO id hash)\n",
499 entry.name, entry.volumeId[ROVOL]);
501 ubik_VL_UpdateEntry(cstruct, 0,
502 entry.volumeId[RWVOL], -1,
506 ("\tFailed to update volume %s (err=%d)\n",
514 ("\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",
516 } else if (!strcmp(oper, "la")) {
519 struct vldbentry *entry;
521 memset(&entries, 0, sizeof(entries));
522 fill_listattributes_entry(&listbyattributes, argp, nargs);
523 display_listattributes_entry(&listbyattributes, 0);
525 ubik_VL_ListAttributes(cstruct, 0,
526 &listbyattributes, &nentries, &entries);
528 printf("VL_ListAttributes returned code = %d\n", code);
531 entry = (struct vldbentry *)entries.bulkentries_val;
532 for (i = 0; i < nentries; i++, entry++)
533 display_entry(entry, 0);
534 if (entries.bulkentries_val)
535 free(entries.bulkentries_val);
536 } else if (!strcmp(oper, "lan2")) {
537 int nentries, i, si, nsi, t = 0;
538 nbulkentries entries;
539 struct nvldbentry *entry;
542 /* The volume name to search for (supports wildcarding) */
544 strcpy(name, argp[0]);
550 fill_listattributes_entry(&listbyattributes, argp, nargs);
551 display_listattributes_entry(&listbyattributes, 0);
552 printf("Wildcard VolName: '%s'\n", name);
554 for (si = 0; si != -1; si = nsi) {
556 memset(&entries, 0, sizeof(entries));
558 ubik_VL_ListAttributesN2(cstruct, 0,
559 &listbyattributes, name, si, &nentries,
562 printf("VL_ListAttributesN2 returned code = %d\n",
568 entry = (struct nvldbentry *)entries.nbulkentries_val;
569 for (i = 0; i < nentries; i++, entry++)
570 display_entryN(entry, 0);
571 if (entries.nbulkentries_val)
572 free(entries.nbulkentries_val);
574 printf("--- %d volumes ---\n", t);
575 } else if (!strcmp(oper, "ln")) {
577 vldb_list linkedvldbs;
578 vldblist vllist, vllist1;
580 fill_listattributes_entry(&listbyattributes, argp, nargs);
581 display_listattributes_entry(&listbyattributes, 0);
582 memset(&linkedvldbs, 0, sizeof(vldb_list));
584 ubik_VL_LinkedList(cstruct, 0, &listbyattributes,
585 &netries, &linkedvldbs);
587 printf("VL_LinkedList returned code = %d\n", code);
590 printf("Found %d entr%s\n", netries,
591 (netries == 1 ? "y" : "ies"));
592 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
593 vllist1 = vllist->next_vldb;
594 display_entry((struct vldbentry *) &vllist->VldbEntry, 0);
597 } else if (!strcmp(oper, "lnn")) {
599 nvldb_list linkedvldbs;
600 nvldblist vllist, vllist1;
602 fill_listattributes_entry(&listbyattributes, argp, nargs);
603 display_listattributes_entry(&listbyattributes, 0);
604 memset(&linkedvldbs, 0, sizeof(vldb_list));
606 ubik_VL_LinkedListN(cstruct, 0, &listbyattributes,
607 &netries, &linkedvldbs);
609 printf("VL_LinkedList returned code = %d\n", code);
612 printf("Found %d entr%s\n", netries,
613 (netries == 1 ? "y" : "ies"));
614 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
615 vllist1 = vllist->next_vldb;
616 display_entry((struct vldbentry *)&vllist->VldbEntry, 0);
619 } else if (!strcmp(oper, "di")) {
620 sscanf(&(*argp)[0], "%d", &id);
622 sscanf(&(*argp)[0], "%d", &voltype);
624 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
626 display_entry(&entry, code);
627 printf("return code is %d.\n", code);
628 } else if (!strcmp(oper, "rmnh")) {
629 sscanf(&(*argp)[0], "%d", &id);
631 sscanf(&(*argp)[0], "%d", &voltype);
633 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
635 display_entry(&entry, code);
636 memset(&updateentry, 0, sizeof(updateentry));
637 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
638 printf("\tRehashing namehash table for %s (%d)\n", entry.name,
639 entry.volumeId[RWVOL]);
641 ubik_VL_UpdateEntry(cstruct, 0,
642 entry.volumeId[RWVOL], -1, &updateentry, 0);
644 printf("\tFailed to update volume %s (err=%d)\n",
647 printf("return code is %d.\n", code);
648 } else if (!strcmp(oper, "undelete")) {
649 afs_int32 index, count, next_index;
651 memset(&updateentry, 0, sizeof(updateentry));
652 sscanf(&(*argp)[0], "%d", &id);
654 sscanf(&(*argp)[0], "%d", &voltype);
655 if (voltype < 0 && voltype > 2) {
656 printf("Illegal voltype; must be 0, 1 or 2\n");
659 printf("Searching vldb for volume %d...\n", id);
660 for (index = 0; 1; index = next_index) {
661 memset(&entry, 0, sizeof(entry));
663 ubik_VL_ListEntry(cstruct, 0, index, &count,
664 &next_index, &entry);
666 printf("VL_ListEntry returned code = %d\n", code);
671 if (entry.volumeId[voltype] == id) {
672 printf("\nThe current contents of the vldb for %d:\n",
674 display_entry(&entry, 0);
676 if (entry.flags & VLDELETED) {
677 updateentry.Mask = VLUPDATE_FLAGS;
678 updateentry.flags = entry.flags;
679 updateentry.flags &= ~VLDELETED;
681 ("\tUndeleting vldb entry for vol %d (%s)\n",
684 ubik_VL_UpdateEntry(cstruct, 0, id, -1,
688 ("\tFailed to update volume %s (err=%d)\n",
692 printf("Entry not deleted; ignored\n");
697 } else if (!strcmp(oper, "dn")) {
700 ubik_VL_GetEntryByNameO(cstruct, 0, vname, &entry);
701 display_entry(&entry, code);
702 printf("return code is %d.\n", code);
703 } else if (!strcmp(oper, "nv")) {
704 unsigned int newvolid;
705 sscanf(&(*argp)[0], "%d", &id);
707 ubik_VL_GetNewVolumeId(cstruct, 0, id, &newvolid);
709 printf("Current Max volid is (in hex):0x%x\n", newvolid);
710 printf("return code is %d\n", code);
711 } else if (!strcmp(oper, "gs")) {
713 vital_vlheader vital_header;
715 ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
717 dump_stats(&stats, &vital_header);
718 printf("return code is %d.\n", code);
719 } else if (!strcmp(oper, "ga")) {
723 struct VLCallBack vlcb;
725 addrs.bulkaddrs_val = 0;
726 addrs.bulkaddrs_len = 0;
727 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
728 0 /*spare2 */ , &vlcb,
731 printf("VL_GetAddrs returned code = %d\n", code);
734 addrp = addrs.bulkaddrs_val;
735 for (i = 0; i < nentries; i++, addrp++) {
736 if ((*addrp & 0xff000000) == 0xff000000)
737 printf("[0x%x %u] (special multi-homed entry)\n",
740 printf("[0x%x %u] %s\n", *addrp, *addrp,
741 hostutil_GetNameByINet(ntohl(*addrp)));
743 free(addrs.bulkaddrs_val);
744 } else if (!strcmp(oper, "gau")) {
748 struct VLCallBack vlcb;
750 addrs.bulkaddrs_val = 0;
751 addrs.bulkaddrs_len = 0;
752 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
753 0 /*spare2 */ , &vlcb,
756 printf("VL_GetAddrs returned code = %d\n", code);
759 addrp = addrs.bulkaddrs_val;
760 for (i = 0; i < nentries; i++, addrp++) {
761 if ((*addrp & 0xff000000) == 0xff000000) {
762 int mhnentries, unique;
763 struct in_addr hostAddr;
766 ListAddrByAttributes attrs;
769 printf("[0x%x %u] (special multi-homed entry)\n",
771 attrs.Mask = VLADDR_INDEX;
772 mhaddrs.bulkaddrs_val = 0;
773 mhaddrs.bulkaddrs_len = 0;
774 attrs.index = *addrp & 0x00ffffff;
777 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
778 &unique, &mhnentries, &mhaddrs);
780 printf("VL_GetAddrsU returned code = %d\n", code);
784 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
785 attrs.index, uuid.time_low, uuid.time_mid,
786 uuid.time_hi_and_version,
787 uuid.clock_seq_hi_and_reserved,
788 uuid.clock_seq_low, uuid.node[0], uuid.node[1],
789 uuid.node[2], uuid.node[3], uuid.node[4],
790 uuid.node[5], unique);
791 mhaddrp = mhaddrs.bulkaddrs_val;
792 for (j = 0; j < mhnentries; j++) {
793 mhaddrp[j] = ntohl(mhaddrp[j]);
794 hostAddr.s_addr = mhaddrp[j];
795 printf("\t%s (%s)\n", inet_ntoa(hostAddr),
796 hostutil_GetNameByINet(mhaddrp[j]));
798 if (mhaddrs.bulkaddrs_val)
799 free(mhaddrs.bulkaddrs_val);
801 printf("[0x%x %u] %s\n", *addrp, *addrp,
802 hostutil_GetNameByINet(ntohl(*addrp)));
805 free(addrs.bulkaddrs_val);
806 } else if (!strcmp(oper, "mhc")) {
807 afs_uint32 serveraddrs[MAXSERVERID + 1][VL_MAXIPADDRS_PERMH];
808 afs_int32 serveraddrtype[MAXSERVERID + 1];
809 int nentries1, nentries2, i, j, x, y, unique, found;
810 afs_uint32 *addrp1, *addrp2;
811 bulkaddrs addrs1, addrs2;
812 struct VLCallBack vlcb;
813 ListAddrByAttributes attrs;
815 afs_int32 base, index;
817 for (i = 0; i < MAXSERVERID + 1; i++) {
818 serveraddrtype[i] = 0;
819 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
820 serveraddrs[i][j] = 0;
823 /* Collect a list of all registered IP addresses */
824 addrs1.bulkaddrs_val = 0;
825 addrs1.bulkaddrs_len = 0;
827 ubik_VL_GetAddrs(cstruct, 0, 0, 0, &vlcb,
828 &nentries1, &addrs1);
830 printf("VL_GetAddrs returned code = %d\n", code);
833 addrp1 = addrs1.bulkaddrs_val;
834 for (i = 0; i < nentries1; i++, addrp1++) {
835 if ((*addrp1 & 0xff000000) != 0xff000000) {
836 serveraddrs[i][0] = ntohl(*addrp1);
837 serveraddrtype[i] = 1;
839 /* It's multihomed. Get all of its addresses */
840 serveraddrtype[i] = 2;
841 base = (*addrp1 >> 16) & 0xff;
842 index = *addrp1 & 0xffff;
844 addrs2.bulkaddrs_val = 0;
845 addrs2.bulkaddrs_len = 0;
846 attrs.Mask = VLADDR_INDEX;
847 attrs.index = (base * VL_MHSRV_PERBLK) + index;
849 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
850 &unique, &nentries2, &addrs2);
852 printf("VL_GetAddrsU returned code = %d\n", code);
856 addrp2 = addrs2.bulkaddrs_val;
857 for (j = 0; j < nentries2; j++) {
858 serveraddrs[i][j] = ntohl(addrp2[j]);
860 free(addrs2.bulkaddrs_val);
864 if (serveraddrtype[i] == 1) {
865 printf("%u\n", serveraddrs[i][0]);
868 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
869 if (serveraddrs[i][j])
870 printf(" %u", serveraddrs[i][j]);
875 free(addrs1.bulkaddrs_val);
877 /* Look for any duplicates */
878 for (i = 0; i < MAXSERVERID + 1; i++) {
879 if (!serveraddrtype[i])
881 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
882 if (!serveraddrs[i][j])
886 for (x = i + 1; x < MAXSERVERID + 1; x++) {
887 if (!serveraddrtype[x])
889 for (y = 0; y < VL_MAXIPADDRS_PERMH; y++) {
890 if (!serveraddrs[x][y])
892 if (serveraddrs[i][j] == serveraddrs[x][y]) {
893 serveraddrs[x][y] = 0;
900 ("Found %d entries of IP address %u (0x%x)\n",
901 found + 1, serveraddrs[i][j],
907 /*----------------------------------------*/
909 } else if (!strcmp(oper, "regaddr")) {
911 afs_uint32 *addrp, tad;
915 memset(&uuid, 0, sizeof(uuid));
916 sscanf(&(*argp)[0], "%d", &i);
918 memcpy(uuid.node, &i, sizeof(i));
920 if (nargs < 0 || nargs > 16) {
921 printf("Illegal # entries = %d\n", nargs);
924 addrp = malloc(20 * 4);
925 addrs.bulkaddrs_val = addrp;
926 addrs.bulkaddrs_len = nargs;
928 sscanf(&(*argp)[0], "%d", &tad);
933 ubik_VL_RegisterAddrs(cstruct, 0, &uuid,
934 0 /*spare */ , &addrs);
936 printf("VL_RegisterAddrs returned code = %d\n", code);
939 } else if (!strcmp(oper, "ca")) {
940 struct hostent *h1, *h2;
943 printf("changing %s", *argp);
944 h1 = hostutil_GetHostByName(&(*argp)[0]);
946 printf("cmdebug: can't resolve address for host %s",
950 memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32));
953 printf(" to %s\n", *argp);
954 h2 = hostutil_GetHostByName(&(*argp)[0]);
956 printf("cmdebug: can't resolve address for host %s",
960 memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32));
962 printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2));
964 ubik_VL_ChangeAddr(cstruct, 0, ntohl(a1),
967 printf("VL_ChangeAddr returned code = %d\n", code);
970 } else if (!strcmp(oper, "caid")) {
973 sscanf(&(*argp)[0], "%d", &a1);
974 printf("changing %d (0x%x)", a1, a1);
976 sscanf(&(*argp)[0], "%d", &a2);
977 printf(" to %d (0x%x)\n", a2, a2);
978 code = ubik_VL_ChangeAddr(cstruct, 0, a1, a2);
980 printf("VL_ChangeAddr returned code = %d\n", code);
983 } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h") || !strcmp(oper, "help"))
985 else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
988 printf("Unknown oper (%s)!\n", oper);
996 #include "AFS_component_version_number.c"
999 main(int argc, char **argv)
1001 struct cmd_syndesc *ts;
1004 strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
1005 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "initialize the program");
1006 cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL,
1007 "Cell configuration directory");
1008 cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL,
1009 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1010 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1011 "Run it without authentication");
1012 cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL,
1013 "vldb server to talk to");
1014 cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL,
1015 "cellname '-host' belongs to (required for auth conns)");
1016 cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL,
1017 "print vldb statistics (non interactive)");
1018 code = cmd_Dispatch(argc, argv);
1024 fill_entry(struct vldbentry *entry, char **argp, int nargs)
1031 sscanf(&(*argp)[0], "%d", &entry->spares3);
1033 sscanf(&(*argp)[0], "%d", &entry->nServers);
1034 strcpy(entry->name, name);
1035 for (i = 0; i < entry->nServers; i++) {
1037 sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]);
1039 for (i = 0; i < entry->nServers; i++) {
1041 sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]);
1043 for (i = 0; i < entry->nServers; i++) {
1045 sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]);
1047 for (i = 0; i < MAXTYPES; i++) {
1049 sscanf(&(*argp)[0], "%u", &entry->volumeId[i]);
1052 sscanf(&(*argp)[0], "%d", &entry->flags);
1054 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1058 fill_update_entry(struct VldbUpdateEntry *entry, char **argp, int nargs)
1065 if (strcmp(name, "null")) {
1066 strcpy(entry->name, name);
1067 entry->Mask |= VLUPDATE_VOLUMENAME;
1070 sscanf(&(*argp)[0], "%d", &entry->flags);
1071 if (entry->flags != -1)
1072 entry->Mask |= VLUPDATE_FLAGS;
1074 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1075 if (entry->flags != -1)
1076 entry->Mask |= VLUPDATE_CLONEID;
1078 sscanf(&(*argp)[0], "%u", &entry->ReadOnlyId);
1079 if (entry->ReadOnlyId != -1)
1080 entry->Mask |= VLUPDATE_READONLYID;
1082 sscanf(&(*argp)[0], "%u", &entry->BackupId);
1083 if (entry->BackupId != -1)
1084 entry->Mask |= VLUPDATE_BACKUPID;
1086 sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites);
1087 if (entry->nModifiedRepsites != -1)
1088 entry->Mask |= VLUPDATE_REPSITES;
1089 for (i = 0; i < entry->nModifiedRepsites; i++) {
1091 sscanf(&(*argp)[0], "%x", &Mask);
1093 sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]);
1095 sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]);
1096 if (Mask & VLUPDATE_REPS_DELETE)
1097 entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE;
1098 if (Mask & VLUPDATE_REPS_MODSERV) {
1100 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1101 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV;
1102 } else if (Mask & VLUPDATE_REPS_MODPART) {
1104 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1105 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART;
1106 } else if (Mask & VLUPDATE_REPS_MODFLAG) {
1108 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1109 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG;
1110 } else if (Mask & VLUPDATE_REPS_ADD) {
1112 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1114 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1116 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1117 entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD;
1123 fill_listattributes_entry(struct VldbListByAttributes *entry, char **argp,
1130 entry->server = ntohl(GetServer(argp[0]));
1131 sscanf(&(*argp)[0], "%d", &entry->server);
1132 if (entry->server != 0)
1133 entry->Mask |= VLLIST_SERVER;
1138 sscanf(&(*argp)[0], "%d", &entry->partition);
1139 if (entry->partition != -1)
1140 entry->Mask |= VLLIST_PARTITION;
1145 sscanf(&(*argp)[0], "%d", &entry->volumeid);
1146 if (entry->volumeid != -1)
1147 entry->Mask |= VLLIST_VOLUMEID;
1152 sscanf(&(*argp)[0], "%d", &entry->flag);
1153 if (entry->flag != -1)
1154 entry->Mask |= VLLIST_FLAG;
1158 display_listattributes_entry(struct VldbListByAttributes *entry, int error)
1162 printf("\nList entry values (Mask=%x)\n", entry->Mask);
1163 if (entry->Mask & VLLIST_SERVER)
1164 printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff,
1165 (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff,
1166 (entry->server) & 0xff);
1167 if (entry->Mask & VLLIST_PARTITION)
1168 printf("\tPartition: %d\n", entry->partition);
1169 if (entry->Mask & VLLIST_VOLUMEID)
1170 printf("\tVolumeId: %u\n", entry->volumeid);
1171 if (entry->Mask & VLLIST_FLAG)
1172 printf("\tFlag: %x\n", entry->flag);
1176 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1179 display_entry(struct vldbentry *entry, int error)
1185 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1186 entry->name, entry->volumeId[RWVOL], entry->flags);
1187 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1188 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1190 printf("nServers=%d\n", entry->nServers);
1191 printf("ServerNumber\tServerPart\tserverFlag\n");
1192 for (i = 0; i < entry->nServers; i++)
1193 printf("%12u\t%10d\t%10x\n", entry->serverNumber[i],
1194 entry->serverPartition[i], entry->serverFlags[i]);
1198 display_entryN(struct nvldbentry *entry, int error)
1204 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1205 entry->name, entry->volumeId[RWVOL], entry->flags);
1206 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1207 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1209 printf("nServers=%d\n", entry->nServers);
1210 printf("ServerNumber\tServerPart\tserverFlag\n");
1211 ei = entry->matchindex & 0xffff;
1212 et = (entry->matchindex >> 16) & 0xffff;
1213 for (i = 0; i < entry->nServers; i++) {
1214 printf("%12u\t%10d\t%10x", entry->serverNumber[i],
1215 entry->serverPartition[i], entry->serverFlags[i]);
1217 printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO"));
1224 display_update_entry(struct VldbUpdateEntry *entry, int error)
1230 printf("\nUpdate entry values (Mask=%x)\n", entry->Mask);
1231 if (entry->Mask & VLUPDATE_VOLUMENAME)
1232 printf("\tNew name: %s\n", entry->name);
1233 if (entry->Mask & VLUPDATE_FLAGS)
1234 printf("\tNew flags: %X\n", entry->flags);
1235 if (entry->Mask & VLUPDATE_CLONEID)
1236 printf("\tNew CloneId: %X\n", entry->cloneId);
1237 if (entry->Mask & VLUPDATE_READONLYID)
1238 printf("\tNew RO id: %d\n", entry->ReadOnlyId);
1239 if (entry->Mask & VLUPDATE_BACKUPID)
1240 printf("\tNew BACKUP id: %d\n", entry->BackupId);
1241 if (entry->Mask & VLUPDATE_REPSITES) {
1242 printf("\tRepsites info:\n");
1243 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1244 for (i = 0; i < entry->nModifiedRepsites; i++) {
1245 printf("\t%4x\t%7u\t%5d", entry->RepsitesMask[i],
1246 entry->RepsitesTargetServer[i],
1247 entry->RepsitesTargetPart[i]);
1248 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1249 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV))
1250 printf("\t%7u", entry->RepsitesNewServer[i]);
1252 printf("\t-------");
1253 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1254 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART))
1255 printf("\t%5d", entry->RepsitesNewPart[i]);
1258 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1259 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG))
1260 printf("\t%5x\n", entry->RepsitesNewFlags[i]);
1262 printf("\t-----\n");
1268 dump_stats(vldstats *stats, vital_vlheader *vital_header)
1272 time_t start_time = stats->start_time;
1275 strftime(strg, sizeof(strg), "%a %b %d %H:%M:%S %Y",
1276 localtime_r(&start_time, &tm));
1277 printf("Dynamic statistics stats (starting time: %s):\n", strg);
1278 printf("OpcodeName\t# Requests\t# Aborts\n");
1279 for (i = 0; i < VL_NUMBER_OPCODESX; i++)
1280 printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i],
1282 printf("\nVldb header stats (version=%d)\n",
1283 ntohl(vital_header->vldbversion));
1284 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1285 ntohl(vital_header->headersize), ntohl(vital_header->allocs),
1286 ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId));
1287 for (i = 0; i < MAXTYPES; i++)
1288 printf("total %s entries=%d\n", volumetype_string(i),
1289 ntohl(vital_header->totalEntries[i]));
1293 GetArgs(char *line, char **args, int *nargs)
1298 while (isspace(*line))
1304 *args++ = line, (*nargs)++;
1305 while (*line && !isspace(*line))
1313 printf("Valid Commands:\n");
1315 printf(" CreateEntry:\n");
1317 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1319 printf(" DeleteEntry:\n");
1320 printf("\trm <volid> <voltype>\n");
1322 printf(" ReplaceEntry:\n");
1323 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1325 printf(" UpdateEntry:\n");
1327 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1329 printf(" ListEntry:\n");
1332 printf(" Find duplicate entries of a volume\n");
1333 printf("\tldups\n");
1335 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1336 printf("\tcheckhash\n");
1339 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1340 printf("\tfixhash\n");
1342 printf(" ListAttributes:\n");
1343 printf("\tla [server] [partition] [volumeid] [flag]\n");
1345 printf(" ListAttributesN2:\n");
1346 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1348 printf(" GetEntryByID:\n");
1349 printf("\tdi <volid> <voltype>\n");
1351 printf(" UpdateEntry (refresh namehash table):\n");
1352 printf("\trmnh <volid> <voltype>\n");
1354 printf(" GetEntryByName:\n");
1355 printf("\tdn <volname> <voltype>\n");
1357 printf(" UpdateEntry (undelete a vol entry):\n");
1358 printf("\tundelete <volid> <voltype>\n");
1360 * printf(" LinkedList\n");
1361 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1363 * printf(" LinkedListN\n");
1364 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1366 printf(" GetNewVoumeId:\n");
1367 printf("\tnv <bump-count>\n");
1369 printf(" GetStats:\n");
1372 printf(" ChangeAddr:\n");
1373 printf("\tca <oldmachname> <newmachname>\n");
1376 * printf(" ChangeAddr\n");
1377 * printf("\t:caid <oldaddr> <newaddr>\n");
1379 printf(" GetAddrs:\n");
1382 printf(" GetAddrsU:\n");
1385 printf(" RegisterAddrs:\n");
1386 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1388 printf("\tmisc: q, quit, ?, h\n");