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
] = {
63 "Probe", /* RPC is ProbeServer */
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
[6].items
) { /* -probe */
212 for (i
= 0; cstruct
->conns
[i
]; i
++, nconns
++) {
213 rx_SetConnDeadTime(cstruct
->conns
[i
], 6);
214 addr
= rx_HostOf(rx_PeerOf(cstruct
->conns
[i
]));
218 printf(" %s", afs_inet_ntoa_r(addr
, hoststr
));
221 printf("no connections\n");
225 multi_Rx(cstruct
->conns
, nconns
) {
226 multi_VL_ProbeServer();
227 addr
= rx_HostOf(rx_PeerOf(cstruct
->conns
[multi_i
]));
229 printf(" ok: %s\n", afs_inet_ntoa_r(addr
, hoststr
));
232 printf(" not ok (%d): %s\n", multi_error
,
233 afs_inet_ntoa_r(addr
, hoststr
));
240 if (as
->parms
[5].items
) { /* -getstats */
242 vital_vlheader vital_header
;
243 code
= ubik_VL_GetStats(cstruct
, 0, &stats
, &vital_header
);
245 dump_stats(&stats
, &vital_header
);
251 int nargs
, releasetype
;
252 memset(&entry
, 0, sizeof(entry
));
253 memset(&updateentry
, 0, sizeof(updateentry
));
254 memset(&listbyattributes
, 0, sizeof(listbyattributes
));
256 if (fgets(line
, 499, stdin
) == NULL
) {
263 GetArgs(line
, argp
, &nargs
);
267 } else if (!strcmp(oper
, "cr")) {
268 fill_entry(&entry
, argp
, nargs
);
269 display_entry(&entry
, 0);
270 code
= ubik_VL_CreateEntry(cstruct
, 0, &entry
);
271 printf("return code is %d\n", code
);
272 } else if (!strcmp(oper
, "rm")) {
273 sscanf(&(*argp
)[0], "%d", &id
);
275 sscanf(&(*argp
)[0], "%d", &voltype
);
276 code
= ubik_VL_DeleteEntry(cstruct
, 0, id
, voltype
);
277 printf("return code is %d\n", code
);
278 } else if (!strcmp(oper
, "re")) {
279 sscanf(&(*argp
)[0], "%d", &id
);
281 sscanf(&(*argp
)[0], "%d", &voltype
);
283 sscanf(&(*argp
)[0], "%d", &releasetype
);
285 fill_entry(&entry
, argp
, nargs
);
286 display_entry(&entry
, 0);
288 ubik_VL_ReplaceEntry(
289 cstruct
, 0, id
, voltype
,
290 &entry
, releasetype
);
291 printf("return code is %d\n", code
);
292 } else if (!strcmp(oper
, "up")) {
293 sscanf(&(*argp
)[0], "%d", &id
);
295 sscanf(&(*argp
)[0], "%d", &voltype
);
297 sscanf(&(*argp
)[0], "%d", &releasetype
);
299 fill_update_entry(&updateentry
, argp
, nargs
);
300 display_update_entry(&updateentry
, 0);
302 ubik_VL_UpdateEntry(cstruct
, 0, id
, voltype
,
303 &updateentry
, releasetype
);
304 printf("return code is %d\n", code
);
305 } else if (!strcmp(oper
, "ls")) {
306 afs_int32 index
, count
, next_index
;
307 for (index
= 0; 1; index
= next_index
) {
308 memset(&entry
, 0, sizeof(entry
));
310 ubik_VL_ListEntry(cstruct
, 0, index
, &count
,
311 &next_index
, &entry
);
313 printf("VL_ListEntry returned code = %d\n", code
);
318 display_entry(&entry
, 0);
320 } else if (!strcmp(oper
, "ldups")) {
321 afs_int32 index
, count
, num
= 0, num1
= 0, next_index
;
324 VL
= SVL
= malloc(ALLOCNT
* sizeof(struct Vlent
));
326 printf("Can't allocate memory...\n");
329 printf("Enumerating all entries in vldb...\n");
330 for (index
= 0; 1; index
= next_index
) {
331 memset(&entry
, 0, sizeof(entry
));
333 ubik_VL_ListEntry(cstruct
, 0, index
, &count
,
334 &next_index
, &entry
);
336 printf("VL_ListEntry returned code = %d\n", code
);
342 if ((vl1
= GetVolume(entry
.volumeId
[0], &entry
))) {
345 ("Duplicate entry is found for RW vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
346 entry
.volumeId
[0], vl1
->rwid
, vl1
->roid
,
347 vl1
->baid
, vl1
->name
);
349 if ((vl1
= GetVolume(entry
.volumeId
[1], &entry
))) {
352 ("Duplicate entry is found for RO vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
353 entry
.volumeId
[1], vl1
->rwid
, vl1
->roid
,
354 vl1
->baid
, vl1
->name
);
356 if ((vl1
= GetVolume(entry
.volumeId
[2], &entry
))) {
359 ("Duplicate entry is found for BA vol %u: [RW %u, RO %u, BA %u, name=%s]\n",
360 entry
.volumeId
[2], vl1
->rwid
, vl1
->roid
,
361 vl1
->baid
, vl1
->name
);
363 /*display_entry(&entry, 0); */
365 printf("(%d vldb entries found - %d duplicates)\n", num
,
367 } else if (!strcmp(oper
, "checkhash")) {
368 int index
, count
, num
= 0, num1
= 0, num2
= 0, num3
=
369 0, num31
= 0, num4
= 0, num41
= 0, next_index
;
370 struct vldbentry tentry
;
372 VL
= SVL
= malloc(ALLOCNT
* sizeof(struct Vlent
));
374 printf("Can't allocate memory...\n");
377 printf("Volumes not found in main hash tables in vldb...\n");
378 for (index
= 0; 1; index
= next_index
) {
379 memset(&entry
, 0, sizeof(entry
));
381 ubik_VL_ListEntry(cstruct
, 0, index
, &count
,
382 &next_index
, &entry
);
384 printf("VL_ListEntry returned code = %d\n", code
);
391 ubik_VL_GetEntryByNameO(cstruct
, 0, entry
.name
,
393 if (code
== VL_NOENT
) {
395 printf("\tVolume %s %d (not in namehash)\n",
396 entry
.name
, entry
.volumeId
[RWVOL
]);
399 ubik_VL_GetEntryByID(cstruct
, 0,
400 entry
.volumeId
[RWVOL
], RWVOL
, &tentry
);
401 if (code
== VL_NOENT
) {
403 printf("\tVolume %s %d (not in rwid hash)\n",
404 entry
.name
, entry
.volumeId
[RWVOL
]);
406 if (entry
.volumeId
[BACKVOL
]) {
408 ubik_VL_GetEntryByID(cstruct
, 0,
409 entry
.volumeId
[BACKVOL
], BACKVOL
,
412 if (code
== VL_NOENT
) {
414 printf("\tVolume %s %d (not in backup id hash)\n",
415 entry
.name
, entry
.volumeId
[BACKVOL
]);
418 if (entry
.volumeId
[ROVOL
]) {
420 ubik_VL_GetEntryByID(cstruct
, 0,
421 entry
.volumeId
[ROVOL
], ROVOL
, &tentry
);
423 if (code
== VL_NOENT
) {
425 printf("\tVolume %s %d (not in RO id hash)\n",
426 entry
.name
, entry
.volumeId
[ROVOL
]);
431 ("\nTotal vldb entries %d\nTotal volumes %d (%d rw, %d backup, %d ro)\n",
432 num
, num
+ num31
+ num41
, num
, num31
, num41
);
434 ("\n\t%d didn't hash properly by name\n\t%d didn't hash properly by rw volid\n",
437 ("\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",
438 num3
, num31
, num4
, num41
);
439 } else if (!strcmp(oper
, "fixhash")) {
440 int index
, count
, num
= 0, num1
= 0, num2
= 0, next_index
, x
=
442 struct vldbentry tentry
;
444 VL
= SVL
= malloc(ALLOCNT
* sizeof(struct Vlent
));
446 printf("Can't allocate memory...\n");
450 ("Volumes not found in main hash tables in vldb will be fixed...\n");
451 memset(&updateentry
, 0, sizeof(updateentry
));
452 for (index
= 0; 1; index
= next_index
) {
453 memset(&entry
, 0, sizeof(entry
));
455 ubik_VL_ListEntry(cstruct
, 0, index
, &count
,
456 &next_index
, &entry
);
458 printf("VL_ListEntry returned code = %d\n", code
);
465 ubik_VL_GetEntryByNameO(cstruct
, 0, entry
.name
,
467 if (code
== VL_NOENT
) {
469 updateentry
.Mask
= VLUPDATE_VOLNAMEHASH
;
470 printf("\tVolume %s %d (not in namehash)\n",
471 entry
.name
, entry
.volumeId
[RWVOL
]);
473 ubik_VL_UpdateEntry(cstruct
, 0,
474 entry
.volumeId
[RWVOL
], -1, &updateentry
,
478 printf("\tFailed to update volume %s (err=%d)\n",
483 ubik_VL_GetEntryByID(cstruct
, 0,
484 entry
.volumeId
[RWVOL
], RWVOL
, &tentry
);
485 if (code
== VL_NOENT
) {
488 updateentry
.Mask
= VLUPDATE_RWID
;
489 updateentry
.spares3
= entry
.volumeId
[RWVOL
];
490 printf("\tVolume %s %d (not in rw id hash)\n",
491 entry
.name
, entry
.volumeId
[RWVOL
]);
493 ubik_VL_UpdateEntryByName(cstruct
, 0,
494 entry
.name
, &updateentry
, 0);
496 printf("\tFailed to update volume %s (err=%d)\n",
502 if (entry
.volumeId
[BACKVOL
]) {
504 ubik_VL_GetEntryByID(cstruct
, 0,
505 entry
.volumeId
[BACKVOL
], BACKVOL
,
507 if (code
== VL_NOENT
) {
509 updateentry
.Mask
= VLUPDATE_BACKUPID
;
510 updateentry
.BackupId
= entry
.volumeId
[BACKVOL
];
511 printf("\tVolume %s %d (not in backup id hash)\n",
512 entry
.name
, entry
.volumeId
[BACKVOL
]);
514 ubik_VL_UpdateEntry(cstruct
, 0,
515 entry
.volumeId
[RWVOL
], -1,
519 ("\tFailed to update volume %s (err=%d)\n",
525 if (entry
.volumeId
[ROVOL
]) {
527 ubik_VL_GetEntryByID(cstruct
, 0,
528 entry
.volumeId
[ROVOL
], ROVOL
, &tentry
);
529 if (code
== VL_NOENT
) {
531 updateentry
.Mask
= VLUPDATE_READONLYID
;
532 updateentry
.ReadOnlyId
= entry
.volumeId
[ROVOL
];
533 printf("\tVolume %s %d (not in RO id hash)\n",
534 entry
.name
, entry
.volumeId
[ROVOL
]);
536 ubik_VL_UpdateEntry(cstruct
, 0,
537 entry
.volumeId
[RWVOL
], -1,
541 ("\tFailed to update volume %s (err=%d)\n",
549 ("\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",
551 } else if (!strcmp(oper
, "la")) {
554 struct vldbentry
*entry
;
556 memset(&entries
, 0, sizeof(entries
));
557 fill_listattributes_entry(&listbyattributes
, argp
, nargs
);
558 display_listattributes_entry(&listbyattributes
, 0);
560 ubik_VL_ListAttributes(cstruct
, 0,
561 &listbyattributes
, &nentries
, &entries
);
563 printf("VL_ListAttributes returned code = %d\n", code
);
566 entry
= (struct vldbentry
*)entries
.bulkentries_val
;
567 for (i
= 0; i
< nentries
; i
++, entry
++)
568 display_entry(entry
, 0);
569 if (entries
.bulkentries_val
)
570 free(entries
.bulkentries_val
);
571 } else if (!strcmp(oper
, "lan2")) {
572 int nentries
, i
, si
, nsi
, t
= 0;
573 nbulkentries entries
;
574 struct nvldbentry
*entry
;
577 /* The volume name to search for (supports wildcarding) */
579 strcpy(name
, argp
[0]);
585 fill_listattributes_entry(&listbyattributes
, argp
, nargs
);
586 display_listattributes_entry(&listbyattributes
, 0);
587 printf("Wildcard VolName: '%s'\n", name
);
589 for (si
= 0; si
!= -1; si
= nsi
) {
591 memset(&entries
, 0, sizeof(entries
));
593 ubik_VL_ListAttributesN2(cstruct
, 0,
594 &listbyattributes
, name
, si
, &nentries
,
597 printf("VL_ListAttributesN2 returned code = %d\n",
603 entry
= (struct nvldbentry
*)entries
.nbulkentries_val
;
604 for (i
= 0; i
< nentries
; i
++, entry
++)
605 display_entryN(entry
, 0);
606 if (entries
.nbulkentries_val
)
607 free(entries
.nbulkentries_val
);
609 printf("--- %d volumes ---\n", t
);
610 } else if (!strcmp(oper
, "ln")) {
612 vldb_list linkedvldbs
;
613 vldblist vllist
, vllist1
;
615 fill_listattributes_entry(&listbyattributes
, argp
, nargs
);
616 display_listattributes_entry(&listbyattributes
, 0);
617 memset(&linkedvldbs
, 0, sizeof(vldb_list
));
619 ubik_VL_LinkedList(cstruct
, 0, &listbyattributes
,
620 &netries
, &linkedvldbs
);
622 printf("VL_LinkedList returned code = %d\n", code
);
625 printf("Found %d entr%s\n", netries
,
626 (netries
== 1 ? "y" : "ies"));
627 for (vllist
= linkedvldbs
.node
; vllist
; vllist
= vllist1
) {
628 vllist1
= vllist
->next_vldb
;
629 display_entry((struct vldbentry
*) &vllist
->VldbEntry
, 0);
632 } else if (!strcmp(oper
, "lnn")) {
634 nvldb_list linkedvldbs
;
635 nvldblist vllist
, vllist1
;
637 fill_listattributes_entry(&listbyattributes
, argp
, nargs
);
638 display_listattributes_entry(&listbyattributes
, 0);
639 memset(&linkedvldbs
, 0, sizeof(vldb_list
));
641 ubik_VL_LinkedListN(cstruct
, 0, &listbyattributes
,
642 &netries
, &linkedvldbs
);
644 printf("VL_LinkedList returned code = %d\n", code
);
647 printf("Found %d entr%s\n", netries
,
648 (netries
== 1 ? "y" : "ies"));
649 for (vllist
= linkedvldbs
.node
; vllist
; vllist
= vllist1
) {
650 vllist1
= vllist
->next_vldb
;
651 display_entry((struct vldbentry
*)&vllist
->VldbEntry
, 0);
654 } else if (!strcmp(oper
, "di")) {
655 sscanf(&(*argp
)[0], "%d", &id
);
657 sscanf(&(*argp
)[0], "%d", &voltype
);
659 ubik_VL_GetEntryByID(cstruct
, 0, id
, voltype
,
661 display_entry(&entry
, code
);
662 printf("return code is %d.\n", code
);
663 } else if (!strcmp(oper
, "rmnh")) {
664 sscanf(&(*argp
)[0], "%d", &id
);
666 sscanf(&(*argp
)[0], "%d", &voltype
);
668 ubik_VL_GetEntryByID(cstruct
, 0, id
, voltype
,
670 display_entry(&entry
, code
);
671 memset(&updateentry
, 0, sizeof(updateentry
));
672 updateentry
.Mask
= VLUPDATE_VOLNAMEHASH
;
673 printf("\tRehashing namehash table for %s (%d)\n", entry
.name
,
674 entry
.volumeId
[RWVOL
]);
676 ubik_VL_UpdateEntry(cstruct
, 0,
677 entry
.volumeId
[RWVOL
], -1, &updateentry
, 0);
679 printf("\tFailed to update volume %s (err=%d)\n",
682 printf("return code is %d.\n", code
);
683 } else if (!strcmp(oper
, "undelete")) {
684 afs_int32 index
, count
, next_index
;
686 memset(&updateentry
, 0, sizeof(updateentry
));
687 sscanf(&(*argp
)[0], "%d", &id
);
689 sscanf(&(*argp
)[0], "%d", &voltype
);
690 if (voltype
< 0 || voltype
> 2) {
691 printf("Illegal voltype; must be 0, 1 or 2\n");
694 printf("Searching vldb for volume %d...\n", id
);
695 for (index
= 0; 1; index
= next_index
) {
696 memset(&entry
, 0, sizeof(entry
));
698 ubik_VL_ListEntry(cstruct
, 0, index
, &count
,
699 &next_index
, &entry
);
701 printf("VL_ListEntry returned code = %d\n", code
);
706 if (entry
.volumeId
[voltype
] == id
) {
707 printf("\nThe current contents of the vldb for %d:\n",
709 display_entry(&entry
, 0);
711 if (entry
.flags
& VLDELETED
) {
712 updateentry
.Mask
= VLUPDATE_FLAGS
;
713 updateentry
.flags
= entry
.flags
;
714 updateentry
.flags
&= ~VLDELETED
;
716 ("\tUndeleting vldb entry for vol %d (%s)\n",
719 ubik_VL_UpdateEntry(cstruct
, 0, id
, -1,
723 ("\tFailed to update volume %s (err=%d)\n",
727 printf("Entry not deleted; ignored\n");
732 } else if (!strcmp(oper
, "dn")) {
735 ubik_VL_GetEntryByNameO(cstruct
, 0, vname
, &entry
);
736 display_entry(&entry
, code
);
737 printf("return code is %d.\n", code
);
738 } else if (!strcmp(oper
, "nv")) {
739 unsigned int newvolid
;
740 sscanf(&(*argp
)[0], "%d", &id
);
742 ubik_VL_GetNewVolumeId(cstruct
, 0, id
, &newvolid
);
744 printf("Current Max volid is (in hex):0x%x\n", newvolid
);
745 printf("return code is %d\n", code
);
746 } else if (!strcmp(oper
, "gs")) {
748 vital_vlheader vital_header
;
750 ubik_VL_GetStats(cstruct
, 0, &stats
, &vital_header
);
752 dump_stats(&stats
, &vital_header
);
753 printf("return code is %d.\n", code
);
754 } else if (!strcmp(oper
, "ga")) {
758 struct VLCallBack vlcb
;
760 addrs
.bulkaddrs_val
= 0;
761 addrs
.bulkaddrs_len
= 0;
762 code
= ubik_VL_GetAddrs(cstruct
, 0, 0 /*Handle */ ,
763 0 /*spare2 */ , &vlcb
,
766 printf("VL_GetAddrs returned code = %d\n", code
);
769 addrp
= addrs
.bulkaddrs_val
;
770 for (i
= 0; i
< nentries
; i
++, addrp
++) {
771 if ((*addrp
& 0xff000000) == 0xff000000)
772 printf("[0x%x %u] (special multi-homed entry)\n",
775 printf("[0x%x %u] %s\n", *addrp
, *addrp
,
776 hostutil_GetNameByINet(ntohl(*addrp
)));
778 free(addrs
.bulkaddrs_val
);
779 } else if (!strcmp(oper
, "gau")) {
783 struct VLCallBack vlcb
;
785 addrs
.bulkaddrs_val
= 0;
786 addrs
.bulkaddrs_len
= 0;
787 code
= ubik_VL_GetAddrs(cstruct
, 0, 0 /*Handle */ ,
788 0 /*spare2 */ , &vlcb
,
791 printf("VL_GetAddrs returned code = %d\n", code
);
794 addrp
= addrs
.bulkaddrs_val
;
795 for (i
= 0; i
< nentries
; i
++, addrp
++) {
796 if ((*addrp
& 0xff000000) == 0xff000000) {
797 int mhnentries
, unique
;
798 struct in_addr hostAddr
;
801 ListAddrByAttributes attrs
;
804 printf("[0x%x %u] (special multi-homed entry)\n",
806 memset(&attrs
, 0, sizeof(attrs
));
807 attrs
.Mask
= VLADDR_INDEX
;
808 mhaddrs
.bulkaddrs_val
= 0;
809 mhaddrs
.bulkaddrs_len
= 0;
810 attrs
.index
= *addrp
& 0x00ffffff;
813 ubik_VL_GetAddrsU(cstruct
, 0, &attrs
, &uuid
,
814 &unique
, &mhnentries
, &mhaddrs
);
816 printf("VL_GetAddrsU returned code = %d\n", code
);
820 (" [%d]: uuid[%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x]\n addrunique=%d, ip address(es):\n",
821 attrs
.index
, uuid
.time_low
, uuid
.time_mid
,
822 uuid
.time_hi_and_version
,
823 uuid
.clock_seq_hi_and_reserved
,
824 uuid
.clock_seq_low
, uuid
.node
[0], uuid
.node
[1],
825 uuid
.node
[2], uuid
.node
[3], uuid
.node
[4],
826 uuid
.node
[5], unique
);
827 mhaddrp
= mhaddrs
.bulkaddrs_val
;
828 for (j
= 0; j
< mhnentries
; j
++) {
829 mhaddrp
[j
] = ntohl(mhaddrp
[j
]);
830 hostAddr
.s_addr
= mhaddrp
[j
];
831 printf("\t%s (%s)\n", inet_ntoa(hostAddr
),
832 hostutil_GetNameByINet(mhaddrp
[j
]));
834 if (mhaddrs
.bulkaddrs_val
)
835 free(mhaddrs
.bulkaddrs_val
);
837 printf("[0x%x %u] %s\n", *addrp
, *addrp
,
838 hostutil_GetNameByINet(ntohl(*addrp
)));
841 free(addrs
.bulkaddrs_val
);
842 } else if (!strcmp(oper
, "mhc")) {
843 afs_uint32 serveraddrs
[MAXSERVERID
+ 1][VL_MAXIPADDRS_PERMH
];
844 afs_int32 serveraddrtype
[MAXSERVERID
+ 1];
845 int nentries1
, nentries2
, i
, j
, x
, y
, unique
, found
;
846 afs_uint32
*addrp1
, *addrp2
;
847 bulkaddrs addrs1
, addrs2
;
848 struct VLCallBack vlcb
;
849 ListAddrByAttributes attrs
;
851 afs_int32 base
, index
;
853 for (i
= 0; i
< MAXSERVERID
+ 1; i
++) {
854 serveraddrtype
[i
] = 0;
855 for (j
= 0; j
< VL_MAXIPADDRS_PERMH
; j
++)
856 serveraddrs
[i
][j
] = 0;
859 /* Collect a list of all registered IP addresses */
860 addrs1
.bulkaddrs_val
= 0;
861 addrs1
.bulkaddrs_len
= 0;
863 ubik_VL_GetAddrs(cstruct
, 0, 0, 0, &vlcb
,
864 &nentries1
, &addrs1
);
866 printf("VL_GetAddrs returned code = %d\n", code
);
869 addrp1
= addrs1
.bulkaddrs_val
;
870 for (i
= 0; i
< nentries1
; i
++, addrp1
++) {
871 if ((*addrp1
& 0xff000000) != 0xff000000) {
872 serveraddrs
[i
][0] = ntohl(*addrp1
);
873 serveraddrtype
[i
] = 1;
875 /* It's multihomed. Get all of its addresses */
876 serveraddrtype
[i
] = 2;
877 base
= (*addrp1
>> 16) & 0xff;
878 index
= *addrp1
& 0xffff;
880 addrs2
.bulkaddrs_val
= 0;
881 addrs2
.bulkaddrs_len
= 0;
882 memset(&attrs
, 0, sizeof(attrs
));
883 attrs
.Mask
= VLADDR_INDEX
;
884 attrs
.index
= (base
* VL_MHSRV_PERBLK
) + index
;
886 ubik_VL_GetAddrsU(cstruct
, 0, &attrs
, &uuid
,
887 &unique
, &nentries2
, &addrs2
);
889 printf("VL_GetAddrsU returned code = %d\n", code
);
893 addrp2
= addrs2
.bulkaddrs_val
;
894 for (j
= 0; j
< nentries2
; j
++) {
895 serveraddrs
[i
][j
] = ntohl(addrp2
[j
]);
897 free(addrs2
.bulkaddrs_val
);
901 if (serveraddrtype
[i
] == 1) {
902 printf("%u\n", serveraddrs
[i
][0]);
905 for (j
= 0; j
< VL_MAXIPADDRS_PERMH
; j
++)
906 if (serveraddrs
[i
][j
])
907 printf(" %u", serveraddrs
[i
][j
]);
912 free(addrs1
.bulkaddrs_val
);
914 /* Look for any duplicates */
915 for (i
= 0; i
< MAXSERVERID
+ 1; i
++) {
916 if (!serveraddrtype
[i
])
918 for (j
= 0; j
< VL_MAXIPADDRS_PERMH
; j
++) {
919 if (!serveraddrs
[i
][j
])
923 for (x
= i
+ 1; x
< MAXSERVERID
+ 1; x
++) {
924 if (!serveraddrtype
[x
])
926 for (y
= 0; y
< VL_MAXIPADDRS_PERMH
; y
++) {
927 if (!serveraddrs
[x
][y
])
929 if (serveraddrs
[i
][j
] == serveraddrs
[x
][y
]) {
930 serveraddrs
[x
][y
] = 0;
937 ("Found %d entries of IP address %u (0x%x)\n",
938 found
+ 1, serveraddrs
[i
][j
],
944 /*----------------------------------------*/
946 } else if (!strcmp(oper
, "regaddr")) {
948 afs_uint32
*addrp
, tad
;
952 memset(&uuid
, 0, sizeof(uuid
));
953 sscanf(&(*argp
)[0], "%d", &i
);
955 memcpy(uuid
.node
, &i
, sizeof(i
));
957 if (nargs
< 0 || nargs
> 16) {
958 printf("Illegal # entries = %d\n", nargs
);
961 addrp
= malloc(20 * 4);
962 addrs
.bulkaddrs_val
= addrp
;
963 addrs
.bulkaddrs_len
= nargs
;
965 sscanf(&(*argp
)[0], "%d", &tad
);
970 ubik_VL_RegisterAddrs(cstruct
, 0, &uuid
,
971 0 /*spare */ , &addrs
);
973 printf("VL_RegisterAddrs returned code = %d\n", code
);
976 } else if (!strcmp(oper
, "ca")) {
977 struct hostent
*h1
, *h2
;
980 printf("changing %s", *argp
);
981 h1
= hostutil_GetHostByName(&(*argp
)[0]);
983 printf("cmdebug: can't resolve address for host %s",
987 memcpy(&a1
, (afs_int32
*) h1
->h_addr
, sizeof(afs_uint32
));
990 printf(" to %s\n", *argp
);
991 h2
= hostutil_GetHostByName(&(*argp
)[0]);
993 printf("cmdebug: can't resolve address for host %s",
997 memcpy(&a2
, (afs_int32
*) h2
->h_addr
, sizeof(afs_uint32
));
999 printf("changing 0x%x to 0x%x\n", ntohl(a1
), ntohl(a2
));
1001 ubik_VL_ChangeAddr(cstruct
, 0, ntohl(a1
),
1004 printf("VL_ChangeAddr returned code = %d\n", code
);
1007 } else if (!strcmp(oper
, "caid")) {
1010 sscanf(&(*argp
)[0], "%d", &a1
);
1011 printf("changing %d (0x%x)", a1
, a1
);
1013 sscanf(&(*argp
)[0], "%d", &a2
);
1014 printf(" to %d (0x%x)\n", a2
, a2
);
1015 code
= ubik_VL_ChangeAddr(cstruct
, 0, a1
, a2
);
1017 printf("VL_ChangeAddr returned code = %d\n", code
);
1020 } else if ((!strcmp(oper
, "?")) || !strcmp(oper
, "h") || !strcmp(oper
, "help"))
1022 else if ((!strcmp(oper
, "q")) || !strcmp(oper
, "quit"))
1025 printf("Unknown oper (%s)!\n", oper
);
1033 #include "AFS_component_version_number.c"
1036 main(int argc
, char **argv
)
1038 struct cmd_syndesc
*ts
;
1041 strcpy(confdir
, AFSDIR_CLIENT_ETC_DIRPATH
);
1042 ts
= cmd_CreateSyntax("initcmd", handleit
, NULL
, 0, "initialize the program");
1043 cmd_AddParm(ts
, "-cellpath", CMD_LIST
, CMD_OPTIONAL
,
1044 "Cell configuration directory");
1045 cmd_AddParm(ts
, "-server", CMD_LIST
, CMD_OPTIONAL
,
1046 "Use the cell config in /usr/afs/etc (default /usr/vice/etc)");
1047 cmd_AddParm(ts
, "-noauth", CMD_FLAG
, CMD_OPTIONAL
,
1048 "Run it without authentication");
1049 cmd_AddParm(ts
, "-host", CMD_LIST
, CMD_OPTIONAL
,
1050 "vldb server to talk to");
1051 cmd_AddParm(ts
, "-cell", CMD_LIST
, CMD_OPTIONAL
,
1052 "cellname '-host' belongs to (required for auth conns)");
1053 cmd_AddParm(ts
, "-getstats", CMD_FLAG
, CMD_OPTIONAL
,
1054 "print vldb statistics (non interactive)");
1055 cmd_AddParm(ts
, "-probe", CMD_FLAG
, CMD_OPTIONAL
,
1056 "probe vldb servers, use with -host to probe only one. (non interactive)");
1057 code
= cmd_Dispatch(argc
, argv
);
1063 fill_entry(struct vldbentry
*entry
, char **argp
, int nargs
)
1070 sscanf(&(*argp
)[0], "%d", &entry
->spares3
);
1072 sscanf(&(*argp
)[0], "%d", &entry
->nServers
);
1073 strcpy(entry
->name
, name
);
1074 for (i
= 0; i
< entry
->nServers
; i
++) {
1076 sscanf(&(*argp
)[0], "%u", &entry
->serverNumber
[i
]);
1078 for (i
= 0; i
< entry
->nServers
; i
++) {
1080 sscanf(&(*argp
)[0], "%d", &entry
->serverPartition
[i
]);
1082 for (i
= 0; i
< entry
->nServers
; i
++) {
1084 sscanf(&(*argp
)[0], "%d", &entry
->serverFlags
[i
]);
1086 for (i
= 0; i
< MAXTYPES
; i
++) {
1088 sscanf(&(*argp
)[0], "%u", &entry
->volumeId
[i
]);
1091 sscanf(&(*argp
)[0], "%d", &entry
->flags
);
1093 sscanf(&(*argp
)[0], "%u", &entry
->cloneId
);
1097 fill_update_entry(struct VldbUpdateEntry
*entry
, char **argp
, int nargs
)
1104 if (strcmp(name
, "null")) {
1105 strcpy(entry
->name
, name
);
1106 entry
->Mask
|= VLUPDATE_VOLUMENAME
;
1109 sscanf(&(*argp
)[0], "%d", &entry
->flags
);
1110 if (entry
->flags
!= -1)
1111 entry
->Mask
|= VLUPDATE_FLAGS
;
1113 sscanf(&(*argp
)[0], "%u", &entry
->cloneId
);
1114 if (entry
->flags
!= -1)
1115 entry
->Mask
|= VLUPDATE_CLONEID
;
1117 sscanf(&(*argp
)[0], "%u", &entry
->ReadOnlyId
);
1118 if (entry
->ReadOnlyId
!= -1)
1119 entry
->Mask
|= VLUPDATE_READONLYID
;
1121 sscanf(&(*argp
)[0], "%u", &entry
->BackupId
);
1122 if (entry
->BackupId
!= -1)
1123 entry
->Mask
|= VLUPDATE_BACKUPID
;
1125 sscanf(&(*argp
)[0], "%d", &entry
->nModifiedRepsites
);
1126 if (entry
->nModifiedRepsites
!= -1)
1127 entry
->Mask
|= VLUPDATE_REPSITES
;
1128 for (i
= 0; i
< entry
->nModifiedRepsites
; i
++) {
1130 sscanf(&(*argp
)[0], "%x", &Mask
);
1132 sscanf(&(*argp
)[0], "%u", &entry
->RepsitesTargetServer
[i
]);
1134 sscanf(&(*argp
)[0], "%d", &entry
->RepsitesTargetPart
[i
]);
1135 if (Mask
& VLUPDATE_REPS_DELETE
)
1136 entry
->RepsitesMask
[i
] |= VLUPDATE_REPS_DELETE
;
1137 if (Mask
& VLUPDATE_REPS_MODSERV
) {
1139 sscanf(&(*argp
)[0], "%u", &entry
->RepsitesNewServer
[i
]);
1140 entry
->RepsitesMask
[i
] |= VLUPDATE_REPS_MODSERV
;
1141 } else if (Mask
& VLUPDATE_REPS_MODPART
) {
1143 sscanf(&(*argp
)[0], "%d", &entry
->RepsitesNewPart
[i
]);
1144 entry
->RepsitesMask
[i
] |= VLUPDATE_REPS_MODPART
;
1145 } else if (Mask
& VLUPDATE_REPS_MODFLAG
) {
1147 sscanf(&(*argp
)[0], "%d", &entry
->RepsitesNewFlags
[i
]);
1148 entry
->RepsitesMask
[i
] |= VLUPDATE_REPS_MODFLAG
;
1149 } else if (Mask
& VLUPDATE_REPS_ADD
) {
1151 sscanf(&(*argp
)[0], "%u", &entry
->RepsitesNewServer
[i
]);
1153 sscanf(&(*argp
)[0], "%d", &entry
->RepsitesNewPart
[i
]);
1155 sscanf(&(*argp
)[0], "%d", &entry
->RepsitesNewFlags
[i
]);
1156 entry
->RepsitesMask
[i
] |= VLUPDATE_REPS_ADD
;
1162 fill_listattributes_entry(struct VldbListByAttributes
*entry
, char **argp
,
1169 entry
->server
= ntohl(GetServer(argp
[0]));
1170 sscanf(&(*argp
)[0], "%d", &entry
->server
);
1171 if (entry
->server
!= 0)
1172 entry
->Mask
|= VLLIST_SERVER
;
1177 sscanf(&(*argp
)[0], "%d", &entry
->partition
);
1178 if (entry
->partition
!= -1)
1179 entry
->Mask
|= VLLIST_PARTITION
;
1184 sscanf(&(*argp
)[0], "%d", &entry
->volumeid
);
1185 if (entry
->volumeid
!= -1)
1186 entry
->Mask
|= VLLIST_VOLUMEID
;
1191 sscanf(&(*argp
)[0], "%d", &entry
->flag
);
1192 if (entry
->flag
!= -1)
1193 entry
->Mask
|= VLLIST_FLAG
;
1197 display_listattributes_entry(struct VldbListByAttributes
*entry
, int error
)
1201 printf("\nList entry values (Mask=%x)\n", entry
->Mask
);
1202 if (entry
->Mask
& VLLIST_SERVER
)
1203 printf("\tServer: %d.%d.%d.%d\n", (entry
->server
>> 24) & 0xff,
1204 (entry
->server
>> 16) & 0xff, (entry
->server
>> 8) & 0xff,
1205 (entry
->server
) & 0xff);
1206 if (entry
->Mask
& VLLIST_PARTITION
)
1207 printf("\tPartition: %d\n", entry
->partition
);
1208 if (entry
->Mask
& VLLIST_VOLUMEID
)
1209 printf("\tVolumeId: %u\n", entry
->volumeid
);
1210 if (entry
->Mask
& VLLIST_FLAG
)
1211 printf("\tFlag: %x\n", entry
->flag
);
1215 #define volumetype_string(type) (type == RWVOL? "read/write":type == ROVOL? "readonly":type == BACKVOL? "backup":"unknown")
1218 display_entry(struct vldbentry
*entry
, int error
)
1224 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1225 entry
->name
, entry
->volumeId
[RWVOL
], entry
->flags
);
1226 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1227 entry
->volumeId
[0], entry
->volumeId
[1], entry
->volumeId
[2],
1229 printf("nServers=%d\n", entry
->nServers
);
1230 printf("ServerNumber\tServerPart\tserverFlag\n");
1231 for (i
= 0; i
< entry
->nServers
; i
++)
1232 printf("%12u\t%10d\t%10x\n", entry
->serverNumber
[i
],
1233 entry
->serverPartition
[i
], entry
->serverFlags
[i
]);
1237 display_entryN(struct nvldbentry
*entry
, int error
)
1243 printf("\nEntry for volume name: %s, volid=%u (flags=%X) are:\n",
1244 entry
->name
, entry
->volumeId
[RWVOL
], entry
->flags
);
1245 printf("ParentID=%u, ReadOnlyID=%u, backupID=%u, CloneId=%u ",
1246 entry
->volumeId
[0], entry
->volumeId
[1], entry
->volumeId
[2],
1248 printf("nServers=%d\n", entry
->nServers
);
1249 printf("ServerNumber\tServerPart\tserverFlag\n");
1250 ei
= entry
->matchindex
& 0xffff;
1251 et
= (entry
->matchindex
>> 16) & 0xffff;
1252 for (i
= 0; i
< entry
->nServers
; i
++) {
1253 printf("%12u\t%10d\t%10x", entry
->serverNumber
[i
],
1254 entry
->serverPartition
[i
], entry
->serverFlags
[i
]);
1256 printf(" <--- %s", (et
== 4) ? "RW" : ((et
== 8) ? "BK" : "RO"));
1263 display_update_entry(struct VldbUpdateEntry
*entry
, int error
)
1269 printf("\nUpdate entry values (Mask=%x)\n", entry
->Mask
);
1270 if (entry
->Mask
& VLUPDATE_VOLUMENAME
)
1271 printf("\tNew name: %s\n", entry
->name
);
1272 if (entry
->Mask
& VLUPDATE_FLAGS
)
1273 printf("\tNew flags: %X\n", entry
->flags
);
1274 if (entry
->Mask
& VLUPDATE_CLONEID
)
1275 printf("\tNew CloneId: %X\n", entry
->cloneId
);
1276 if (entry
->Mask
& VLUPDATE_READONLYID
)
1277 printf("\tNew RO id: %d\n", entry
->ReadOnlyId
);
1278 if (entry
->Mask
& VLUPDATE_BACKUPID
)
1279 printf("\tNew BACKUP id: %d\n", entry
->BackupId
);
1280 if (entry
->Mask
& VLUPDATE_REPSITES
) {
1281 printf("\tRepsites info:\n");
1282 printf("\tFlag\tTServer\tTPart\tNServer\tNPart\tNFlag\n");
1283 for (i
= 0; i
< entry
->nModifiedRepsites
; i
++) {
1284 printf("\t%4x\t%7u\t%5d", entry
->RepsitesMask
[i
],
1285 entry
->RepsitesTargetServer
[i
],
1286 entry
->RepsitesTargetPart
[i
]);
1287 if ((entry
->RepsitesMask
[i
] & VLUPDATE_REPS_ADD
)
1288 || (entry
->RepsitesMask
[i
] & VLUPDATE_REPS_MODSERV
))
1289 printf("\t%7u", entry
->RepsitesNewServer
[i
]);
1291 printf("\t-------");
1292 if ((entry
->RepsitesMask
[i
] & VLUPDATE_REPS_ADD
)
1293 || (entry
->RepsitesMask
[i
] & VLUPDATE_REPS_MODPART
))
1294 printf("\t%5d", entry
->RepsitesNewPart
[i
]);
1297 if ((entry
->RepsitesMask
[i
] & VLUPDATE_REPS_ADD
)
1298 || (entry
->RepsitesMask
[i
] & VLUPDATE_REPS_MODFLAG
))
1299 printf("\t%5x\n", entry
->RepsitesNewFlags
[i
]);
1301 printf("\t-----\n");
1307 dump_stats(vldstats
*stats
, vital_vlheader
*vital_header
)
1311 time_t start_time
= stats
->start_time
;
1314 strftime(strg
, sizeof(strg
), "%a %b %d %H:%M:%S %Y",
1315 localtime_r(&start_time
, &tm
));
1316 printf("Dynamic statistics stats (starting time: %s):\n", strg
);
1317 printf("OpcodeName\t# Requests\t# Aborts\n");
1318 for (i
= 0; i
< VL_NUMBER_OPCODESX
; i
++)
1319 printf("%10s\t%10d\t%8d\n", opcode_names
[i
], stats
->requests
[i
],
1321 printf("\nVldb header stats (version=%d)\n",
1322 ntohl(vital_header
->vldbversion
));
1323 printf("headersize=%d, allocs=%d, frees=%d, MaxVolid=%X\n",
1324 ntohl(vital_header
->headersize
), ntohl(vital_header
->allocs
),
1325 ntohl(vital_header
->frees
), ntohl(vital_header
->MaxVolumeId
));
1326 for (i
= 0; i
< MAXTYPES
; i
++)
1327 printf("total %s entries=%d\n", volumetype_string(i
),
1328 ntohl(vital_header
->totalEntries
[i
]));
1332 GetArgs(char *line
, char **args
, int *nargs
)
1337 while (isspace(*line
))
1343 *args
++ = line
, (*nargs
)++;
1344 while (*line
&& !isspace(*line
))
1352 printf("Valid Commands:\n");
1354 printf(" CreateEntry:\n");
1356 ("\tcr <vname> <vtype> <#S> <Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn> <Volid1-3> <flag>\n");
1358 printf(" DeleteEntry:\n");
1359 printf("\trm <volid> <voltype>\n");
1361 printf(" ReplaceEntry:\n");
1362 printf("\tre <volid> <voltype> <New vldb entry ala 'cr'>\n");
1364 printf(" UpdateEntry:\n");
1366 ("\tup <volid> <voltype> <vname> <vtype> <#AddSer> [<Saddr1>.<Saddrn> <Spart1>.<Spartn> <Sflag1>.<Sflagn>] <Volid1-3> <flag>\n");
1368 printf(" ListEntry:\n");
1371 printf(" Find duplicate entries of a volume\n");
1372 printf("\tldups\n");
1374 printf(" For each vlentry, find it by name, RW id, BK id, and RO id\n");
1375 printf("\tcheckhash\n");
1378 (" UpdateEntry (update the volname, RW id, BK id, RO id hashes):\n");
1379 printf("\tfixhash\n");
1381 printf(" ListAttributes:\n");
1382 printf("\tla [server] [partition] [volumeid] [flag]\n");
1384 printf(" ListAttributesN2:\n");
1385 printf("\tlan2 [volname] [server] [partition] [volumeid] [flag]\n");
1387 printf(" GetEntryByID:\n");
1388 printf("\tdi <volid> <voltype>\n");
1390 printf(" UpdateEntry (refresh namehash table):\n");
1391 printf("\trmnh <volid> <voltype>\n");
1393 printf(" GetEntryByName:\n");
1394 printf("\tdn <volname> <voltype>\n");
1396 printf(" UpdateEntry (undelete a vol entry):\n");
1397 printf("\tundelete <volid> <voltype>\n");
1399 * printf(" LinkedList\n");
1400 * printf("\t:ln [server] [partition] [volumeid] [flag]\n");
1402 * printf(" LinkedListN\n");
1403 * printf("\t:lnn [server] [partition] [volumeid] [flag]\n");
1405 printf(" GetNewVoumeId:\n");
1406 printf("\tnv <bump-count>\n");
1408 printf(" GetStats:\n");
1411 printf(" ChangeAddr:\n");
1412 printf("\tca <oldmachname> <newmachname>\n");
1415 * printf(" ChangeAddr\n");
1416 * printf("\t:caid <oldaddr> <newaddr>\n");
1418 printf(" GetAddrs:\n");
1421 printf(" GetAddrsU:\n");
1424 printf(" RegisterAddrs:\n");
1425 printf("\tregaddr uuidNumber <ip1 .. ipn>\n");
1427 printf("\tmisc: q, quit, ?, h\n");