PsmAddress sm_rbt_last(PsmPartition partition, PsmAddress rbt) { SmRbt *rbtPtr; PsmAddress node; PsmAddress last = 0; SmRbtNode *nodePtr; CHKZERO(partition); CHKZERO(rbt); rbtPtr = (SmRbt *) psp(partition, rbt); CHKZERO(rbtPtr); if (lockSmrbt(rbtPtr) == ERROR) { return 0; } node = rbtPtr->root; while (node) { last = node; nodePtr = (SmRbtNode *) psp(partition, node); if (nodePtr == NULL) { putErrmsg("Corrupt red-black tree.", NULL); last = 0; break; } node = nodePtr->child[RIGHT]; } unlockSmrbt(rbtPtr); return last; }
PsmAddress Sm_list_insert_after(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress oldElt, PsmAddress data) { SmListElt *oldEltBuffer; PsmAddress list; SmList *listBuffer; CHKZERO(partition); CHKZERO(oldElt); oldEltBuffer = (SmListElt *) psp(partition, oldElt); CHKZERO(oldEltBuffer); if ((list = oldEltBuffer->list) == 0) { putErrmsg(_noListMsg(), NULL); return 0; } listBuffer = (SmList *) psp(partition, list); if (lockSmlist(listBuffer) == ERROR) { putErrmsg(_cannotLockMsg(), NULL); return 0; } return finishInsertingAfter(fileName, lineNbr, partition, oldElt, oldEltBuffer, list, listBuffer, data); }
PsmAddress Sm_rbt_traverse(PsmPartition partition, PsmAddress fromNode, int direction) { SmRbtNode *nodePtr; SmRbt *rbtPtr; int nextNode; CHKZERO(partition); CHKZERO(fromNode); nodePtr = (SmRbtNode *) psp(partition, fromNode); CHKZERO(nodePtr); rbtPtr = (SmRbt *) psp(partition, nodePtr->rbt); CHKZERO(rbtPtr); if (lockSmrbt(rbtPtr) == ERROR) { return 0; } if (direction != LEFT) { direction = RIGHT; } nextNode = traverseRbt(partition, fromNode, direction); unlockSmrbt(rbtPtr); return nextNode; }
PsmAddress postProbeEvent(IonNode *node, Embargo *embargo) { PsmPartition ionwm = getIonwm(); PsmAddress addr; IonProbe *probe; IonVdb *ionvdb; IonNeighbor *neighbor; PsmAddress nextElt; unsigned int rtlt; /* Round-trip light time. */ int interval = 6; /* Minimum 6-sec interval. */ PsmAddress elt; IonProbe *pr; CHKZERO(node); CHKZERO(embargo); addr = psm_zalloc(ionwm, sizeof(IonProbe)); if (addr == 0) { putErrmsg("Can't create probe event.", NULL); return 0; } probe = (IonProbe *) psp(ionwm, addr); CHKZERO(probe); probe->time = getUTCTime(); probe->destNodeNbr = node->nodeNbr; probe->neighborNodeNbr = embargo->nodeNbr; /* Schedule next probe of this embargoed neighbor for the * time that is the current time plus 2x the round-trip * light time from the local node to the neighbor (but * at least 6 seconds). */ ionvdb = getIonVdb(); neighbor = findNeighbor(ionvdb, embargo->nodeNbr, &nextElt); if (neighbor) { rtlt = (neighbor->owltOutbound + neighbor->owltInbound) << 1; if (rtlt > interval) { interval = rtlt; } } probe->time += interval; for (elt = sm_list_last(ionwm, ionvdb->probes); elt; elt = sm_list_prev(ionwm, elt)) { pr = (IonProbe *) psp(ionwm, sm_list_data(ionwm, elt)); CHKZERO(pr); if (pr->time <= probe->time) { return sm_list_insert_after(ionwm, elt, addr); } } return sm_list_insert_first(ionwm, ionvdb->probes, addr); }
PsmAddress Sm_list_insert(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress list, PsmAddress data, SmListCompareFn compare, void *argData) { SmList *listBuffer; PsmAddress elt; SmListElt *eltBuffer; if (compare == (SmListCompareFn) NULL) { /* List is assumed to be unsorted. We simply add the new element at the end of the list. */ return Sm_list_insert_last(fileName, lineNbr, partition, list, data); } /* Using user-specified comparison function. List is assumed to be in sorted order. */ CHKZERO(partition); CHKZERO(list); listBuffer = (SmList *) psp(partition, list); CHKZERO(listBuffer); if (lockSmlist(listBuffer) == ERROR) { putErrmsg(_cannotLockMsg(), NULL); return 0; } /* Find position to insert new data into list. Start from end of list to keep sort stable; sort sequence is implicitly FIFO within key, i.e., we insert element AFTER the last element in the table with the same key value. */ for (elt = listBuffer->last; elt != 0; elt = eltBuffer->prev) { eltBuffer = (SmListElt *) psp(partition, elt); CHKZERO(eltBuffer); if (compare(partition, eltBuffer->data, argData) <= 0) { break; } } /* insert into list */ if (elt == 0) { return finishInsertingFirst(fileName, lineNbr, partition, list, listBuffer, data); } return finishInsertingAfter(fileName, lineNbr, partition, elt, eltBuffer, list, listBuffer, data); }
PsmAddress Sm_list_insert_before(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress oldElt, PsmAddress data) { SmListElt *oldEltBuffer; PsmAddress list; SmList *listBuffer; PsmAddress elt; SmListElt *eltBuffer; CHKZERO(partition); CHKZERO(oldElt); oldEltBuffer = (SmListElt *) psp(partition, oldElt); CHKZERO(oldEltBuffer); if ((list = oldEltBuffer->list) == 0) { putErrmsg(_noListMsg(), NULL); return 0; } listBuffer = (SmList *) psp(partition, list); if (lockSmlist(listBuffer) == ERROR) { putErrmsg(_cannotLockMsg(), NULL); return 0; } elt = Psm_zalloc(fileName, lineNbr, partition, sizeof(SmListElt)); if (elt == 0) { unlockSmlist(listBuffer); putErrmsg(_noSpaceForEltMsg(), NULL); return 0; } eltBuffer = (SmListElt *) psp(partition, elt); eraseListElt(eltBuffer); eltBuffer->list = list; eltBuffer->data = data; eltBuffer->prev = oldEltBuffer->prev; eltBuffer->next = oldElt; if (oldEltBuffer->prev != 0) { eltBuffer = (SmListElt *) psp(partition, oldEltBuffer->prev); CHKZERO(eltBuffer); eltBuffer->next = elt; } else { listBuffer->first = elt; } oldEltBuffer->prev = elt; listBuffer->length += 1; unlockSmlist(listBuffer); return elt; }
Object sdr_list_prev(Sdr sdrv, Object elt) { SdrListElt eltBuffer; CHKZERO(sdrFetchSafe(sdrv)); CHKZERO(elt); sdrFetch(eltBuffer, (Address) elt); return eltBuffer.prev; }
Object sdr_list_last(Sdr sdrv, Object list) { SdrList listBuffer; CHKZERO(sdrFetchSafe(sdrv)); CHKZERO(list); sdrFetch(listBuffer, (Address) list); return listBuffer.last; }
vast ionAppendZcoExtent(Object zco, ZcoMedium source, Object location, vast offset, vast size, int *cancel) { Sdr sdr = getIonsdr(); IonVdb *vdb = _ionvdb(NULL); Object length; int admissionDelayed = 0; CHKZERO(vdb); if (cancel) { *cancel = 0; /* Initialize. */ } CHKZERO(sdr_begin_xn(sdr)); while (1) { length = zco_append_extent(sdr, zco, source, location, offset, size); if (sdr_end_xn(sdr) < 0 || length == ERROR) { putErrmsg("Can't create ZCO.", NULL); return ERROR; } if (length == 0) /* Not enough ZCO space. */ { if (admissionDelayed) { ionReleaseZcoSpace(vdb); } admissionDelayed = 1; if (ionWaitForZcoSpace(vdb) == 1) { if (cancel && *cancel) { return 0; } CHKZERO(sdr_begin_xn(sdr)); continue; } return ERROR; } /* ZCO extent was appended. */ if (admissionDelayed) { ionReleaseZcoSpace(vdb); } return length; } }
Object ionCreateZco(ZcoMedium source, Object location, vast offset, vast size, int *cancel) { Sdr sdr = getIonsdr(); IonVdb *vdb = _ionvdb(NULL); Object zco; int admissionDelayed = 0; CHKZERO(vdb); if (cancel) { *cancel = 0; /* Initialize. */ } CHKZERO(sdr_begin_xn(sdr)); while (1) { zco = zco_create(sdr, source, location, offset, size); if (sdr_end_xn(sdr) < 0 || zco == (Object) ERROR) { putErrmsg("Can't create ZCO.", NULL); return 0; } if (zco == 0) /* Not enough ZCO space. */ { if (admissionDelayed) { ionReleaseZcoSpace(vdb); } admissionDelayed = 1; if (ionWaitForZcoSpace(vdb) == 1) { if (cancel && *cancel) { return 0; } CHKZERO(sdr_begin_xn(sdr)); continue; } return 0; } /* ZCO was created. */ if (admissionDelayed) { ionReleaseZcoSpace(vdb); } return zco; } }
PsmAddress sm_rbt_data(PsmPartition partition, PsmAddress node) { SmRbtNode *nodePtr; CHKZERO(partition); CHKZERO(node); nodePtr = (SmRbtNode *) psp(partition, node); CHKZERO(nodePtr); return nodePtr->data; }
PsmAddress sm_list_data(PsmPartition partition, PsmAddress elt) { SmListElt *eltBuffer; CHKZERO(partition); CHKZERO(elt); eltBuffer = (SmListElt *) psp(partition, elt); CHKZERO(eltBuffer); return eltBuffer->data; }
Address sdr_list_user_data(Sdr sdrv, Object list) { SdrState *sdr; SdrList listBuffer; CHKZERO(sdrv); CHKZERO(list); sdr = sdrv->sdr; CHKZERO(takeSdr(sdr) == 0); sdrFetch(listBuffer, list); releaseSdr(sdr); return listBuffer.userData; }
Object sdr_list_last(Sdr sdrv, Object list) { SdrState *sdr; SdrList listBuffer; CHKZERO(sdrv); CHKZERO(list); sdr = sdrv->sdr; CHKZERO(takeSdr(sdr) == 0); sdrFetch(listBuffer, (Address) list); releaseSdr(sdr); return listBuffer.last; }
Address sdr_list_data(Sdr sdrv, Object elt) { SdrState *sdr; SdrListElt eltBuffer; CHKZERO(sdrv); CHKZERO(elt); sdr = sdrv->sdr; CHKZERO(takeSdr(sdr) == 0); sdrFetch(eltBuffer, (Address) elt); releaseSdr(sdr); return eltBuffer.data; }
int _extractSmallSdnv(unsigned int *into, unsigned char **from, int *remnant, int lineNbr) { int sdnvLength; uvast val; CHKZERO(into && from && remnant); if (*remnant < 1) { writeMemoNote("[?] Missing SDNV at line...", itoa(lineNbr)); return 0; } sdnvLength = decodeSdnv(&val, *from); if (sdnvLength < 1) { writeMemoNote("[?] Invalid SDNV at line...", itoa(lineNbr)); return 0; } *into = val; /* Truncate. */ (*from) += sdnvLength; (*remnant) -= sdnvLength; return sdnvLength; }
Object getOrMakeCustodianByEid(Object custodians, const char *eid) { Object custodianAddr; /* Try to find custodian info if it exists. */ CHKZERO(sdr_begin_xn(acsSdr)); custodianAddr = findCustodianByEid(custodians, eid); if(sdr_end_xn(acsSdr) < 0) { putErrmsg("Can't search custodian database", eid); return 0; } /* If no custodian info, make it. */ if(custodianAddr == 0) { custodianAddr = newSdrAcsCustodian(custodians, eid); if(custodianAddr == 0) { ACSLOG_WARN("Couldn't record new custodian info for %s", eid); return 0; } } return custodianAddr; }
static Object newSdrAcsCustodian(Object custodians, const char *eid) { Object newCustodianAddr; SdrAcsPendingCust newCustodian; memset(&newCustodian, 0, sizeof(newCustodian)); strncpy(newCustodian.eid, eid, MAX_EID_LEN); newCustodian.eid[MAX_EID_LEN] = '\0'; /* Set default ACS size and delay. */ newCustodian.acsDelay = 2; newCustodian.acsSize = 300; CHKZERO(sdr_begin_xn(acsSdr)); newCustodianAddr = sdr_malloc(acsSdr, sizeof(newCustodian)); newCustodian.signals = sdr_list_create(acsSdr); sdr_poke(acsSdr, newCustodianAddr, newCustodian); sdr_list_insert_last(acsSdr, custodians, newCustodianAddr); if(sdr_end_xn(acsSdr) < 0) { ACSLOG_WARN("Couldn't create new custodian info for %s", eid); return 0; } return newCustodianAddr; }
Address sdr_list_data(Sdr sdrv, Object elt) { SdrListElt eltBuffer; CHKZERO(elt); sdrFetch(eltBuffer, (Address) elt); return eltBuffer.data; }
Object sdr_list_list(Sdr sdrv, Object elt) { SdrListElt eltBuffer; CHKZERO(elt); sdrFetch(eltBuffer, (Address) elt); return eltBuffer.list; }
Address sdr_list_user_data(Sdr sdrv, Object list) { SdrList listBuffer; CHKZERO(list); sdrFetch(listBuffer, list); return listBuffer.userData; }
PsmAddress sm_list_user_data(PsmPartition partition, PsmAddress list) { SmList *listBuffer; PsmAddress userData; CHKZERO(partition); CHKZERO(list); listBuffer = (SmList *) psp(partition, list); CHKZERO(listBuffer); if (lockSmlist(listBuffer) == ERROR) { return 0; } userData = listBuffer->userData; unlockSmlist(listBuffer); return userData; }
PsmAddress sm_rbt_user_data(PsmPartition partition, PsmAddress rbt) { SmRbt *rbtPtr; PsmAddress userData; CHKZERO(partition); CHKZERO(rbt); rbtPtr = (SmRbt *) psp(partition, rbt); CHKZERO(rbtPtr); if (lockSmrbt(rbtPtr) == ERROR) { return 0; } userData = rbtPtr->userData; unlockSmrbt(rbtPtr); return userData; }
Object sdr_list_first(Sdr sdrv, Object list) { //TODO stub //SdrList listBuffer; //CHKZERO(sdrFetchSafe(sdrv)); CHKZERO(list); //sdrFetch(listBuffer, (Address) list); //return listBuffer.first; return sm_list_first(sdrv, list); }
PsmAddress sm_list_last(PsmPartition partition, PsmAddress list) { SmList *listBuffer; PsmAddress last; CHKZERO(partition); CHKZERO(list); listBuffer = (SmList *) psp(partition, list); CHKZERO(listBuffer); if (lockSmlist(listBuffer) == ERROR) { putErrmsg("Can't get last element.", NULL); return 0; } last = listBuffer->last; unlockSmlist(listBuffer); return last; }
Object sdr_list_prev(Sdr sdrv, Object elt) { //TODO stub //SdrListElt eltBuffer; //CHKZERO(sdrFetchSafe(sdrv)); CHKZERO(elt); //sdrFetch(eltBuffer, (Address) elt); //return eltBuffer.prev; return sm_list_prev(sdrv, elt); }
PsmAddress psm_get_root(PsmPartition partition) { PartitionMap *map; PsmAddress root; CHKZERO(partition); map = (PartitionMap *) (partition->space); lockPartition(map); root = map->directory; unlockPartition(map); return root; }
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; }
static PsmAddress finishInsertingAfter(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress oldElt, SmListElt *oldEltBuffer, PsmAddress list, SmList *listBuffer, PsmAddress data) { PsmAddress elt; SmListElt *eltBuffer; elt = Psm_zalloc(fileName, lineNbr, partition, sizeof(SmListElt)); if (elt == 0) { unlockSmlist(listBuffer); putErrmsg(_noSpaceForEltMsg(), NULL); return 0; } eltBuffer = (SmListElt *) psp(partition, elt); eraseListElt(eltBuffer); eltBuffer->list = list; eltBuffer->data = data; eltBuffer->next = oldEltBuffer->next; eltBuffer->prev = oldElt; if (oldEltBuffer->next != 0) { eltBuffer = (SmListElt *) psp(partition, oldEltBuffer->next); CHKZERO(eltBuffer); eltBuffer->prev = elt; } else { listBuffer->last = elt; } oldEltBuffer->next = elt; listBuffer->length += 1; unlockSmlist(listBuffer); return elt; }
int _extractSdnv(unsigned long *into, unsigned char **from, int *remnant, int lineNbr) { int sdnvLength; CHKZERO(into && from && remnant); if (*remnant < 1) { writeMemoNote("[?] Missing SDNV at line...", itoa(lineNbr)); return 0; } sdnvLength = decodeSdnv(into, *from); if (sdnvLength < 1) { writeMemoNote("[?] Invalid SDNV at line...", itoa(lineNbr)); return 0; } (*from) += sdnvLength; (*remnant) -= sdnvLength; return sdnvLength; }