2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
26 #include <WINNT/afsevent.h>
28 #ifdef HAVE_SYS_TIME_H
31 #ifdef HAVE_SYS_FILE_H
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
50 #include <afs/afsutil.h>
53 #include <rx/rx_globals.h>
55 #include <afs/cellconfig.h>
63 void fill_listattributes_entry();
64 void display_listattributes_entry();
66 void display_entryN();
67 void display_update_entry();
72 void fill_update_entry();
74 #define VL_NUMBER_OPCODESX 34
75 static char *opcode_names[VL_NUMBER_OPCODESX] = {
121 #define ALLOCNT 50000
122 struct Vlent *VLa[NVOLS];
123 #define VHash(avol) ((avol)&(NVOLS-1))
124 struct Vlent *VL, *SVL;
126 struct ubik_client *cstruct;
127 struct rx_connection *serverconns[MAXSERVERS];
128 char confdir[AFSDIR_PATH_MAX];
132 GetVolume(vol, entry)
133 struct vldbentry *entry;
136 register struct Vlent *vl;
141 for (vl = VLa[i]; vl; vl = vl->next) {
142 if ((vl->rwid == vol && vol != entry->volumeId[0])
143 || (vl->roid == vol && vol != entry->volumeId[1])
144 || (vl->baid == vol && vol != entry->volumeId[2])) {
148 VL->rwid = entry->volumeId[0];
149 VL->roid = entry->volumeId[1];
150 VL->baid = entry->volumeId[2];
151 strcpy(entry->name, VL->name);
154 if (VLcnt++ > ALLOCNT) { /* XXXX FIX XXXXXXXXX */
155 printf("Too many entries (> %d)\n", ALLOCNT);
162 /* Almost identical's to pr_Initialize in vlserver/pruser.c */
164 vl_Initialize(int auth, char *confDir, int server, char *cellp)
166 return ugen_ClientInit(auth?0:1, confDir, cellp, 0,
167 &cstruct, NULL, "vl_Initialize", rxkad_clear,
168 MAXSERVERS, AFSCONF_VLDBSERVICE, 50, server,
169 htons(AFSCONF_VLDBPORT), USER_SERVICE_ID);
172 /* return host address in network byte order */
174 GetServer(char *aname)
176 register struct hostent *th;
179 register afs_int32 code;
181 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
183 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
184 return htonl(addr); /* convert to network order (128 in byte 0) */
186 th = gethostbyname(aname);
189 memcpy(&addr, th->h_addr, sizeof(addr));
196 struct cmd_syndesc *as;
198 register struct cmd_item *ti;
199 register afs_int32 code, server = 0, sawserver = 0;
200 afs_int32 id, voltype;
201 struct vldbentry entry;
202 char *cmd = 0, *cellp = 0;
203 struct VldbUpdateEntry updateentry;
204 struct VldbListByAttributes listbyattributes;
205 int noAuth = 1; /* Default is authenticated connections */
207 if (ti = as->parms[0].items) /* -cellpath <dir> */
208 strcpy(confdir, ti->data);
209 if (as->parms[1].items) /* -server */
210 strcpy(confdir, AFSDIR_SERVER_ETC_DIRPATH);
211 if (as->parms[2].items) /* -noauth */
213 if (ti = as->parms[3].items) { /* -host */
214 server = GetServer(ti->data);
216 printf("server '%s' not found in host table\n", ti->data);
221 if (!sawserver && noAuth && (!(ti = as->parms[4].items))) {
223 ("Must also specify the -cell' option along with -host for authenticated conns\n");
226 if (ti = as->parms[4].items) { /* -cell */
229 if (code = vl_Initialize(noAuth, confdir, server, cellp)) {
230 printf("Couldn't initialize vldb library (code=%d).\n", code);
234 if (as->parms[5].items) { /* -gstats */
236 vital_vlheader vital_header;
237 code = ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header);
239 dump_stats(&stats, &vital_header);
245 int nargs, releasetype;
246 memset(&entry, 0, sizeof(entry));
247 memset(&updateentry, 0, sizeof(updateentry));
248 memset(&listbyattributes, 0, sizeof(listbyattributes));
250 if (fgets(line, 499, stdin) == NULL) {
255 register char **argp = args;
256 GetArgs(line, argp, &nargs);
259 if (!strcmp(oper, "cr")) {
260 fill_entry(&entry, argp, nargs);
261 display_entry(&entry, 0);
262 code = ubik_Call(VL_CreateEntry, cstruct, 0, &entry);
263 printf("return code is %d\n", code);
264 } else if (!strcmp(oper, "rm")) {
265 sscanf(&(*argp)[0], "%d", &id);
267 sscanf(&(*argp)[0], "%d", &voltype);
268 code = ubik_Call(VL_DeleteEntry, cstruct, 0, id, voltype);
269 printf("return code is %d\n", code);
270 } else if (!strcmp(oper, "re")) {
271 sscanf(&(*argp)[0], "%d", &id);
273 sscanf(&(*argp)[0], "%d", &voltype);
275 sscanf(&(*argp)[0], "%d", &releasetype);
277 fill_entry(&entry, argp, nargs);
278 display_entry(&entry, 0);
280 ubik_Call(VL_ReplaceEntry, cstruct, 0, id, voltype,
281 &entry, releasetype);
282 printf("return code is %d\n", code);
283 } else if (!strcmp(oper, "up")) {
284 sscanf(&(*argp)[0], "%d", &id);
286 sscanf(&(*argp)[0], "%d", &voltype);
288 sscanf(&(*argp)[0], "%d", &releasetype);
290 fill_update_entry(&updateentry, argp, nargs);
291 display_update_entry(&updateentry, 0);
293 ubik_Call(VL_UpdateEntry, cstruct, 0, id, voltype,
294 &updateentry, releasetype);
295 printf("return code is %d\n", code);
296 } else if (!strcmp(oper, "ls")) {
297 afs_int32 index, count, next_index;
298 for (index = 0; 1; index = next_index) {
299 memset(&entry, 0, sizeof(entry));
301 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
302 &next_index, &entry);
304 printf("VL_ListEntry returned code = %d\n", code);
309 display_entry(&entry, 0);
311 } else if (!strcmp(oper, "ldups")) {
312 afs_int32 index, count, num = 0, num1 = 0, next_index;
316 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
318 printf("Can't allocate memory...\n");
321 printf("Enumerating all entries in vldb...\n");
322 for (index = 0; 1; index = next_index) {
323 memset(&entry, 0, sizeof(entry));
325 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
326 &next_index, &entry);
328 printf("VL_ListEntry returned code = %d\n", code);
334 if (vl1 = GetVolume(entry.volumeId[0], &entry)) {
337 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
338 entry.volumeId[0], vl1->rwid, vl1->roid,
339 vl1->baid, vl1->name);
341 if (vl1 = GetVolume(entry.volumeId[1], &entry)) {
344 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
345 entry.volumeId[1], vl1->rwid, vl1->roid,
346 vl1->baid, vl1->name);
348 if (vl1 = GetVolume(entry.volumeId[2], &entry)) {
351 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
352 entry.volumeId[2], vl1->rwid, vl1->roid,
353 vl1->baid, vl1->name);
355 /*display_entry(&entry, 0); */
357 printf("(%d vldb entries found - %d duplicates)\n", num,
359 } else if (!strcmp(oper, "checkhash")) {
360 int index, count, num = 0, num1 = 0, num2 = 0, num3 =
361 0, num31 = 0, num4 = 0, num41 = 0, next_index;
362 struct vldbentry tentry;
365 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
367 printf("Can't allocate memory...\n");
370 printf("Volumes not found in main hash tables in vldb...\n");
371 for (index = 0; 1; index = next_index) {
372 memset(&entry, 0, sizeof(entry));
374 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
375 &next_index, &entry);
377 printf("VL_ListEntry returned code = %d\n", code);
384 ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name,
386 if (code == VL_NOENT) {
388 printf("\tVolume %s %d (not in namehash)\n",
389 entry.name, entry.volumeId[RWVOL]);
392 ubik_Call(VL_GetEntryByID, cstruct, 0,
393 entry.volumeId[RWVOL], RWVOL, &tentry);
394 if (code == VL_NOENT) {
396 printf("\tVolume %s %d (not in rwid hash)\n",
397 entry.name, entry.volumeId[RWVOL]);
399 if (entry.volumeId[BACKVOL]) {
401 ubik_Call(VL_GetEntryByID, cstruct, 0,
402 entry.volumeId[BACKVOL], BACKVOL,
405 if (code == VL_NOENT) {
407 printf("\tVolume %s %d (not in backup id hash)\n",
408 entry.name, entry.volumeId[BACKVOL]);
411 if (entry.volumeId[ROVOL]) {
413 ubik_Call(VL_GetEntryByID, cstruct, 0,
414 entry.volumeId[ROVOL], ROVOL, &tentry);
416 if (code == VL_NOENT) {
418 printf("\tVolume %s %d (not in RO id hash)\n",
419 entry.name, entry.volumeId[ROVOL]);
424 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
425 num, num + num31 + num41, num, num31, num41);
427 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
430 ("\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",
431 num3, num31, num4, num41);
432 } else if (!strcmp(oper, "fixhash")) {
433 int index, count, num = 0, num1 = 0, num2 = 0, next_index, x =
435 struct vldbentry tentry;
438 (struct Vlent *)malloc(ALLOCNT * sizeof(struct Vlent));
440 printf("Can't allocate memory...\n");
444 ("Volumes not found in main hash tables in vldb will be fixed...\n");
445 memset(&updateentry, 0, sizeof(updateentry));
446 for (index = 0; 1; index = next_index) {
447 /* FIXME: n2 is never changed for some reason */
448 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
449 memset(&entry, 0, sizeof(entry));
451 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
452 &next_index, &entry);
454 printf("VL_ListEntry returned code = %d\n", code);
461 ubik_Call(VL_GetEntryByNameO, cstruct, 0, entry.name,
463 if (code == VL_NOENT) {
466 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
467 printf("\tVolume %s %d (not in namehash)\n",
468 entry.name, entry.volumeId[RWVOL]);
470 ubik_Call(VL_UpdateEntry, cstruct, 0,
471 entry.volumeId[RWVOL], -1, &updateentry,
475 printf("\tFailed to update volume %s (err=%d)\n",
480 ubik_Call(VL_GetEntryByID, cstruct, 0,
481 entry.volumeId[RWVOL], RWVOL, &tentry);
482 if (code == VL_NOENT) {
485 updateentry.Mask = VLUPDATE_RWID;
486 updateentry.spares3 = entry.volumeId[RWVOL];
487 printf("\tVolume %s %d (not in rw id hash)\n",
488 entry.name, entry.volumeId[RWVOL]);
490 ubik_Call(VL_UpdateEntryByName, cstruct, 0,
491 entry.name, &updateentry, 0);
493 printf("\tFailed to update volume %s (err=%d)\n",
499 if (entry.volumeId[BACKVOL] && !n2) {
501 ubik_Call(VL_GetEntryByID, cstruct, 0,
502 entry.volumeId[BACKVOL], BACKVOL,
504 if (code == VL_NOENT) {
507 updateentry.Mask = VLUPDATE_BACKUPID;
508 updateentry.BackupId = entry.volumeId[BACKVOL];
509 printf("\tVolume %s %d (not in backup id hash)\n",
510 entry.name, entry.volumeId[BACKVOL]);
512 ubik_Call(VL_UpdateEntry, cstruct, 0,
513 entry.volumeId[RWVOL], -1,
517 ("\tFailed to update volume %s (err=%d)\n",
523 if (entry.volumeId[ROVOL && !n2]) {
525 ubik_Call(VL_GetEntryByID, cstruct, 0,
526 entry.volumeId[ROVOL], ROVOL, &tentry);
527 if (code == VL_NOENT) {
530 updateentry.Mask = VLUPDATE_READONLYID;
531 updateentry.ReadOnlyId = entry.volumeId[ROVOL];
532 printf("\tVolume %s %d (not in RO id hash)\n",
533 entry.name, entry.volumeId[ROVOL]);
535 ubik_Call(VL_UpdateEntry, cstruct, 0,
536 entry.volumeId[RWVOL], -1,
540 ("\tFailed to update volume %s (err=%d)\n",
548 ("\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",
550 } else if (!strcmp(oper, "la")) {
553 struct vldbentry *entry;
555 memset(&entries, 0, sizeof(entries));
556 fill_listattributes_entry(&listbyattributes, argp, nargs);
557 display_listattributes_entry(&listbyattributes, 0);
559 ubik_Call(VL_ListAttributes, cstruct, 0,
560 &listbyattributes, &nentries, &entries);
562 printf("VL_ListAttributes returned code = %d\n", code);
565 entry = (struct vldbentry *)entries.bulkentries_val;
566 for (i = 0; i < nentries; i++, entry++)
567 display_entry(entry, 0);
568 if (entries.bulkentries_val)
569 free((char *)entries.bulkentries_val);
570 } else if (!strcmp(oper, "lan2")) {
571 int nentries, i, si, nsi, t = 0;
572 nbulkentries entries;
573 struct nvldbentry *entry;
576 /* The volume name to search for (supports wildcarding) */
578 strcpy(name, argp[0]);
584 fill_listattributes_entry(&listbyattributes, argp, nargs);
585 display_listattributes_entry(&listbyattributes, 0);
586 printf("Wildcard VolName: '%s'\n", name);
588 for (si = 0; si != -1; si = nsi) {
590 memset(&entries, 0, sizeof(entries));
592 ubik_Call(VL_ListAttributesN2, cstruct, 0,
593 &listbyattributes, name, si, &nentries,
596 printf("VL_ListAttributesN2 returned code = %d\n",
602 entry = (struct nvldbentry *)entries.nbulkentries_val;
603 for (i = 0; i < nentries; i++, entry++)
604 display_entryN(entry, 0);
605 if (entries.nbulkentries_val)
606 free((char *)entries.nbulkentries_val);
608 printf("--- %d volumes ---\n", t);
609 } else if (!strcmp(oper, "ln")) {
611 vldb_list linkedvldbs;
612 vldblist vllist, vllist1;
614 fill_listattributes_entry(&listbyattributes, argp, nargs);
615 display_listattributes_entry(&listbyattributes, 0);
616 memset(&linkedvldbs, 0, sizeof(vldb_list));
618 ubik_Call(VL_LinkedList, cstruct, 0, &listbyattributes,
619 &netries, &linkedvldbs);
621 printf("VL_LinkedList returned code = %d\n", code);
624 printf("Found %d entr%s\n", netries,
625 (netries == 1 ? "y" : "ies"));
626 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
627 vllist1 = vllist->next_vldb;
628 display_entry(&vllist->VldbEntry, 0);
629 free((char *)vllist);
631 } else if (!strcmp(oper, "lnn")) {
633 nvldb_list linkedvldbs;
634 nvldblist vllist, vllist1;
636 fill_listattributes_entry(&listbyattributes, argp, nargs);
637 display_listattributes_entry(&listbyattributes, 0);
638 memset(&linkedvldbs, 0, sizeof(vldb_list));
640 ubik_Call(VL_LinkedListN, cstruct, 0, &listbyattributes,
641 &netries, &linkedvldbs);
643 printf("VL_LinkedList returned code = %d\n", code);
646 printf("Found %d entr%s\n", netries,
647 (netries == 1 ? "y" : "ies"));
648 for (vllist = linkedvldbs.node; vllist; vllist = vllist1) {
649 vllist1 = vllist->next_vldb;
650 display_entry(&vllist->VldbEntry, 0);
651 free((char *)vllist);
653 } else if (!strcmp(oper, "di")) {
654 sscanf(&(*argp)[0], "%d", &id);
656 sscanf(&(*argp)[0], "%d", &voltype);
658 ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype,
660 display_entry(&entry, code);
661 printf("return code is %d.\n", code);
662 } else if (!strcmp(oper, "rmnh")) {
663 sscanf(&(*argp)[0], "%d", &id);
665 sscanf(&(*argp)[0], "%d", &voltype);
667 ubik_Call(VL_GetEntryByID, cstruct, 0, id, voltype,
669 display_entry(&entry, code);
670 memset(&updateentry, 0, sizeof(updateentry));
671 updateentry.Mask = VLUPDATE_VOLNAMEHASH;
672 printf("\tRehashing namehash table for %s (%d)\n", entry.name,
673 entry.volumeId[RWVOL]);
675 ubik_Call(VL_UpdateEntry, cstruct, 0,
676 entry.volumeId[RWVOL], -1, &updateentry, 0);
678 printf("\tFailed to update volume %s (err=%d)\n",
681 printf("return code is %d.\n", code);
682 } else if (!strcmp(oper, "undelete")) {
683 afs_int32 index, count, next_index;
685 memset(&updateentry, 0, sizeof(updateentry));
686 sscanf(&(*argp)[0], "%d", &id);
688 sscanf(&(*argp)[0], "%d", &voltype);
689 if (voltype < 0 && voltype > 2) {
690 printf("Illegal voltype; must be 0, 1 or 2\n");
693 printf("Searching vldb for volume %d...\n", id);
694 for (index = 0; 1; index = next_index) {
695 memset(&entry, 0, sizeof(entry));
697 ubik_Call(VL_ListEntry, cstruct, 0, index, &count,
698 &next_index, &entry);
700 printf("VL_ListEntry returned code = %d\n", code);
705 if (entry.volumeId[voltype] == id) {
706 printf("\nThe current contents of the vldb for %d:\n",
708 display_entry(&entry, 0);
710 if (entry.flags & VLDELETED) {
711 updateentry.Mask = VLUPDATE_FLAGS;
712 updateentry.flags = entry.flags;
713 updateentry.flags &= ~VLDELETED;
715 ("\tUndeleting vldb entry for vol %d (%s)\n",
718 ubik_Call(VL_UpdateEntry, cstruct, 0, id, -1,
722 ("\tFailed to update volume %s (err=%d)\n",
726 printf("Entry not deleted; ignored\n");
731 } else if (!strcmp(oper, "dn")) {
734 ubik_Call(VL_GetEntryByNameO, cstruct, 0, vname, &entry);
735 display_entry(&entry, code);
736 printf("return code is %d.\n", code);
737 } else if (!strcmp(oper, "nv")) {
739 sscanf(&(*argp)[0], "%d", &id);
741 ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &newvolid);
743 printf("Current Max volid is (in hex):%X\n", newvolid);
744 printf("return code is %d\n", code);
745 } else if (!strcmp(oper, "gs")) {
747 vital_vlheader vital_header;
749 ubik_Call(VL_GetStats, cstruct, 0, &stats, &vital_header);
751 dump_stats(&stats, &vital_header);
752 printf("return code is %d.\n", code);
753 } else if (!strcmp(oper, "ga")) {
757 struct VLCallBack vlcb;
759 addrs.bulkaddrs_val = 0;
760 addrs.bulkaddrs_len = 0;
761 code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ ,
762 0 /*spare2 */ , &vlcb,
765 printf("VL_GetAddrs returned code = %d\n", code);
768 addrp = addrs.bulkaddrs_val;
769 for (i = 0; i < nentries; i++, addrp++) {
770 if ((*addrp & 0xff000000) == 0xff000000)
771 printf("[0x%x %u] (special multi-homed entry)\n",
774 printf("[0x%x %u] %s\n", *addrp, *addrp,
775 hostutil_GetNameByINet(ntohl(*addrp)));
777 free((char *)addrs.bulkaddrs_val);
778 } else if (!strcmp(oper, "gau")) {
782 struct VLCallBack vlcb;
784 addrs.bulkaddrs_val = 0;
785 addrs.bulkaddrs_len = 0;
786 code = ubik_Call(VL_GetAddrs, cstruct, 0, 0 /*Handle */ ,
787 0 /*spare2 */ , &vlcb,
790 printf("VL_GetAddrs returned code = %d\n", code);
793 addrp = addrs.bulkaddrs_val;
794 for (i = 0; i < nentries; i++, addrp++) {
795 if ((*addrp & 0xff000000) == 0xff000000) {
796 int mhnentries, unique;
797 struct in_addr hostAddr;
800 ListAddrByAttributes attrs;
803 printf("[0x%x %u] (special multi-homed entry)\n",
805 attrs.Mask = VLADDR_INDEX;
806 mhaddrs.bulkaddrs_val = 0;
807 mhaddrs.bulkaddrs_len = 0;
808 attrs.index = *addrp & 0x00ffffff;
811 ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid,
812 &unique, &mhnentries, &mhaddrs);
814 printf("VL_GetAddrsU returned code = %d\n", code);
818 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
819 attrs.index, uuid.time_low, uuid.time_mid,
820 uuid.time_hi_and_version,
821 uuid.clock_seq_hi_and_reserved,
822 uuid.clock_seq_low, uuid.node[0], uuid.node[1],
823 uuid.node[2], uuid.node[3], uuid.node[4],
824 uuid.node[5], unique);
825 mhaddrp = mhaddrs.bulkaddrs_val;
826 for (j = 0; j < mhnentries; j++) {
827 mhaddrp[j] = ntohl(mhaddrp[j]);
828 hostAddr.s_addr = mhaddrp[j];
829 printf("\t%s (%s)\n", inet_ntoa(hostAddr),
830 hostutil_GetNameByINet(mhaddrp[j]));
832 if (mhaddrs.bulkaddrs_val)
833 free((char *)mhaddrs.bulkaddrs_val);
835 printf("[0x%x %u] %s\n", *addrp, *addrp,
836 hostutil_GetNameByINet(ntohl(*addrp)));
839 free((char *)addrs.bulkaddrs_val);
840 } else if (!strcmp(oper, "mhc")) {
841 afs_int32 serveraddrs[MAXSERVERID + 1][VL_MAXIPADDRS_PERMH];
842 afs_int32 serveraddrtype[MAXSERVERID + 1];
843 int nentries1, nentries2, i, j, x, y, unique, found;
844 afs_uint32 *addrp1, *addrp2;
845 bulkaddrs addrs1, addrs2;
846 struct VLCallBack vlcb;
847 ListAddrByAttributes attrs;
849 afs_int32 base, index;
851 for (i = 0; i < MAXSERVERID + 1; i++) {
852 serveraddrtype[i] = 0;
853 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
854 serveraddrs[i][j] = 0;
857 /* Collect a list of all registered IP addresses */
858 addrs1.bulkaddrs_val = 0;
859 addrs1.bulkaddrs_len = 0;
861 ubik_Call(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb,
862 &nentries1, &addrs1);
864 printf("VL_GetAddrs returned code = %d\n", code);
867 addrp1 = addrs1.bulkaddrs_val;
868 for (i = 0; i < nentries1; i++, addrp1++) {
869 if ((*addrp1 & 0xff000000) != 0xff000000) {
870 serveraddrs[i][0] = ntohl(*addrp1);
871 serveraddrtype[i] = 1;
873 /* It's multihomed. Get all of its addresses */
874 serveraddrtype[i] = 2;
875 base = (*addrp1 >> 16) & 0xff;
876 index = *addrp1 & 0xffff;
878 addrs2.bulkaddrs_val = 0;
879 addrs2.bulkaddrs_len = 0;
880 attrs.Mask = VLADDR_INDEX;
881 attrs.index = (base * VL_MHSRV_PERBLK) + index;
883 ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid,
884 &unique, &nentries2, &addrs2);
886 printf("VL_GetAddrsU returned code = %d\n", code);
890 addrp2 = addrs2.bulkaddrs_val;
891 for (j = 0; j < nentries2; j++) {
892 serveraddrs[i][j] = ntohl(addrp2[j]);
894 free((char *)addrs2.bulkaddrs_val);
898 if (serveraddrtype[i] == 1) {
899 printf("%u\n", serveraddrs[i][0]);
902 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
903 if (serveraddrs[i][j])
904 printf(" %u", serveraddrs[i][j]);
909 free((char *)addrs1.bulkaddrs_val);
911 /* Look for any duplicates */
912 for (i = 0; i < MAXSERVERID + 1; i++) {
913 if (!serveraddrtype[i])
915 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
916 if (!serveraddrs[i][j])
920 for (x = i + 1; x < MAXSERVERID + 1; x++) {
921 if (!serveraddrtype[x])
923 for (y = 0; y < VL_MAXIPADDRS_PERMH; y++) {
924 if (!serveraddrs[x][y])
926 if (serveraddrs[i][j] == serveraddrs[x][y]) {
927 serveraddrs[x][y] = 0;
934 ("Found %d entries of IP address %u (0x%x)\n",
935 found + 1, serveraddrs[i][j],
941 /*----------------------------------------*/
943 } else if (!strcmp(oper, "regaddr")) {
945 afs_uint32 *addrp, tad;
949 memset(&uuid, 0, sizeof(uuid));
950 sscanf(&(*argp)[0], "%d", &i);
952 memcpy(uuid.node, &i, sizeof(i));
954 if (nargs < 0 || nargs > 16) {
955 printf("Illegal # entries = %d\n", nargs);
958 addrp = (afs_uint32 *) malloc(20 * 4);
959 addrs.bulkaddrs_val = addrp;
960 addrs.bulkaddrs_len = nargs;
962 sscanf(&(*argp)[0], "%d", &tad);
967 ubik_Call(VL_RegisterAddrs, cstruct, 0, &uuid,
968 0 /*spare */ , &addrs);
970 printf("VL_RegisterAddrs returned code = %d\n", code);
973 } else if (!strcmp(oper, "ca")) {
974 extern struct hostent *hostutil_GetHostByName();
975 struct hostent *h1, *h2;
978 printf("changing %s", *argp);
979 h1 = hostutil_GetHostByName(&(*argp)[0]);
981 printf("cmdebug: can't resolve address for host %s",
985 memcpy(&a1, (afs_int32 *) h1->h_addr, sizeof(afs_uint32));
988 printf(" to %s\n", *argp);
989 h2 = hostutil_GetHostByName(&(*argp)[0]);
991 printf("cmdebug: can't resolve address for host %s",
995 memcpy(&a2, (afs_int32 *) h2->h_addr, sizeof(afs_uint32));
997 printf("changing 0x%x to 0x%x\n", ntohl(a1), ntohl(a2));
999 ubik_Call(VL_ChangeAddr, cstruct, 0, ntohl(a1),
1002 printf("VL_ChangeAddr returned code = %d\n", code);
1005 } else if (!strcmp(oper, "caid")) {
1008 sscanf(&(*argp)[0], "%d", &a1);
1009 printf("changing %d (0x%x)", a1, a1);
1011 sscanf(&(*argp)[0], "%d", &a2);
1012 printf(" to %d (0x%x)\n", a2, a2);
1013 code = ubik_Call(VL_ChangeAddr, cstruct, 0, a1, a2);
1015 printf("VL_ChangeAddr returned code = %d\n", code);
1018 } else if ((!strcmp(oper, "?")) || !strcmp(oper, "h"))
1020 else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
1023 printf("Unknown oper!\n");
1030 #include "AFS_component_version_number.c"
1036 register struct cmd_syndesc *ts;
1039 strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
1040 ts = cmd_CreateSyntax("initcmd", handleit, 0, "initialize the program");
1041 cmd_AddParm(ts, "-cellpath", CMD_LIST, CMD_OPTIONAL,
1042 "Cell configuration directory");
1043 cmd_AddParm(ts, "-server", CMD_LIST, CMD_OPTIONAL,
1044 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1045 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1046 "Run it without authentication");
1047 cmd_AddParm(ts, "-host", CMD_LIST, CMD_OPTIONAL,
1048 "vldb server to talk to");
1049 cmd_AddParm(ts, "-cell", CMD_LIST, CMD_OPTIONAL,
1050 "cellname '-host' belongs to (required for auth conns)");
1051 cmd_AddParm(ts, "-getstats", CMD_FLAG, CMD_OPTIONAL,
1052 "print vldb statistics (non interactive)");
1053 code = cmd_Dispatch(argc, argv);
1059 fill_entry(entry, argp, nargs)
1060 struct vldbentry *entry;
1069 sscanf(&(*argp)[0], "%d", &entry->spares3);
1071 sscanf(&(*argp)[0], "%d", &entry->nServers);
1072 strcpy(entry->name, name);
1073 for (i = 0; i < entry->nServers; i++) {
1075 sscanf(&(*argp)[0], "%u", &entry->serverNumber[i]);
1077 for (i = 0; i < entry->nServers; i++) {
1079 sscanf(&(*argp)[0], "%d", &entry->serverPartition[i]);
1081 for (i = 0; i < entry->nServers; i++) {
1083 sscanf(&(*argp)[0], "%d", &entry->serverFlags[i]);
1085 for (i = 0; i < MAXTYPES; i++) {
1087 sscanf(&(*argp)[0], "%d", &entry->volumeId[i]);
1090 sscanf(&(*argp)[0], "%d", &entry->flags);
1092 sscanf(&(*argp)[0], "%d", &entry->cloneId);
1096 fill_update_entry(entry, argp, nargs)
1097 struct VldbUpdateEntry *entry;
1106 if (strcmp(name, "null")) {
1107 strcpy(entry->name, name);
1108 entry->Mask |= VLUPDATE_VOLUMENAME;
1111 sscanf(&(*argp)[0], "%d", &entry->flags);
1112 if (entry->flags != -1)
1113 entry->Mask |= VLUPDATE_FLAGS;
1115 sscanf(&(*argp)[0], "%d", &entry->cloneId);
1116 if (entry->flags != -1)
1117 entry->Mask |= VLUPDATE_CLONEID;
1119 sscanf(&(*argp)[0], "%d", &entry->ReadOnlyId);
1120 if (entry->ReadOnlyId != -1)
1121 entry->Mask |= VLUPDATE_READONLYID;
1123 sscanf(&(*argp)[0], "%d", &entry->BackupId);
1124 if (entry->BackupId != -1)
1125 entry->Mask |= VLUPDATE_BACKUPID;
1127 sscanf(&(*argp)[0], "%d", &entry->nModifiedRepsites);
1128 if (entry->nModifiedRepsites != -1)
1129 entry->Mask |= VLUPDATE_REPSITES;
1130 for (i = 0; i < entry->nModifiedRepsites; i++) {
1132 sscanf(&(*argp)[0], "%x", &Mask);
1134 sscanf(&(*argp)[0], "%u", &entry->RepsitesTargetServer[i]);
1136 sscanf(&(*argp)[0], "%d", &entry->RepsitesTargetPart[i]);
1137 if (Mask & VLUPDATE_REPS_DELETE)
1138 entry->RepsitesMask[i] |= VLUPDATE_REPS_DELETE;
1139 if (Mask & VLUPDATE_REPS_MODSERV) {
1141 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1142 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODSERV;
1143 } else if (Mask & VLUPDATE_REPS_MODPART) {
1145 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1146 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODPART;
1147 } else if (Mask & VLUPDATE_REPS_MODFLAG) {
1149 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1150 entry->RepsitesMask[i] |= VLUPDATE_REPS_MODFLAG;
1151 } else if (Mask & VLUPDATE_REPS_ADD) {
1153 sscanf(&(*argp)[0], "%u", &entry->RepsitesNewServer[i]);
1155 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewPart[i]);
1157 sscanf(&(*argp)[0], "%d", &entry->RepsitesNewFlags[i]);
1158 entry->RepsitesMask[i] |= VLUPDATE_REPS_ADD;
1164 fill_listattributes_entry(entry, argp, nargs)
1165 struct VldbListByAttributes *entry;
1173 entry->server = ntohl(GetServer(argp[0]));
1174 sscanf(&(*argp)[0], "%d", &entry->server);
1175 if (entry->server != 0)
1176 entry->Mask |= VLLIST_SERVER;
1181 sscanf(&(*argp)[0], "%d", &entry->partition);
1182 if (entry->partition != -1)
1183 entry->Mask |= VLLIST_PARTITION;
1188 sscanf(&(*argp)[0], "%d", &entry->volumeid);
1189 if (entry->volumeid != -1)
1190 entry->Mask |= VLLIST_VOLUMEID;
1195 sscanf(&(*argp)[0], "%d", &entry->flag);
1196 if (entry->flag != -1)
1197 entry->Mask |= VLLIST_FLAG;
1201 display_listattributes_entry(entry, error)
1202 struct VldbListByAttributes *entry;
1207 printf("\nList entry values (Mask=%x)\n", entry->Mask);
1208 if (entry->Mask & VLLIST_SERVER)
1209 printf("\tServer: %d.%d.%d.%d\n", (entry->server >> 24) & 0xff,
1210 (entry->server >> 16) & 0xff, (entry->server >> 8) & 0xff,
1211 (entry->server) & 0xff);
1212 if (entry->Mask & VLLIST_PARTITION)
1213 printf("\tPartition: %d\n", entry->partition);
1214 if (entry->Mask & VLLIST_VOLUMEID)
1215 printf("\tVolumeId: %u\n", entry->volumeid);
1216 if (entry->Mask & VLLIST_FLAG)
1217 printf("\tFlag: %x\n", entry->flag);
1221 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1224 display_entry(entry, error)
1225 struct vldbentry *entry;
1232 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1233 entry->name, entry->volumeId[RWVOL], entry->flags);
1234 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1235 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1237 printf("nServers=%d\n", entry->nServers);
1238 printf("ServerNumber\tServerPart\tserverFlag\n");
1239 for (i = 0; i < entry->nServers; i++)
1240 printf("%12u\t%10d\t%10x\n", entry->serverNumber[i],
1241 entry->serverPartition[i], entry->serverFlags[i]);
1245 display_entryN(entry, error)
1246 struct nvldbentry *entry;
1253 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1254 entry->name, entry->volumeId[RWVOL], entry->flags);
1255 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1256 entry->volumeId[0], entry->volumeId[1], entry->volumeId[2],
1258 printf("nServers=%d\n", entry->nServers);
1259 printf("ServerNumber\tServerPart\tserverFlag\n");
1260 ei = entry->matchindex & 0xffff;
1261 et = (entry->matchindex >> 16) & 0xffff;
1262 for (i = 0; i < entry->nServers; i++) {
1263 printf("%12u\t%10d\t%10x", entry->serverNumber[i],
1264 entry->serverPartition[i], entry->serverFlags[i]);
1266 printf(" <--- %s", (et == 4) ? "RW" : ((et == 8) ? "BK" : "RO"));
1273 display_update_entry(entry, error)
1274 struct VldbUpdateEntry *entry;
1281 printf("\nUpdate entry values (Mask=%x)\n", entry->Mask);
1282 if (entry->Mask & VLUPDATE_VOLUMENAME)
1283 printf("\tNew name: %s\n", entry->name);
1284 if (entry->Mask & VLUPDATE_FLAGS)
1285 printf("\tNew flags: %X\n", entry->flags);
1286 if (entry->Mask & VLUPDATE_CLONEID)
1287 printf("\tNew CloneId: %X\n", entry->cloneId);
1288 if (entry->Mask & VLUPDATE_READONLYID)
1289 printf("\tNew RO id: %D\n", entry->ReadOnlyId);
1290 if (entry->Mask & VLUPDATE_BACKUPID)
1291 printf("\tNew BACKUP id: %D\n", entry->BackupId);
1292 if (entry->Mask & VLUPDATE_REPSITES) {
1293 printf("\tRepsites info:\n");
1294 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1295 for (i = 0; i < entry->nModifiedRepsites; i++) {
1296 printf("\t%4x\t%7U\t%5d", entry->RepsitesMask[i],
1297 entry->RepsitesTargetServer[i],
1298 entry->RepsitesTargetPart[i]);
1299 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1300 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODSERV))
1301 printf("\t%7U", entry->RepsitesNewServer[i]);
1303 printf("\t-------");
1304 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1305 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODPART))
1306 printf("\t%5d", entry->RepsitesNewPart[i]);
1309 if ((entry->RepsitesMask[i] & VLUPDATE_REPS_ADD)
1310 || (entry->RepsitesMask[i] & VLUPDATE_REPS_MODFLAG))
1311 printf("\t%5x\n", entry->RepsitesNewFlags[i]);
1313 printf("\t-----\n");
1319 dump_stats(stats, vital_header)
1321 vital_vlheader *vital_header;
1325 time_t start_time = stats->start_time;
1327 strncpy(strg, ctime(&start_time), sizeof(strg));
1328 strg[strlen(strg) - 1] = 0;
1329 printf("Dynamic statistics stats (starting time: %s):\n", strg);
1330 printf("OpcodeName\t# Requests\t# Aborts\n");
1331 for (i = 0; i < VL_NUMBER_OPCODESX; i++)
1332 printf("%10s\t%10d\t%8d\n", opcode_names[i], stats->requests[i],
1334 printf("\nVldb header stats (version=%d)\n",
1335 ntohl(vital_header->vldbversion));
1336 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1337 ntohl(vital_header->headersize), ntohl(vital_header->allocs),
1338 ntohl(vital_header->frees), ntohl(vital_header->MaxVolumeId));
1339 for (i = 0; i < MAXTYPES; i++)
1340 printf("total %s entries=%d\n", volumetype_string(i),
1341 ntohl(vital_header->totalEntries[i]));
1345 GetArgs(line, args, nargs)
1346 register char *line;
1347 register char **args;
1348 register int *nargs;
1352 register char *last = line;
1353 while (*line == ' ')
1359 *args++ = line, (*nargs)++;
1360 while (*line && *line != ' ')
1368 printf("Valid Commands:\n");
1370 printf(" CreateEntry:\n");
1372 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1374 printf(" DeleteEntry:\n");
1375 printf("\trm <volid> <voltype>\n");
1377 printf(" ReplaceEntry:\n");
1378 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1380 printf(" UpdateEntry:\n");
1382 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1384 printf(" ListEntry:\n");
1387 printf(" Find duplicate entries of a volume\n");
1388 printf("\tldups\n");
1390 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1391 printf("\tcheckhash\n");
1394 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1395 printf("\tfixhash\n");
1397 printf(" ListAttributes:\n");
1398 printf("\tla [server] [partition] [volumeid] [flag]\n");
1400 printf(" ListAttributesN2:\n");
1401 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1403 printf(" GetEntryByID:\n");
1404 printf("\tdi <volid> <voltype>\n");
1406 printf(" UpdateEntry (refresh namehash table):\n");
1407 printf("\trmnh <volid> <voltype>\n");
1409 printf(" GetEntryByName:\n");
1410 printf("\tdn <volname> <voltype>\n");
1412 printf(" UpdateEntry (undelete a vol entry):\n");
1413 printf("\tundelete <volid> <voltype>\n");
1415 * printf(" LinkedList\n");
1416 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1418 * printf(" LinkedListN\n");
1419 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1421 printf(" GetNewVoumeId:\n");
1422 printf("\tnv <bump-count>\n");
1424 printf(" GetStats:\n");
1427 printf(" ChangeAddr:\n");
1428 printf("\tca <oldmachname> <newmachname>\n");
1431 * printf(" ChangeAddr\n");
1432 * printf("\t:caid <oldaddr> <newaddr>\n");
1434 printf(" GetAddrs:\n");
1437 printf(" GetAddrsU:\n");
1440 printf(" RegisterAddrs:\n");
1441 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1443 printf("\tmisc: q, quit, ?, h\n");