void ionDropVdb() { PsmPartition wm = getIonwm(); char *ionvdbName = _ionvdbName(); PsmAddress vdbAddress; PsmAddress elt; char *stop = NULL; if (psm_locate(wm, ionvdbName, &vdbAddress, &elt) < 0) { putErrmsg("Failed searching for vdb.", NULL); return; } if (elt) { dropVdb(wm, vdbAddress); /* Destroy Vdb. */ psm_free(wm, vdbAddress); if (psm_uncatlg(wm, ionvdbName) < 0) { putErrmsg("Failed uncataloging vdb.", NULL); } } oK(_ionvdb(&stop)); /* Forget old Vdb. */ }
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; } }
void ionRaiseVdb() { char *ionvdbName = _ionvdbName(); if(_ionvdb(&ionvdbName) == NULL) /* Create new Vdb. */ { putErrmsg("ION can't reinitialize vdb.", NULL); } }
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; } }
time_t getUTCTime() { IonVdb *ionvdb = _ionvdb(NULL); time_t clocktime; #if defined(FSWCLOCK) #include "fswutc.c" #else clocktime = time(NULL); #endif return clocktime - ionvdb->deltaFromUTC; }
static void ionOfferZcoSpace() { IonVdb *vdb = _ionvdb(NULL); if (vdb) { /* Give all tasks currently waiting for ZCO * space a shot at claiming the space that * has now been made available. */ vdb->zcoClaims += vdb->zcoClaimants; vdb->zcoClaimants = 0; if (vdb->zcoClaims > 0) { sm_SemGive(vdb->zcoSemaphore); } } }
int setDeltaFromUTC(int newDelta) { Sdr ionsdr = _ionsdr(NULL); Object iondbObject = _iondbObject(NULL); IonDB *ionConstants = _ionConstants(); IonVdb *ionvdb = _ionvdb(NULL); sdr_begin_xn(ionsdr); sdr_stage(ionsdr, (char *) ionConstants, iondbObject, sizeof(IonDB)); ionConstants->deltaFromUTC = newDelta; sdr_write(ionsdr, iondbObject, (char *) ionConstants, sizeof(IonDB)); if (sdr_end_xn(ionsdr) < 0) { putErrmsg("Can't change delta from UTC.", NULL); return -1; } ionvdb->deltaFromUTC = newDelta; return 0; }
void ionTerminate() { Sdr sdr = _ionsdr(NULL); Object obj = 0; sm_WmParms ionwmParms; char *ionvdbName = NULL; if (sdr) { sdr_destroy(sdr); sdr = NULL; oK(_ionsdr(&sdr)); /* To reset to NULL. */ } oK(_iondbObject(&obj)); ionwmParms.wmKey = 0; ionwmParms.wmSize = -1; ionwmParms.wmAddress = NULL; oK(_ionwm(&ionwmParms)); oK(_ionvdb(&ionvdbName)); }
IonVdb *getIonVdb() { return _ionvdb(NULL); }
int ionAttach() { Sdr ionsdr = _ionsdr(NULL); Object iondbObject = _iondbObject(NULL); PsmPartition ionwm = _ionwm(NULL); IonVdb *ionvdb = _ionvdb(NULL); char *wdname; char wdnamebuf[256]; IonParms parms; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); if (ionsdr && iondbObject && ionwm && ionvdb) { return 0; /* Already attached. */ } if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } wdname = getenv("ION_NODE_WDNAME"); if (wdname == NULL) { if (igetcwd(wdnamebuf, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } wdname = wdnamebuf; } memset((char *) &parms, 0, sizeof parms); if (checkNodeListParms(&parms, wdname, 0) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (ionsdr == NULL) { ionsdr = sdr_start_using(parms.sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } oK(_ionsdr(&ionsdr)); } if (iondbObject == 0) { sdr_begin_xn(ionsdr); /* Lock database. */ iondbObject = sdr_find(ionsdr, _iondbName(), NULL); sdr_exit_xn(ionsdr); /* Unlock database. */ if (iondbObject == 0) { putErrmsg("ION database not found.", NULL); return -1; } oK(_iondbObject(&iondbObject)); } oK(_ionConstants()); /* Open ION shared-memory partition. */ if (ionwm == NULL) { ionwmParms.wmKey = parms.wmKey; ionwmParms.wmSize = 0; ionwmParms.wmAddress = NULL; ionwmParms.wmName = ION_SM_NAME; ionwm = _ionwm(&ionwmParms); if (ionwm == NULL) { putErrmsg("Can't open access to ION memory.", NULL); return -1; } } if (ionvdb == NULL) { if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION volatile database not found.", NULL); return -1; } } ionRedirectMemos(); return 0; }
int ionInitialize(IonParms *parms, unsigned long ownNodeNbr) { char wdname[256]; Sdr ionsdr; Object iondbObject; IonDB iondbBuf; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); CHKERR(parms); CHKERR(ownNodeNbr); if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } if (igetcwd(wdname, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } if (checkNodeListParms(parms, wdname, ownNodeNbr) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (sdr_load_profile(parms->sdrName, parms->configFlags, parms->heapWords, parms->heapKey, parms->pathName) < 0) { putErrmsg("Unable to load SDR profile for ION.", NULL); return -1; } ionsdr = sdr_start_using(parms->sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } ionsdr = _ionsdr(&ionsdr); /* Recover the ION database, creating it if necessary. */ sdr_begin_xn(ionsdr); iondbObject = sdr_find(ionsdr, _iondbName(), NULL); switch (iondbObject) { case -1: /* SDR error. */ sdr_cancel_xn(ionsdr); putErrmsg("Can't seek ION database in SDR.", NULL); return -1; case 0: /* Not found; must create new DB. */ if (ownNodeNbr == 0) { sdr_cancel_xn(ionsdr); putErrmsg("Must supply non-zero node number.", NULL); return -1; } memset((char *) &iondbBuf, 0, sizeof(IonDB)); memcpy(iondbBuf.workingDirectoryName, wdname, 256); iondbBuf.ownNodeNbr = ownNodeNbr; iondbBuf.occupancyCeiling = ((sdr_heap_size(ionsdr) / 100) * (100 - ION_SEQUESTERED)); iondbBuf.receptionSpikeReserve = iondbBuf.occupancyCeiling / 16; if (iondbBuf.receptionSpikeReserve < MIN_SPIKE_RSRV) { iondbBuf.receptionSpikeReserve = MIN_SPIKE_RSRV; } iondbBuf.contacts = sdr_list_create(ionsdr); iondbBuf.ranges = sdr_list_create(ionsdr); iondbBuf.maxClockError = 0; iondbObject = sdr_malloc(ionsdr, sizeof(IonDB)); if (iondbObject == 0) { sdr_cancel_xn(ionsdr); putErrmsg("No space for database.", NULL); return -1; } sdr_write(ionsdr, iondbObject, (char *) &iondbBuf, sizeof(IonDB)); sdr_catlg(ionsdr, _iondbName(), 0, iondbObject); if (sdr_end_xn(ionsdr)) { putErrmsg("Can't create ION database.", NULL); return -1; } break; default: /* Found DB in the SDR. */ sdr_exit_xn(ionsdr); } oK(_iondbObject(&iondbObject)); oK(_ionConstants()); /* Open ION shared-memory partition. */ ionwmParms.wmKey = parms->wmKey; ionwmParms.wmSize = parms->wmSize; ionwmParms.wmAddress = parms->wmAddress; ionwmParms.wmName = ION_SM_NAME; if (_ionwm(&ionwmParms) == NULL) { putErrmsg("ION memory configuration failed.", NULL); return -1; } if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION can't initialize vdb.", NULL); return -1; } ionRedirectMemos(); return 0; }
int ionInitialize(IonParms *parms, uvast ownNodeNbr) { char wdname[256]; Sdr ionsdr; Object iondbObject; IonDB iondbBuf; vast limit; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); ZcoCallback notify = ionOfferZcoSpace; CHKERR(parms); CHKERR(ownNodeNbr); #ifdef mingw if (_winsock(0) < 0) { return -1; } #endif if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } if (igetcwd(wdname, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } if (checkNodeListParms(parms, wdname, ownNodeNbr) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (sdr_load_profile(parms->sdrName, parms->configFlags, parms->heapWords, parms->heapKey, parms->pathName, "ionrestart") < 0) { putErrmsg("Unable to load SDR profile for ION.", NULL); return -1; } ionsdr = sdr_start_using(parms->sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } ionsdr = _ionsdr(&ionsdr); /* Recover the ION database, creating it if necessary. */ CHKERR(sdr_begin_xn(ionsdr)); iondbObject = sdr_find(ionsdr, _iondbName(), NULL); switch (iondbObject) { case -1: /* SDR error. */ sdr_cancel_xn(ionsdr); putErrmsg("Can't seek ION database in SDR.", NULL); return -1; case 0: /* Not found; must create new DB. */ if (ownNodeNbr == 0) { sdr_cancel_xn(ionsdr); putErrmsg("Must supply non-zero node number.", NULL); return -1; } memset((char *) &iondbBuf, 0, sizeof(IonDB)); memcpy(iondbBuf.workingDirectoryName, wdname, 256); iondbBuf.ownNodeNbr = ownNodeNbr; iondbBuf.productionRate = -1; /* Unknown. */ iondbBuf.consumptionRate = -1; /* Unknown. */ limit = (sdr_heap_size(ionsdr) / 100) * (100 - ION_SEQUESTERED); zco_set_max_heap_occupancy(ionsdr, limit); iondbBuf.occupancyCeiling = zco_get_max_file_occupancy(ionsdr); iondbBuf.occupancyCeiling += limit; iondbBuf.contacts = sdr_list_create(ionsdr); iondbBuf.ranges = sdr_list_create(ionsdr); iondbBuf.maxClockError = 0; iondbBuf.clockIsSynchronized = 1; memcpy(&iondbBuf.parmcopy, parms, sizeof(IonParms)); iondbObject = sdr_malloc(ionsdr, sizeof(IonDB)); if (iondbObject == 0) { sdr_cancel_xn(ionsdr); putErrmsg("No space for database.", NULL); return -1; } sdr_write(ionsdr, iondbObject, (char *) &iondbBuf, sizeof(IonDB)); sdr_catlg(ionsdr, _iondbName(), 0, iondbObject); if (sdr_end_xn(ionsdr)) { putErrmsg("Can't create ION database.", NULL); return -1; } break; default: /* Found DB in the SDR. */ sdr_exit_xn(ionsdr); } oK(_iondbObject(&iondbObject)); oK(_ionConstants()); /* Open ION shared-memory partition. */ ionwmParms.wmKey = parms->wmKey; ionwmParms.wmSize = parms->wmSize; ionwmParms.wmAddress = parms->wmAddress; ionwmParms.wmName = ION_SM_NAME; if (_ionwm(&ionwmParms) == NULL) { putErrmsg("ION memory configuration failed.", NULL); return -1; } if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION can't initialize vdb.", NULL); return -1; } zco_register_callback(notify); ionRedirectMemos(); #ifdef mingw DWORD threadId; HANDLE thread = CreateThread(NULL, 0, waitForSigterm, NULL, 0, &threadId); if (thread == NULL) { putErrmsg("Can't create sigterm thread.", utoa(GetLastError())); } else { CloseHandle(thread); } #endif return 0; }
int ionAttach() { Sdr ionsdr = _ionsdr(NULL); Object iondbObject = _iondbObject(NULL); PsmPartition ionwm = _ionwm(NULL); IonVdb *ionvdb = _ionvdb(NULL); char *wdname; char wdnamebuf[256]; IonParms parms; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); ZcoCallback notify = ionOfferZcoSpace; if (ionsdr && iondbObject && ionwm && ionvdb) { return 0; /* Already attached. */ } #ifdef mingw if (_winsock(0) < 0) { return -1; } signal(SIGINT, SIG_IGN); #endif if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } wdname = getenv("ION_NODE_WDNAME"); if (wdname == NULL) { if (igetcwd(wdnamebuf, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } wdname = wdnamebuf; } memset((char *) &parms, 0, sizeof parms); if (checkNodeListParms(&parms, wdname, 0) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (ionsdr == NULL) { ionsdr = sdr_start_using(parms.sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } oK(_ionsdr(&ionsdr)); } if (iondbObject == 0) { if (sdr_heap_is_halted(ionsdr)) { iondbObject = sdr_find(ionsdr, _iondbName(), NULL); } else { CHKERR(sdr_begin_xn(ionsdr)); iondbObject = sdr_find(ionsdr, _iondbName(), NULL); sdr_exit_xn(ionsdr); } if (iondbObject == 0) { putErrmsg("ION database not found.", NULL); return -1; } oK(_iondbObject(&iondbObject)); } oK(_ionConstants()); /* Open ION shared-memory partition. */ if (ionwm == NULL) { ionwmParms.wmKey = parms.wmKey; ionwmParms.wmSize = 0; ionwmParms.wmAddress = NULL; ionwmParms.wmName = ION_SM_NAME; ionwm = _ionwm(&ionwmParms); if (ionwm == NULL) { putErrmsg("Can't open access to ION memory.", NULL); return -1; } } if (ionvdb == NULL) { if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION volatile database not found.", NULL); return -1; } } zco_register_callback(notify); ionRedirectMemos(); #ifdef mingw DWORD threadId; HANDLE thread = CreateThread(NULL, 0, waitForSigterm, NULL, 0, &threadId); if (thread == NULL) { putErrmsg("Can't create sigterm thread.", utoa(GetLastError())); } else { CloseHandle(thread); } #endif return 0; }