* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
+#include <afs/param.h>
+
+#include <roken.h>
+
+#ifdef AFS_NT40_ENV
+#include <WINNT/afsevent.h>
+#endif
+
+#include <ubik.h>
+#include <afs/afsutil.h>
+#include <afs/cmd.h>
+
+#include "vlserver.h"
+#include "vldbint.h"
+
/* Read a VLDB file and verify it for correctness */
#define VL 0x001 /* good volume entry */
#define vldbread(x,y,z) vldbio(x,y,z,0)
#define vldbwrite(x,y,z) vldbio(x,y,z,1)
-#include <afsconfig.h>
-#include <afs/param.h>
-
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <WINNT/afsevent.h>
-#include <io.h>
-#else
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#endif
-
-#include "vlserver.h"
-#include "vldbint.h"
-#include <ubik.h>
-#include <afs/afsutil.h>
-#include <afs/cmd.h>
-
#define ADDR(x) (x/sizeof(struct nvlentry))
int fd;
} *record;
afs_int32 maxentries;
int serveraddrs[MAXSERVERID + 2];
+u_char serverxref[MAXSERVERID + 2]; /**< to resolve cross-linked mh entries */
/* Used to control what goes to stdout based on quiet flag */
void
}
-#if 0
-int
-writeUbikHeader()
-{
- /* Bump the version number?? We could cheat and push a new db... */
-}
-#endif
-
#define HDRSIZE 64
int
readUbikHeader(void)
ntohl(headerp->vital_header.totalEntries[1]);
headerp->SIT = ntohl(headerp->SIT);
- for (i = 0; i < MAXSERVERID; i++)
+ for (i = 0; i <= MAXSERVERID; i++)
headerp->IpMappedAddr[i] = ntohl(headerp->IpMappedAddr[i]);
for (i = 0; i < HASHSIZE; i++)
headerp->VolnameHash[i] = ntohl(headerp->VolnameHash[i]);
htonl(headerp->vital_header.totalEntries[1]);
headerp->SIT = htonl(headerp->SIT);
- for (i = 0; i < MAXSERVERID; i++)
+ for (i = 0; i <= MAXSERVERID; i++)
headerp->IpMappedAddr[i] = htonl(headerp->IpMappedAddr[i]);
for (i = 0; i < HASHSIZE; i++)
headerp->VolnameHash[i] = htonl(headerp->VolnameHash[i]);
vldbread(addr, (char *)mhblockP, VL_ADDREXTBLK_SIZE);
mhblockP->ex_count = ntohl(mhblockP->ex_count);
- mhblockP->ex_flags = ntohl(mhblockP->ex_flags);
+ mhblockP->ex_hdrflags = ntohl(mhblockP->ex_hdrflags);
for (i = 0; i < VL_MAX_ADDREXTBLKS; i++)
mhblockP->ex_contaddrs[i] = ntohl(mhblockP->ex_contaddrs[i]);
vldbwrite(addr, (char *)vlentryp, sizeof(*vlentryp));
}
-void
-readSIT(int base, int addr)
-{
- int i, j, a;
- char sitbuf[VL_ADDREXTBLK_SIZE];
- struct extentaddr *extent;
-
- if (!addr)
- return;
- vldbread(addr, sitbuf, VL_ADDREXTBLK_SIZE);
- extent = (struct extentaddr *)sitbuf;
-
- quiet_println("multihome info block: base %d\n", base);
- if (base == 0) {
- quiet_println(" count = %u\n", ntohl(extent->ex_count));
- quiet_println(" flags = %u\n", ntohl(extent->ex_flags));
- for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
- quiet_println(" contaddrs[%d] = %u\n", i,
- ntohl(extent->ex_contaddrs[i]));
- }
- }
- for (i = 1; i < VL_MHSRV_PERBLK; i++) {
- /* should we skip this entry */
- for (j = 0; j < VL_MAX_ADDREXTBLKS; j++) {
- if (extent[i].ex_addrs[j])
- break;
- }
- if (j >= VL_MAX_ADDREXTBLKS)
- continue;
-
- quiet_println(" base %d index %d:\n", base, i);
-
- quiet_println(" afsuuid = (%x %x %x /%d/%d/ /%x/%x/%x/%x/%x/%x/)\n",
- ntohl(extent[i].ex_hostuuid.time_low),
- ntohl(extent[i].ex_hostuuid.time_mid),
- ntohl(extent[i].ex_hostuuid.time_hi_and_version),
- ntohl(extent[i].ex_hostuuid.clock_seq_hi_and_reserved),
- ntohl(extent[i].ex_hostuuid.clock_seq_low),
- ntohl(extent[i].ex_hostuuid.node[0]),
- ntohl(extent[i].ex_hostuuid.node[1]),
- ntohl(extent[i].ex_hostuuid.node[2]),
- ntohl(extent[i].ex_hostuuid.node[3]),
- ntohl(extent[i].ex_hostuuid.node[4]),
- ntohl(extent[i].ex_hostuuid.node[5]));
- quiet_println(" uniquifier = %u\n", ntohl(extent[i].ex_uniquifier));
- for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
- a = ntohl(extent[i].ex_addrs[j]);
- if (a) {
- quiet_println(" %d.%d.%d.%d\n", (a >> 24) & 0xff,
- (a >> 16) & 0xff, (a >> 8) & 0xff, (a) & 0xff);
- }
- }
- }
-}
-
/*
* Read each entry in the database:
* Record what type of entry it is and its address in the record array.
* addresses of all the mh blocks.
*/
readMH(header->SIT, MHblock);
- if (MHblock->ex_flags != VLCONTBLOCK) {
+ if (MHblock->ex_hdrflags != VLCONTBLOCK) {
log_error
(VLDB_CHECK_ERROR,"Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
header->SIT);
continue;
readMH(caddrs[i], MHblock);
- if (MHblock->ex_flags != VLCONTBLOCK) {
+ if (MHblock->ex_hdrflags != VLCONTBLOCK) {
log_error
(VLDB_CHECK_ERROR,"Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
header->SIT);
*/
mhentries = 0;
for (j = 1; j < VL_MHSRV_PERBLK; j++) {
+ int first_ipindex = -1;
e = (struct extentaddr *)&(MHblock[j]);
- /* Search the IpMappedAddr array for the reference to this entry */
- for (ipindex = 0; ipindex < MAXSERVERID; ipindex++) {
- if (((header->IpMappedAddr[ipindex] & 0xff000000) ==
- 0xff000000)
- &&
- (((header->
- IpMappedAddr[ipindex] & 0x00ff0000) >> 16) == i)
- && ((header->IpMappedAddr[ipindex] & 0x0000ffff) ==
- j)) {
- break;
+ /* Search the IpMappedAddr array for all the references to this entry. */
+ /* Use the first reference for checking the ip addresses of this entry. */
+ for (ipindex = 0; ipindex <= MAXSERVERID; ipindex++) {
+ if (((header->IpMappedAddr[ipindex] & 0xff000000) == 0xff000000)
+ && (((header-> IpMappedAddr[ipindex] & 0x00ff0000) >> 16) == i)
+ && ((header->IpMappedAddr[ipindex] & 0x0000ffff) == j)) {
+ if (first_ipindex == -1) {
+ first_ipindex = ipindex;
+ } else {
+ serverxref[ipindex] = first_ipindex;
+ }
}
}
- if (ipindex >= MAXSERVERID)
- ipindex = -1;
- else
+ ipindex = first_ipindex;
+ if (ipindex != -1)
serveraddrs[ipindex] = -1;
if (memcmp(&e->ex_hostuuid, &nulluuid, sizeof(afsUUID)) == 0) {
log_error
(VLDB_CHECK_ERROR,"IP Addr for entry %d: Multihome block is bad (%d)\n",
i, ((header->IpMappedAddr[i] & 0x00ff0000) >> 16));
+ if (caddrs[(header->IpMappedAddr[i] & 0x00ff0000) >> 16] == 0)
+ log_error(VLDB_CHECK_ERROR,"IP Addr for entry %d: No such multihome block (%d)\n",
+ i, ((header->IpMappedAddr[i] & 0x00ff0000) >> 16));
if (((header->IpMappedAddr[i] & 0x0000ffff) > VL_MHSRV_PERBLK)
|| ((header->IpMappedAddr[i] & 0x0000ffff) < 1))
log_error
i);
serveraddrs[i] = 0;
}
+ if (serverxref[i] != BADSERVERID) {
+ log_error
+ (VLDB_CHECK_WARNING,
+ "warning: MH block %d, index %d is cross-linked by server numbers %d and %d.\n",
+ (header->IpMappedAddr[i] & 0x00ff0000) >> 16,
+ (header->IpMappedAddr[i] & 0x0000ffff),
+ i, serverxref[i]);
+ /* set addresses found/not found for this server number,
+ * using the first index to the mh we found above. */
+ serveraddrs[i] = serveraddrs[serverxref[i]];
+ }
if (listservers) {
quiet_println(" Server ip addr %d = MH block %d, index %d\n",
i, (header->IpMappedAddr[i] & 0x00ff0000) >> 16,
}
maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1;
- record = (struct er *)malloc(maxentries * sizeof(struct er));
- memset(record, 0, (maxentries * sizeof(struct er)));
+ record = calloc(maxentries, sizeof(struct er));
memset(serveraddrs, 0, sizeof(serveraddrs));
+ for (i = 0; i <= MAXSERVERID; i++) {
+ serverxref[i] = BADSERVERID;
+ }
/* Will fill in the record array of entries it found */
ReadAllEntries(&header);