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>
41 #include <afs/afsutil.h>
44 #include <rx/rx_globals.h>
46 #include <afs/cellconfig.h>
53 void fill_listattributes_entry(struct VldbListByAttributes *, char **, int);
54 void display_listattributes_entry(struct VldbListByAttributes *,int);
55 void display_entry(struct vldbentry *, int);
56 void display_entryN(struct nvldbentry *, int);
57 void display_update_entry(struct VldbUpdateEntry *, int);
58 void dump_stats(vldstats *, vital_vlheader *);
59 void GetArgs(char *, char **, int *);
60 void print_usage(void);
61 void fill_entry(struct vldbentry *, char **, int);
62 void fill_update_entry(struct VldbUpdateEntry *, char **, int);
64 #define VL_NUMBER_OPCODESX 34
65 static char *opcode_names[VL_NUMBER_OPCODESX] = {
111 #define ALLOCNT 50000
112 struct Vlent *VLa[NVOLS];
113 #define VHash(avol) ((avol)&(NVOLS-1))
114 struct Vlent *VL, *SVL;
116 struct ubik_client *cstruct;
117 struct rx_connection *serverconns[MAXSERVERS];
118 char confdir[AFSDIR_PATH_MAX];
122 GetVolume(int vol, struct vldbentry *entry)
125 register struct Vlent *vl;
130 for (vl = VLa[i]; vl; vl = vl->next) {
131 if ((vl->rwid == vol && vol != entry->volumeId[0])
132 || (vl->roid == vol && vol != entry->volumeId[1])
133 || (vl->baid == vol && vol != entry->volumeId[2])) {
137 VL->rwid = entry->volumeId[0];
138 VL->roid = entry->volumeId[1];
139 VL->baid = entry->volumeId[2];
140 strcpy(entry->name, VL->name);
143 if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */
144 printf("Too many entries (> %d)\n", ALLOCNT);
151 /* Almost identical's to pr_Initialize in vlserver/pruser.c */
153 vl_Initialize(int auth, char *confDir, int server, char *cellp)
155 return ugen_ClientInit(auth?0:1, confDir, cellp, 0,
156 &cstruct, NULL, "vl_Initialize", rxkad_clear,
157 MAXSERVERS, AFSCONF_VLDBSERVICE, 50, server,
158 htons(AFSCONF_VLDBPORT), USER_SERVICE_ID);
161 /* return host address in network byte order */
163 GetServer(char *aname)
165 register struct hostent *th;
168 register afs_int32 code;
170 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
172 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
173 return htonl(addr); /* convert to network order (128 in byte 0) */
175 th = gethostbyname(aname);
178 memcpy(&addr, th->h_addr, sizeof(addr));
184 handleit(struct cmd_syndesc *as, void *arock)
186 register struct cmd_item *ti;
187 register afs_int32 code, server = 0, sawserver = 0;
188 afs_int32 id, voltype;
189 struct vldbentry entry;
191 struct VldbUpdateEntry updateentry;
192 struct VldbListByAttributes listbyattributes;
193 int noAuth = 1; /* Default is authenticated connections */
195 if ((ti = as->parms[0].items)) /* -cellpath <dir> */
196 strcpy(confdir, ti->data);
197 if (as->parms[1].items) /* -server */
198 strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH);
199 if (as->parms[2].items) /* -noauth */
201 if ((ti = as->parms[3].items)) { /* -host */
202 server = GetServer(ti->data);
204 printf("server '%s' not found in host table\n", ti->data);
209 if (!sawserver && noAuth && (!(ti = as->parms[4].items))) {
211 ("Must also specify the -cell' option along with -host for authenticated conns\n");
214 if ((ti = as->parms[4].items)) { /* -cell */
217 if ((code = vl_Initialize(noAuth, confdir, server, cellp))) {
218 printf("Couldn't initialize vldb library (code=%d).\n", code);
222 if (as->parms[5].items) { /* -gstats */
224 vital_vlheader vital_header;
225 code = ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
227 dump_stats(&stats, &vital_header);
233 int nargs, releasetype;
234 memset(&entry, 0, sizeof(entry));
235 memset(&updateentry, 0, sizeof(updateentry));
236 memset(&listbyattributes, 0, sizeof(listbyattributes));
238 if (fgets(line, 499, stdin) == NULL) {
243 register char **argp = args;
244 GetArgs(line, argp, &nargs);
247 if (!strcmp(oper, "cr")) {
248 fill_entry(&entry, argp, nargs);
249 display_entry(&entry, 0);
250 code = ubik_VL_CreateEntry(cstruct, 0, &entry);
251 printf("return code is %d\n", code);
252 } else if (!strcmp(oper, "rm")) {
253 sscanf(&(*argp)[0], "%d", &id);
255 sscanf(&(*argp)[0], "%d", &voltype);
256 code = ubik_VL_DeleteEntry(cstruct, 0, id, voltype);
257 printf("return code is %d\n", code);
258 } else if (!strcmp(oper, "re")) {
259 sscanf(&(*argp)[0], "%d", &id);
261 sscanf(&(*argp)[0], "%d", &voltype);
263 sscanf(&(*argp)[0], "%d", &releasetype);
265 fill_entry(&entry, argp, nargs);
266 display_entry(&entry, 0);
268 ubik_VL_ReplaceEntry(
269 cstruct, 0, id, voltype,
270 &entry, releasetype);
271 printf("return code is %d\n", code);
272 } else if (!strcmp(oper, "up")) {
273 sscanf(&(*argp)[0], "%d", &id);
275 sscanf(&(*argp)[0], "%d", &voltype);
277 sscanf(&(*argp)[0], "%d", &releasetype);
279 fill_update_entry(&updateentry, argp, nargs);
280 display_update_entry(&updateentry, 0);
282 ubik_VL_UpdateEntry(cstruct, 0, id, voltype,
283 &updateentry, releasetype);
284 printf("return code is %d\n", code);
285 } else if (!strcmp(oper, "ls")) {
286 afs_int32 index, count, next_index;
287 for (index = 0; 1; index = next_index) {
288 memset(&entry, 0, sizeof(entry));
290 ubik_VL_ListEntry(cstruct, 0, index, &count,
291 &next_index, &entry);
293 printf("VL_ListEntry returned code = %d\n", code);
298 display_entry(&entry, 0);
300 } else if (!strcmp(oper, "ldups")) {
301 afs_int32 index, count, num = 0, num1 = 0, next_index;
305 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
307 printf("Can't allocate memory...\n");
310 printf("Enumerating all entries in vldb...\n");
311 for (index = 0; 1; index = next_index) {
312 memset(&entry, 0, sizeof(entry));
314 ubik_VL_ListEntry(cstruct, 0, index, &count,
315 &next_index, &entry);
317 printf("VL_ListEntry returned code = %d\n", code);
323 if ((vl1 = GetVolume(entry.volumeId[0], &entry))) {
326 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
327 entry.volumeId[0], vl1->rwid, vl1->roid,
328 vl1->baid, vl1->name);
330 if ((vl1 = GetVolume(entry.volumeId[1], &entry))) {
333 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
334 entry.volumeId[1], vl1->rwid, vl1->roid,
335 vl1->baid, vl1->name);
337 if ((vl1 = GetVolume(entry.volumeId[2], &entry))) {
340 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
341 entry.volumeId[2], vl1->rwid, vl1->roid,
342 vl1->baid, vl1->name);
344 /*display_entry(&entry, 0); */
346 printf("(%d vldb entries found - %d duplicates)\n", num,
348 } else if (!strcmp(oper, "checkhash")) {
349 int index, count, num = 0, num1 = 0, num2 = 0, num3 =
350 0, num31 = 0, num4 = 0, num41 = 0, next_index;
351 struct vldbentry tentry;
354 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
356 printf("Can't allocate memory...\n");
359 printf("Volumes not found in main hash tables in vldb...\n");
360 for (index = 0; 1; index = next_index) {
361 memset(&entry, 0, sizeof(entry));
363 ubik_VL_ListEntry(cstruct, 0, index, &count,
364 &next_index, &entry);
366 printf("VL_ListEntry returned code = %d\n", code);
373 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
375 if (code == VL_NOENT) {
377 printf("\tVolume %s %d (not in namehash)\n",
378 entry.name, entry.volumeId[RWVOL]);
381 ubik_VL_GetEntryByID(cstruct, 0,
382 entry.volumeId[RWVOL], RWVOL, &tentry);
383 if (code == VL_NOENT) {
385 printf("\tVolume %s %d (not in rwid hash)\n",
386 entry.name, entry.volumeId[RWVOL]);
388 if (entry.volumeId[BACKVOL]) {
390 ubik_VL_GetEntryByID(cstruct, 0,
391 entry.volumeId[BACKVOL], BACKVOL,
394 if (code == VL_NOENT) {
396 printf("\tVolume %s %d (not in backup id hash)\n",
397 entry.name, entry.volumeId[BACKVOL]);
400 if (entry.volumeId[ROVOL]) {
402 ubik_VL_GetEntryByID(cstruct, 0,
403 entry.volumeId[ROVOL], ROVOL, &tentry);
405 if (code == VL_NOENT) {
407 printf("\tVolume %s %d (not in RO id hash)\n",
408 entry.name, entry.volumeId[ROVOL]);
413 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
414 num, num + num31 + num41, num, num31, num41);
416 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
419 ("\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",
420 num3, num31, num4, num41);
421 } else if (!strcmp(oper, "fixhash")) {
422 int index, count, num = 0, num1 = 0, num2 = 0, next_index, x =
424 struct vldbentry tentry;
427 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
429 printf("Can't allocate memory...\n");
433 ("Volumes not found in main hash tables in vldb will be fixed...\n");
434 memset(&updateentry, 0, sizeof(updateentry));
435 for (index = 0; 1; index = next_index) {
436 /* FIXME: n2 is never changed for some reason */
437 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
438 memset(&entry, 0, sizeof(entry));
440 ubik_VL_ListEntry(cstruct, 0, index, &count,
441 &next_index, &entry);
443 printf("VL_ListEntry returned code = %d\n", code);
450 ubik_VL_GetEntryByNameO(cstruct, 0, entry.name,
452 if (code == VL_NOENT) {
455 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
456 printf("\tVolume %s %d (not in namehash)\n",
457 entry.name, entry.volumeId[RWVOL]);
459 ubik_VL_UpdateEntry(cstruct, 0,
460 entry.volumeId[RWVOL], -1, &updateentry,
464 printf("\tFailed to update volume %s (err=%d)\n",
469 ubik_VL_GetEntryByID(cstruct, 0,
470 entry.volumeId[RWVOL], RWVOL, &tentry);
471 if (code == VL_NOENT) {
474 updateentry.Mask = VLUPDATE_RWID;
475 updateentry.spares3 = entry.volumeId[RWVOL];
476 printf("\tVolume %s %d (not in rw id hash)\n",
477 entry.name, entry.volumeId[RWVOL]);
479 ubik_VL_UpdateEntryByName(cstruct, 0,
480 entry.name, &updateentry, 0);
482 printf("\tFailed to update volume %s (err=%d)\n",
488 if (entry.volumeId[BACKVOL] && !n2) {
490 ubik_VL_GetEntryByID(cstruct, 0,
491 entry.volumeId[BACKVOL], BACKVOL,
493 if (code == VL_NOENT) {
496 updateentry.Mask = VLUPDATE_BACKUPID;
497 updateentry.BackupId = entry.volumeId[BACKVOL];
498 printf("\tVolume %s %d (not in backup id hash)\n",
499 entry.name, entry.volumeId[BACKVOL]);
501 ubik_VL_UpdateEntry(cstruct, 0,
502 entry.volumeId[RWVOL], -1,
506 ("\tFailed to update volume %s (err=%d)\n",
512 if (entry.volumeId[ROVOL && !n2]) {
514 ubik_VL_GetEntryByID(cstruct, 0,
515 entry.volumeId[ROVOL], ROVOL, &tentry);
516 if (code == VL_NOENT) {
519 updateentry.Mask = VLUPDATE_READONLYID;
520 updateentry.ReadOnlyId = entry.volumeId[ROVOL];
521 printf("\tVolume %s %d (not in RO id hash)\n",
522 entry.name, entry.volumeId[ROVOL]);
524 ubik_VL_UpdateEntry(cstruct, 0,
525 entry.volumeId[RWVOL], -1,
529 ("\tFailed to update volume %s (err=%d)\n",
537 ("\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",
539 } else if (!strcmp(oper, "la")) {
542 struct vldbentry *entry;
544 memset(&entries, 0, sizeof(entries));
545 fill_listattributes_entry(&listbyattributes, argp, nargs);
546 display_listattributes_entry(&listbyattributes, 0);
548 ubik_VL_ListAttributes(cstruct, 0,
549 &listbyattributes, &nentries, &entries);
551 printf("VL_ListAttributes returned code = %d\n", code);
554 entry = (struct vldbentry *)entries.bulkentries_val;
555 for (i = 0; i < nentries; i++, entry++)
556 display_entry(entry, 0);
557 if (entries.bulkentries_val)
558 free((char *)entries.bulkentries_val);
559 } else if (!strcmp(oper, "lan2")) {
560 int nentries, i, si, nsi, t = 0;
561 nbulkentries entries;
562 struct nvldbentry *entry;
565 /* The volume name to search for (supports wildcarding) */
567 strcpy(name, argp[0]);
573 fill_listattributes_entry(&listbyattributes, argp, nargs);
574 display_listattributes_entry(&listbyattributes, 0);
575 printf("Wildcard VolName: '%s'\n", name);
577 for (si = 0; si != -1; si = nsi) {
579 memset(&entries, 0, sizeof(entries));
581 ubik_VL_ListAttributesN2(cstruct, 0,
582 &listbyattributes, name, si, &nentries,
585 printf("VL_ListAttributesN2 returned code = %d\n",
591 entry = (struct nvldbentry *)entries.nbulkentries_val;
592 for (i = 0; i < nentries; i++, entry++)
593 display_entryN(entry, 0);
594 if (entries.nbulkentries_val)
595 free((char *)entries.nbulkentries_val);
597 printf("--- %d volumes ---\n", t);
598 } else if (!strcmp(oper, "ln")) {
600 vldb_list linkedvldbs;
601 vldblist vllist, vllist1;
603 fill_listattributes_entry(&listbyattributes, argp, nargs);
604 display_listattributes_entry(&listbyattributes, 0);
605 memset(&linkedvldbs, 0, sizeof(vldb_list));
607 ubik_VL_LinkedList(cstruct, 0, &listbyattributes,
608 &netries, &linkedvldbs);
610 printf("VL_LinkedList returned code = %d\n", code);
613 printf("Found %d entr%s\n", netries,
614 (netries == 1 ? "y" : "ies"));
615 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
616 vllist1 = vllist->next_vldb;
617 display_entry((struct vldbentry *) &vllist->VldbEntry, 0);
620 } else if (!strcmp(oper, "lnn")) {
622 nvldb_list linkedvldbs;
623 nvldblist vllist, vllist1;
625 fill_listattributes_entry(&listbyattributes, argp, nargs);
626 display_listattributes_entry(&listbyattributes, 0);
627 memset(&linkedvldbs, 0, sizeof(vldb_list));
629 ubik_VL_LinkedListN(cstruct, 0, &listbyattributes,
630 &netries, &linkedvldbs);
632 printf("VL_LinkedList returned code = %d\n", code);
635 printf("Found %d entr%s\n", netries,
636 (netries == 1 ? "y" : "ies"));
637 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
638 vllist1 = vllist->next_vldb;
639 display_entry((struct vldbentry *)&vllist->VldbEntry, 0);
640 free((char *)vllist);
642 } else if (!strcmp(oper, "di")) {
643 sscanf(&(*argp)[0], "%d", &id);
645 sscanf(&(*argp)[0], "%d", &voltype);
647 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
649 display_entry(&entry, code);
650 printf("return code is %d.\n", code);
651 } else if (!strcmp(oper, "rmnh")) {
652 sscanf(&(*argp)[0], "%d", &id);
654 sscanf(&(*argp)[0], "%d", &voltype);
656 ubik_VL_GetEntryByID(cstruct, 0, id, voltype,
658 display_entry(&entry, code);
659 memset(&updateentry, 0, sizeof(updateentry));
660 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
661 printf("\tRehashing namehash table for %s (%d)\n", entry.name,
662 entry.volumeId[RWVOL]);
664 ubik_VL_UpdateEntry(cstruct, 0,
665 entry.volumeId[RWVOL], -1, &updateentry, 0);
667 printf("\tFailed to update volume %s (err=%d)\n",
670 printf("return code is %d.\n", code);
671 } else if (!strcmp(oper, "undelete")) {
672 afs_int32 index, count, next_index;
674 memset(&updateentry, 0, sizeof(updateentry));
675 sscanf(&(*argp)[0], "%d", &id);
677 sscanf(&(*argp)[0], "%d", &voltype);
678 if (voltype < 0 && voltype > 2) {
679 printf("Illegal voltype; must be 0, 1 or 2\n");
682 printf("Searching vldb for volume %d...\n", id);
683 for (index = 0; 1; index = next_index) {
684 memset(&entry, 0, sizeof(entry));
686 ubik_VL_ListEntry(cstruct, 0, index, &count,
687 &next_index, &entry);
689 printf("VL_ListEntry returned code = %d\n", code);
694 if (entry.volumeId[voltype] == id) {
695 printf("\nThe current contents of the vldb for %d:\n",
697 display_entry(&entry, 0);
699 if (entry.flags & VLDELETED) {
700 updateentry.Mask = VLUPDATE_FLAGS;
701 updateentry.flags = entry.flags;
702 updateentry.flags &= ~VLDELETED;
704 ("\tUndeleting vldb entry for vol %d (%s)\n",
707 ubik_VL_UpdateEntry(cstruct, 0, id, -1,
711 ("\tFailed to update volume %s (err=%d)\n",
715 printf("Entry not deleted; ignored\n");
720 } else if (!strcmp(oper, "dn")) {
723 ubik_VL_GetEntryByNameO(cstruct, 0, vname, &entry);
724 display_entry(&entry, code);
725 printf("return code is %d.\n", code);
726 } else if (!strcmp(oper, "nv")) {
727 unsigned int newvolid;
728 sscanf(&(*argp)[0], "%d", &id);
730 ubik_VL_GetNewVolumeId(cstruct, 0, id, &newvolid);
732 printf("Current Max volid is (in hex):0x%x\n", newvolid);
733 printf("return code is %d\n", code);
734 } else if (!strcmp(oper, "gs")) {
736 vital_vlheader vital_header;
738 ubik_VL_GetStats(cstruct, 0, &stats, &vital_header);
740 dump_stats(&stats, &vital_header);
741 printf("return code is %d.\n", code);
742 } else if (!strcmp(oper, "ga")) {
746 struct VLCallBack vlcb;
748 addrs.bulkaddrs_val = 0;
749 addrs.bulkaddrs_len = 0;
750 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
751 0 /*spare2 */ , &vlcb,
754 printf("VL_GetAddrs returned code = %d\n", code);
757 addrp = addrs.bulkaddrs_val;
758 for (i = 0; i < nentries; i++, addrp++) {
759 if ((*addrp & 0xff000000) == 0xff000000)
760 printf("[0x%x %u] (special multi-homed entry)\n",
763 printf("[0x%x %u] %s\n", *addrp, *addrp,
764 hostutil_GetNameByINet(ntohl(*addrp)));
766 free((char *)addrs.bulkaddrs_val);
767 } else if (!strcmp(oper, "gau")) {
771 struct VLCallBack vlcb;
773 addrs.bulkaddrs_val = 0;
774 addrs.bulkaddrs_len = 0;
775 code = ubik_VL_GetAddrs(cstruct, 0, 0 /*Handle */ ,
776 0 /*spare2 */ , &vlcb,
779 printf("VL_GetAddrs returned code = %d\n", code);
782 addrp = addrs.bulkaddrs_val;
783 for (i = 0; i < nentries; i++, addrp++) {
784 if ((*addrp & 0xff000000) == 0xff000000) {
785 int mhnentries, unique;
786 struct in_addr hostAddr;
789 ListAddrByAttributes attrs;
792 printf("[0x%x %u] (special multi-homed entry)\n",
794 attrs.Mask = VLADDR_INDEX;
795 mhaddrs.bulkaddrs_val = 0;
796 mhaddrs.bulkaddrs_len = 0;
797 attrs.index = *addrp & 0x00ffffff;
800 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
801 &unique, &mhnentries, &mhaddrs);
803 printf("VL_GetAddrsU returned code = %d\n", code);
807 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
808 attrs.index, uuid.time_low, uuid.time_mid,
809 uuid.time_hi_and_version,
810 uuid.clock_seq_hi_and_reserved,
811 uuid.clock_seq_low, uuid.node[0], uuid.node[1],
812 uuid.node[2], uuid.node[3], uuid.node[4],
813 uuid.node[5], unique);
814 mhaddrp = mhaddrs.bulkaddrs_val;
815 for (j = 0; j < mhnentries; j++) {
816 mhaddrp[j] = ntohl(mhaddrp[j]);
817 hostAddr.s_addr = mhaddrp[j];
818 printf("\t%s (%s)\n", inet_ntoa(hostAddr),
819 hostutil_GetNameByINet(mhaddrp[j]));
821 if (mhaddrs.bulkaddrs_val)
822 free((char *)mhaddrs.bulkaddrs_val);
824 printf("[0x%x %u] %s\n", *addrp, *addrp,
825 hostutil_GetNameByINet(ntohl(*addrp)));
828 free((char *)addrs.bulkaddrs_val);
829 } else if (!strcmp(oper, "mhc")) {
830 afs_int32 serveraddrs[MAXSERVERID + 1][VL_MAXIPADDRS_PERMH];
831 afs_int32 serveraddrtype[MAXSERVERID + 1];
832 int nentries1, nentries2, i, j, x, y, unique, found;
833 afs_uint32 *addrp1, *addrp2;
834 bulkaddrs addrs1, addrs2;
835 struct VLCallBack vlcb;
836 ListAddrByAttributes attrs;
838 afs_int32 base, index;
840 for (i = 0; i < MAXSERVERID + 1; i++) {
841 serveraddrtype[i] = 0;
842 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
843 serveraddrs[i][j] = 0;
846 /* Collect a list of all registered IP addresses */
847 addrs1.bulkaddrs_val = 0;
848 addrs1.bulkaddrs_len = 0;
850 ubik_VL_GetAddrs(cstruct, 0, 0, 0, &vlcb,
851 &nentries1, &addrs1);
853 printf("VL_GetAddrs returned code = %d\n", code);
856 addrp1 = addrs1.bulkaddrs_val;
857 for (i = 0; i < nentries1; i++, addrp1++) {
858 if ((*addrp1 & 0xff000000) != 0xff000000) {
859 serveraddrs[i][0] = ntohl(*addrp1);
860 serveraddrtype[i] = 1;
862 /* It's multihomed. Get all of its addresses */
863 serveraddrtype[i] = 2;
864 base = (*addrp1 >> 16) & 0xff;
865 index = *addrp1 & 0xffff;
867 addrs2.bulkaddrs_val = 0;
868 addrs2.bulkaddrs_len = 0;
869 attrs.Mask = VLADDR_INDEX;
870 attrs.index = (base * VL_MHSRV_PERBLK) + index;
872 ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid,
873 &unique, &nentries2, &addrs2);
875 printf("VL_GetAddrsU returned code = %d\n", code);
879 addrp2 = addrs2.bulkaddrs_val;
880 for (j = 0; j < nentries2; j++) {
881 serveraddrs[i][j] = ntohl(addrp2[j]);
883 free((char *)addrs2.bulkaddrs_val);
887 if (serveraddrtype[i] == 1) {
888 printf("%u\n", serveraddrs[i][0]);
891 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
892 if (serveraddrs[i][j])
893 printf(" %u", serveraddrs[i][j]);
898 free((char *)addrs1.bulkaddrs_val);
900 /* Look for any duplicates */
901 for (i = 0; i < MAXSERVERID + 1; i++) {
902 if (!serveraddrtype[i])
904 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
905 if (!serveraddrs[i][j])
909 for (x = i + 1; x < MAXSERVERID + 1; x++) {
910 if (!serveraddrtype[x])
912 for (y = 0; y < VL_MAXIPADDRS_PERMH; y++) {
913 if (!serveraddrs[x][y])
915 if (serveraddrs[i][j] == serveraddrs[x][y]) {
916 serveraddrs[x][y] = 0;
923 ("Found %d entries of IP address %u (0x%x)\n",
924 found + 1, serveraddrs[i][j],
930 /*----------------------------------------*/
932 } else if (!strcmp(oper, "regaddr")) {
934 afs_uint32 *addrp, tad;
938 memset(&uuid, 0, sizeof(uuid));
939 sscanf(&(*argp)[0], "%d", &i);
941 memcpy(uuid.node, &i, sizeof(i));
943 if (nargs < 0 || nargs > 16) {
944 printf("Illegal # entries = %d\n", nargs);
947 addrp = (afs_uint32 *) malloc(20 * 4);
948 addrs.bulkaddrs_val = addrp;
949 addrs.bulkaddrs_len = nargs;
951 sscanf(&(*argp)[0], "%d", &tad);
956 ubik_VL_RegisterAddrs(cstruct, 0, &uuid,
957 0 /*spare */ , &addrs);
959 printf("VL_RegisterAddrs returned code = %d\n", code);
962 } else if (!strcmp(oper, "ca")) {
963 struct hostent *h1, *h2;
966 printf("changing %s", *argp);
967 h1 = hostutil_GetHostByName(&(*argp)[0]);
969 printf("cmdebug: can't resolve address for host %s",
973 memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32));
976 printf(" to %s\n", *argp);
977 h2 = hostutil_GetHostByName(&(*argp)[0]);
979 printf("cmdebug: can't resolve address for host %s",
983 memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32));
985 printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2));
987 ubik_VL_ChangeAddr(cstruct, 0, ntohl(a1),
990 printf("VL_ChangeAddr returned code = %d\n", code);
993 } else if (!strcmp(oper, "caid")) {
996 sscanf(&(*argp)[0], "%d", &a1);
997 printf("changing %d (0x%x)", a1, a1);
999 sscanf(&(*argp)[0], "%d", &a2);
1000 printf(" to %d (0x%x)\n", a2, a2);
1001 code = ubik_VL_ChangeAddr(cstruct, 0, a1, a2);
1003 printf("VL_ChangeAddr returned code = %d\n", code);
1006 } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h"))
1008 else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
1011 printf("Unknown oper!\n");
1018 #include "AFS_component_version_number.c"
1021 main(int argc, char **argv)
1023 register struct cmd_syndesc *ts;
1026 strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
1027 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "initialize the program");
1028 cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL,
1029 "Cell configuration directory");
1030 cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL,
1031 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1032 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1033 "Run it without authentication");
1034 cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL,
1035 "vldb server to talk to");
1036 cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL,
1037 "cellname '-host' belongs to (required for auth conns)");
1038 cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL,
1039 "print vldb statistics (non interactive)");
1040 code = cmd_Dispatch(argc, argv);
1046 fill_entry(struct vldbentry *entry, char **argp, int nargs)
1053 sscanf(&(*argp)[0], "%d", &entry->spares3);
1055 sscanf(&(*argp)[0], "%d", &entry->nServers);
1056 strcpy(entry->name, name);
1057 for (i = 0; i < entry->nServers; i++) {
1059 sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]);
1061 for (i = 0; i < entry->nServers; i++) {
1063 sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]);
1065 for (i = 0; i < entry->nServers; i++) {
1067 sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]);
1069 for (i = 0; i < MAXTYPES; i++) {
1071 sscanf(&(*argp)[0], "%u", &entry->volumeId[i]);
1074 sscanf(&(*argp)[0], "%d", &entry->flags);
1076 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1080 fill_update_entry(struct VldbUpdateEntry *entry, char **argp, int nargs)
1087 if (strcmp(name, "null")) {
1088 strcpy(entry->name, name);
1089 entry->Mask |= VLUPDATE_VOLUMENAME;
1092 sscanf(&(*argp)[0], "%d", &entry->flags);
1093 if (entry->flags != -1)
1094 entry->Mask |= VLUPDATE_FLAGS;
1096 sscanf(&(*argp)[0], "%u", &entry->cloneId);
1097 if (entry->flags != -1)
1098 entry->Mask |= VLUPDATE_CLONEID;
1100 sscanf(&(*argp)[0], "%u", &entry->ReadOnlyId);
1101 if (entry->ReadOnlyId != -1)
1102 entry->Mask |= VLUPDATE_READONLYID;
1104 sscanf(&(*argp)[0], "%u", &entry->BackupId);
1105 if (entry->BackupId != -1)
1106 entry->Mask |= VLUPDATE_BACKUPID;
1108 sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites);
1109 if (entry->nModifiedRepsites != -1)
1110 entry->Mask |= VLUPDATE_REPSITES;
1111 for (i = 0; i < entry->nModifiedRepsites; i++) {
1113 sscanf(&(*argp)[0], "%x", &Mask);
1115 sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]);
1117 sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]);
1118 if (Mask & VLUPDATE_REPS_DELETE)
1119 entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE;
1120 if (Mask & VLUPDATE_REPS_MODSERV) {
1122 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1123 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV;
1124 } else if (Mask & VLUPDATE_REPS_MODPART) {
1126 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1127 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART;
1128 } else if (Mask & VLUPDATE_REPS_MODFLAG) {
1130 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1131 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG;
1132 } else if (Mask & VLUPDATE_REPS_ADD) {
1134 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1136 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1138 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1139 entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD;
1145 fill_listattributes_entry(struct VldbListByAttributes *entry, char **argp,
1152 entry->server = ntohl(GetServer(argp[0]));
1153 sscanf(&(*argp)[0], "%d", &entry->server);
1154 if (entry->server != 0)
1155 entry->Mask |= VLLIST_SERVER;
1160 sscanf(&(*argp)[0], "%d", &entry->partition);
1161 if (entry->partition != -1)
1162 entry->Mask |= VLLIST_PARTITION;
1167 sscanf(&(*argp)[0], "%d", &entry->volumeid);
1168 if (entry->volumeid != -1)
1169 entry->Mask |= VLLIST_VOLUMEID;
1174 sscanf(&(*argp)[0], "%d", &entry->flag);
1175 if (entry->flag != -1)
1176 entry->Mask |= VLLIST_FLAG;
1180 display_listattributes_entry(struct VldbListByAttributes *entry, int error)
1184 printf("\nList entry values (Mask=%x)\n", entry->Mask);
1185 if (entry->Mask & VLLIST_SERVER)
1186 printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff,
1187 (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff,
1188 (entry->server) & 0xff);
1189 if (entry->Mask & VLLIST_PARTITION)
1190 printf("\tPartition: %d\n", entry->partition);
1191 if (entry->Mask & VLLIST_VOLUMEID)
1192 printf("\tVolumeId: %u\n", entry->volumeid);
1193 if (entry->Mask & VLLIST_FLAG)
1194 printf("\tFlag: %x\n", entry->flag);
1198 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1201 display_entry(struct vldbentry *entry, int error)
1207 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1208 entry->name, entry->volumeId[RWVOL], entry->flags);
1209 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1210 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1212 printf("nServers=%d\n", entry->nServers);
1213 printf("ServerNumber\tServerPart\tserverFlag\n");
1214 for (i = 0; i < entry->nServers; i++)
1215 printf("%12u\t%10d\t%10x\n", entry->serverNumber[i],
1216 entry->serverPartition[i], entry->serverFlags[i]);
1220 display_entryN(struct nvldbentry *entry, int error)
1226 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1227 entry->name, entry->volumeId[RWVOL], entry->flags);
1228 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1229 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1231 printf("nServers=%d\n", entry->nServers);
1232 printf("ServerNumber\tServerPart\tserverFlag\n");
1233 ei = entry->matchindex & 0xffff;
1234 et = (entry->matchindex >> 16) & 0xffff;
1235 for (i = 0; i < entry->nServers; i++) {
1236 printf("%12u\t%10d\t%10x", entry->serverNumber[i],
1237 entry->serverPartition[i], entry->serverFlags[i]);
1239 printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO"));
1246 display_update_entry(struct VldbUpdateEntry *entry, int error)
1252 printf("\nUpdate entry values (Mask=%x)\n", entry->Mask);
1253 if (entry->Mask & VLUPDATE_VOLUMENAME)
1254 printf("\tNew name: %s\n", entry->name);
1255 if (entry->Mask & VLUPDATE_FLAGS)
1256 printf("\tNew flags: %X\n", entry->flags);
1257 if (entry->Mask & VLUPDATE_CLONEID)
1258 printf("\tNew CloneId: %X\n", entry->cloneId);
1259 if (entry->Mask & VLUPDATE_READONLYID)
1260 printf("\tNew RO id: %d\n", entry->ReadOnlyId);
1261 if (entry->Mask & VLUPDATE_BACKUPID)
1262 printf("\tNew BACKUP id: %d\n", entry->BackupId);
1263 if (entry->Mask & VLUPDATE_REPSITES) {
1264 printf("\tRepsites info:\n");
1265 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1266 for (i = 0; i < entry->nModifiedRepsites; i++) {
1267 printf("\t%4x\t%7u\t%5d", entry->RepsitesMask[i],
1268 entry->RepsitesTargetServer[i],
1269 entry->RepsitesTargetPart[i]);
1270 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1271 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV))
1272 printf("\t%7u", entry->RepsitesNewServer[i]);
1274 printf("\t-------");
1275 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1276 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART))
1277 printf("\t%5d", entry->RepsitesNewPart[i]);
1280 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1281 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG))
1282 printf("\t%5x\n", entry->RepsitesNewFlags[i]);
1284 printf("\t-----\n");
1290 dump_stats(vldstats *stats, vital_vlheader *vital_header)
1294 time_t start_time = stats->start_time;
1296 afs_ctime(&start_time, strg, sizeof(strg));
1297 strg[strlen(strg) - 1] = 0;
1298 printf("Dynamic statistics stats (starting time: %s):\n", strg);
1299 printf("OpcodeName\t# Requests\t# Aborts\n");
1300 for (i = 0; i < VL_NUMBER_OPCODESX; i++)
1301 printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i],
1303 printf("\nVldb header stats (version=%d)\n",
1304 ntohl(vital_header->vldbversion));
1305 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1306 ntohl(vital_header->headersize), ntohl(vital_header->allocs),
1307 ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId));
1308 for (i = 0; i < MAXTYPES; i++)
1309 printf("total %s entries=%d\n", volumetype_string(i),
1310 ntohl(vital_header->totalEntries[i]));
1314 GetArgs(char *line, char **args, int *nargs)
1318 register char *last = line;
1319 while (*line == ' ')
1325 *args++ = line, (*nargs)++;
1326 while (*line && *line != ' ')
1334 printf("Valid Commands:\n");
1336 printf(" CreateEntry:\n");
1338 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1340 printf(" DeleteEntry:\n");
1341 printf("\trm <volid> <voltype>\n");
1343 printf(" ReplaceEntry:\n");
1344 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1346 printf(" UpdateEntry:\n");
1348 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1350 printf(" ListEntry:\n");
1353 printf(" Find duplicate entries of a volume\n");
1354 printf("\tldups\n");
1356 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1357 printf("\tcheckhash\n");
1360 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1361 printf("\tfixhash\n");
1363 printf(" ListAttributes:\n");
1364 printf("\tla [server] [partition] [volumeid] [flag]\n");
1366 printf(" ListAttributesN2:\n");
1367 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1369 printf(" GetEntryByID:\n");
1370 printf("\tdi <volid> <voltype>\n");
1372 printf(" UpdateEntry (refresh namehash table):\n");
1373 printf("\trmnh <volid> <voltype>\n");
1375 printf(" GetEntryByName:\n");
1376 printf("\tdn <volname> <voltype>\n");
1378 printf(" UpdateEntry (undelete a vol entry):\n");
1379 printf("\tundelete <volid> <voltype>\n");
1381 * printf(" LinkedList\n");
1382 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1384 * printf(" LinkedListN\n");
1385 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1387 printf(" GetNewVoumeId:\n");
1388 printf("\tnv <bump-count>\n");
1390 printf(" GetStats:\n");
1393 printf(" ChangeAddr:\n");
1394 printf("\tca <oldmachname> <newmachname>\n");
1397 * printf(" ChangeAddr\n");
1398 * printf("\t:caid <oldaddr> <newaddr>\n");
1400 printf(" GetAddrs:\n");
1403 printf(" GetAddrsU:\n");
1406 printf(" RegisterAddrs:\n");
1407 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1409 printf("\tmisc: q, quit, ?, h\n");