1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
/*
acslist.c: Dumps the ACS custody database, checking for inconsistencies
between the bundle ID hash table and custody ID hash table.
Author: Andrew Jenkins
University of Colorado at Boulder
Copyright (c) 2008-2010, Regents of the University of Colorado.
This work was supported by NASA contracts NNJ05HE10G, NNC06CB40C, and
NNC07CB47C. */
#include <acsP.h>
#include <sdrhash.h>
static int printToStdout = 0;
#define writeMemoOrStdout(args...) \
if (printToStdout == 0) \
{ \
char acslistBuf[256]; \
snprintf(acslistBuf, sizeof(acslistBuf), args); \
writeMemo(acslistBuf); \
} \
else \
{ \
printf(args); \
printf("\n"); \
}
/* Counts total number of database errors discovered;
* used to calculate task return code. */
static int errors = 0;
/* Takes a key/val pair from the hash table mapping custody IDs to CBID pairs,
* printing the mapping and checking for consistency:
* 1) The key (custody ID) maps to a custody ID/bundle ID pair with a
* matching custody ID.
* 2) Using the value's bundle ID as the key in a search of the other hash
* table (mapping custody IDs to CBID pairs), we find the same result. */
static void printAndCheckByCid(Sdr acsSdr, Object hash, char *key, Address cbidAddr, void *args)
{
int *cidCount = (int *)(args);
AcsCustodyId *cid = (AcsCustodyId *)(key);
AcsCbidEntry cbid;
int hasMismatch = 0;
int rc;
Object hashEntry;
/* These two variables should match cbidAddr & cbid; but they're looked up
* in the bid hash table rather than cid hash table as a consistency check. */
Address bidCbidAddr;
AcsCbidEntry bidCbid;
/* Load the value and print the mapping. */
sdr_peek(acsSdr, cbid, cbidAddr);
writeMemoOrStdout("(%s,%u,%u,%u,%u)->(%u)",
cbid.bundleId.sourceEid,
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
cbid.bundleId.fragmentOffset,
cbid.bundleId.fragmentLength,
cid->id);
/* Verify cbid's idea of custody ID matches the custody ID used as a key in
* the hash table. */
if (cid->id != cbid.custodyId.id)
{
writeMemoOrStdout("Mismatch: custody ID in key (%u) "
"!= in database (%u)",
cid->id,
cbid.custodyId.id);
hasMismatch = 1;
}
/* Verify that if we look up using the bundle ID we've found, we get the
* same cbid (there are no dangling entries in the cidHash) */
rc = sdr_hash_retrieve(acsSdr, acsConstants->bidHash,
(char *)(&cbid.bundleId), &bidCbidAddr, &hashEntry);
if (rc == -1)
{
writeMemoOrStdout("Mismatch: can't find (%s,%u,%u,%u,%u) "
"in bundle ID database.",
cbid.bundleId.sourceEid,
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
cbid.bundleId.fragmentOffset,
cbid.bundleId.fragmentLength);
hasMismatch = 1;
}
else if (cbidAddr != bidCbidAddr)
{
sdr_peek(acsSdr, bidCbid, bidCbidAddr);
writeMemoOrStdout("Mismatch: "
"lookup (%u) in cid: @%lu (%s,%u,%u,%u,%u)->(%u) != "
"lookup (%s, %u, %u, %u, %u) in bid: @%lu "
"(%s,%u,%u,%u,%u)->(%u)",
cid->id,
cbidAddr,
cbid.bundleId.sourceEid,
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
cbid.bundleId.fragmentOffset,
cbid.bundleId.fragmentLength,
cbid.custodyId.id,
cbid.bundleId.sourceEid,
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
cbid.bundleId.fragmentOffset,
cbid.bundleId.fragmentLength,
bidCbidAddr,
bidCbid.bundleId.sourceEid,
bidCbid.bundleId.creationTime.seconds,
bidCbid.bundleId.creationTime.count,
bidCbid.bundleId.fragmentOffset,
bidCbid.bundleId.fragmentLength,
bidCbid.custodyId.id);
hasMismatch = 1;
}
/* If any section had a mismatch, this database entry is in error. */
if (hasMismatch != 0)
{
/* errors counts erroneous database entries; while it's helpful to
* print each mismatch separately, a set of mismatches for one bid/cbid
* pair only count as one error. */
++errors;
}
++(*cidCount);
}
static void printAndCheckByCids(Sdr acsSdr)
{
int cidCount = 0;
sdr_hash_foreach(acsSdr, acsConstants->cidHash, printAndCheckByCid, &cidCount);
writeMemoOrStdout("%d custody IDs", cidCount);
}
/* Takes a key/val pair from the hash table mapping bundle IDs to CBID pairs,
* and checks it for consistency. It doesn't print the mappings by default
* because each mapping should be discovered by printAndCheckByCids().
*
* If a mapping is found that does not match the mapping when searching by
* custody ID, that is an inconsistency and is reported as an error. */
static void checkByBid(Sdr acsSdr, Object hash, char *key, Address cbidAddr,
void *args)
{
AcsBundleId *bid = (AcsBundleId *)(key);
AcsCbidEntry cbid;
int hasMismatch = 0;
int rc;
Object hashEntry;
/* These two variables should match cbidAddr & cbid; but they're looked up
* in the cid hash table rather than bid hash table as a consistency check. */
Address cidCbidAddr;
AcsCbidEntry cidCbid;
/* Load the value. */
sdr_peek(acsSdr, cbid, cbidAddr);
/* Verify cbid's idea of bundle ID matches the bundle ID used as a key in
* the hash table. */
if (strcmp(cbid.bundleId.sourceEid, bid->sourceEid) != 0) {
writeMemoOrStdout("Mismatch: source EID in database (%s) "
"!= in key (%s)",
cbid.bundleId.sourceEid, bid->sourceEid);
hasMismatch = 1;
}
if (cbid.bundleId.creationTime.seconds != bid->creationTime.seconds ||
cbid.bundleId.creationTime.count != bid->creationTime.count)
{
writeMemoOrStdout("Mismatch: creation time in database (%u,%u) "
"!= in key (%u,%u)",
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
bid->creationTime.seconds,
bid->creationTime.count);
hasMismatch = 1;
}
if (cbid.bundleId.fragmentOffset != bid->fragmentOffset ||
cbid.bundleId.fragmentLength != bid->fragmentLength)
{
writeMemoOrStdout("Mismatch: fragment in database (%u,%u) "
"!= in key (%u,%u)",
cbid.bundleId.fragmentOffset, bid->fragmentLength,
cbid.bundleId.fragmentOffset, bid->fragmentLength);
hasMismatch = 1;
}
/* Verify that if we look up using the custody ID we've found, we get the
* same cbid (there are no dangling entries in the bidHash) */
rc = sdr_hash_retrieve(acsSdr, acsConstants->cidHash,
(char *)(&cbid.custodyId), &cidCbidAddr, &hashEntry);
if (rc == -1)
{
writeMemoOrStdout("Mismatch: can't find (%u) "
"in custody ID database.",
cbid.custodyId.id);
hasMismatch = 1;
}
else if (cbidAddr != cidCbidAddr)
{
sdr_peek(acsSdr, cidCbid, cidCbidAddr);
writeMemoOrStdout("Mismatch: "
"lookup (%s, %u, %u, %u, %u) in bid: @%lu (%s,%u,%u,%u,%u)->(%u) != "
"lookup (%u) in cid: @%lu (%s,%u,%u,%u,%u)->(%u)",
bid->sourceEid,
bid->creationTime.seconds,
bid->creationTime.count,
bid->fragmentOffset,
bid->fragmentLength,
cbidAddr,
cbid.bundleId.sourceEid,
cbid.bundleId.creationTime.seconds,
cbid.bundleId.creationTime.count,
cbid.bundleId.fragmentOffset,
cbid.bundleId.fragmentLength,
cbid.custodyId.id,
cbid.custodyId.id,
cidCbidAddr,
cidCbid.bundleId.sourceEid,
cidCbid.bundleId.creationTime.seconds,
cidCbid.bundleId.creationTime.count,
cidCbid.bundleId.fragmentOffset,
cidCbid.bundleId.fragmentLength,
cidCbid.custodyId.id);
hasMismatch = 1;
}
/* If any section had a mismatch, this database entry is in error. */
if (hasMismatch != 0)
{
/* errors counts erroneous database entries; while it's helpful to
* print each mismatch separately, a set of mismatches for one bid/cbid
* pair only count as one error. */
++errors;
}
}
static void checkByBids(Sdr acsSdr)
{
sdr_hash_foreach(acsSdr, acsConstants->bidHash, checkByBid, NULL);
}
#if defined (VXWORKS) || defined (RTEMS)
int acslist(int a1, int a2, int a3, int a4, int a5,
int a6, int a7, int a8, int a9, int a10)
{
#else
int main(int argc, char **argv)
{
if(argc > 1) {
if (strcmp(argv[1], "-s") == 0 ||
strcmp(argv[1], "--stdout") == 0) {
printToStdout = 1;
argc--;
argv++;
}
}
#endif
Sdr acsSdr;
/* Attach to ACS database. */
if (acsAttach() < 0)
{
putErrmsg("Can't attach to ACS.", NULL);
return 1;
}
acsSdr = getAcssdr();
/* Lock SDR and check the database. */
CHKZERO(sdr_begin_xn(acsSdr));
printAndCheckByCids(acsSdr);
checkByBids(acsSdr);
sdr_exit_xn(acsSdr);
/* Cleanup */
writeErrmsgMemos();
acsDetach();
bp_detach();
return errors == 0 ? 0 : 1;
}
|