Пример #1
0
void cm_InitDaemon(int nDaemons)
{
    static osi_once_t once;
    long pid;
    thread_t phandle;
    int i;

    cm_nDaemons = (nDaemons > CM_MAX_DAEMONS) ? CM_MAX_DAEMONS : nDaemons;
    
    if (osi_Once(&once)) {
        lock_InitializeRWLock(&cm_daemonLock, "cm_daemonLock", 
                               LOCK_HIERARCHY_DAEMON_GLOBAL);
        osi_EndOnce(&once);

	/* creating IP Address Change monitor daemon */
        phandle = thrd_Create((SecurityAttrib) 0, 0,
                               (ThreadFunc) cm_IpAddrDaemon, 0, 0, &pid, "cm_IpAddrDaemon");
        osi_assertx(phandle != NULL, "cm_IpAddrDaemon thread creation failure");
        thrd_CloseHandle(phandle);

        /* creating pinging daemon */
        phandle = thrd_Create((SecurityAttrib) 0, 0,
                               (ThreadFunc) cm_Daemon, 0, 0, &pid, "cm_Daemon");
        osi_assertx(phandle != NULL, "cm_Daemon thread creation failure");
        thrd_CloseHandle(phandle);

	for(i=0; i < cm_nDaemons; i++) {
            phandle = thrd_Create((SecurityAttrib) 0, 0,
                                   (ThreadFunc) cm_BkgDaemon, (LPVOID)i, 0, &pid,
                                   "cm_BkgDaemon");
            osi_assertx(phandle != NULL, "cm_BkgDaemon thread creation failure");
            thrd_CloseHandle(phandle);
        }
    }
}
Пример #2
0
void cm_InitCell(int newFile, long maxCells)
{
    static osi_once_t once;

    if (osi_Once(&once)) {
        cm_cell_t * cellp;

        lock_InitializeRWLock(&cm_cellLock, "cell global lock", LOCK_HIERARCHY_CELL_GLOBAL);

        if ( newFile ) {
            cm_data.allCellsp = NULL;
            cm_data.currentCells = 0;
            cm_data.maxCells = maxCells;
            memset(cm_data.cellNameHashTablep, 0, sizeof(cm_cell_t *) * cm_data.cellHashTableSize);
            memset(cm_data.cellIDHashTablep, 0, sizeof(cm_cell_t *) * cm_data.cellHashTableSize);

#ifdef AFS_FREELANCE_CLIENT
            /* Generate a dummy entry for the Freelance cell whether or not
             * freelance mode is being used in this session
             */

            cellp = &cm_data.cellBaseAddress[cm_data.currentCells++];
            memset(cellp, 0, sizeof(cm_cell_t));
            cellp->magic = CM_CELL_MAGIC;

            lock_InitializeMutex(&cellp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL);

            lock_ObtainMutex(&cellp->mx);
            lock_ObtainWrite(&cm_cellLock);

            /* copy in name */
            strncpy(cellp->name, "Freelance.Local.Cell", CELL_MAXNAMELEN); /*safe*/
            cellp->name[CELL_MAXNAMELEN-1] = '\0';

            /* thread on global list */
            cellp->allNextp = cm_data.allCellsp;
            cm_data.allCellsp = cellp;

            cellp->cellID = AFS_FAKE_ROOT_CELL_ID;
            cellp->vlServersp = NULL;
            _InterlockedOr(&cellp->flags, CM_CELLFLAG_FREELANCE);

            cm_AddCellToNameHashTable(cellp);
            cm_AddCellToIDHashTable(cellp);
            lock_ReleaseWrite(&cm_cellLock);
            lock_ReleaseMutex(&cellp->mx);
#endif
        } else {
            lock_ObtainRead(&cm_cellLock);
            for (cellp = cm_data.allCellsp; cellp; cellp=cellp->allNextp) {
                lock_InitializeMutex(&cellp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL);
                cellp->vlServersp = NULL;
                _InterlockedOr(&cellp->flags, CM_CELLFLAG_VLSERVER_INVALID);
            }
            lock_ReleaseRead(&cm_cellLock);
        }

        osi_EndOnce(&once);
    }
}
Пример #3
0
cm_space_t *cm_GetSpace(void)
{
	cm_space_t *tsp;

	if (osi_Once(&cm_utilsOnce)) {
		lock_InitializeRWLock(&cm_utilsLock, "cm_utilsLock", LOCK_HIERARCHY_UTILS_GLOBAL);
		osi_EndOnce(&cm_utilsOnce);
        }
        
        lock_ObtainWrite(&cm_utilsLock);
	if (tsp = cm_spaceListp) {
		cm_spaceListp = tsp->nextp;
        }
        else tsp = (cm_space_t *) malloc(sizeof(cm_space_t));
	(void) memset(tsp, 0, sizeof(cm_space_t));
        lock_ReleaseWrite(&cm_utilsLock);
        
        return tsp;
}
Пример #4
0
void cm_InitDaemon(int nDaemons)
{
    static osi_once_t once;
    pthread_t phandle;
    pthread_attr_t tattr;
    int pstatus;
    int i;

    pthread_attr_init(&tattr);
    pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);

    cm_nDaemons = (nDaemons > CM_MAX_DAEMONS) ? CM_MAX_DAEMONS : nDaemons;

    if (osi_Once(&once)) {
	/* creating IP Address Change monitor daemon */
        pstatus = pthread_create(&phandle, &tattr, cm_IpAddrDaemon, 0);
        osi_assertx(pstatus == 0, "cm_IpAddrDaemon thread creation failure");

        /* creating pinging daemon */
        pstatus = pthread_create(&phandle, &tattr, cm_Daemon, 0);
        osi_assertx(pstatus == 0, "cm_Daemon thread creation failure");

        pstatus = pthread_create(&phandle, &tattr, cm_LockDaemon, 0);
        osi_assertx(pstatus == 0, "cm_LockDaemon thread creation failure");

        cm_bkgListpp = malloc(nDaemons * sizeof(void *));
        cm_bkgListEndpp = malloc(nDaemons * sizeof(void *));
        cm_bkgQueueCountp = malloc(nDaemons * sizeof(afs_uint64));
        cm_daemonLockp = malloc(nDaemons * sizeof(osi_rwlock_t));

	for(i=0; i < cm_nDaemons; i++) {
            lock_InitializeRWLock(&cm_daemonLockp[i], "cm_daemonLock",
                                  LOCK_HIERARCHY_DAEMON_GLOBAL);
            cm_bkgListpp[i] = cm_bkgListEndpp[i] = NULL;
            cm_bkgQueueCountp[i]=0;
            pstatus = pthread_create(&phandle, &tattr, cm_BkgDaemon, (LPVOID)(LONG_PTR)i);
            osi_assertx(pstatus == 0, "cm_BkgDaemon thread creation failure");
        }
        osi_EndOnce(&once);
    }

    pthread_attr_destroy(&tattr);
}
Пример #5
0
/* 
 * Initialize the cache to have an entries.  Called during system startup.
 */
long cm_InitACLCache(int newFile, long size)
{
    cm_aclent_t *aclp;
    long i;
    static osi_once_t once;

    if (osi_Once(&once)) {
        lock_InitializeRWLock(&cm_aclLock, "cm_aclLock", LOCK_HIERARCHY_ACL_GLOBAL);
        osi_EndOnce(&once);
    }

    lock_ObtainWrite(&cm_aclLock);
    if ( newFile ) {
        cm_data.aclLRUp = cm_data.aclLRUEndp = NULL;
        aclp = (cm_aclent_t *) cm_data.aclBaseAddress;
        memset(aclp, 0, size * sizeof(cm_aclent_t));

        /* 
         * Put all of these guys on the LRU queue 
         */
        for (i = 0; i < size; i++) {
            aclp->magic = CM_ACLENT_MAGIC;
            osi_QAddH((osi_queue_t **) &cm_data.aclLRUp, (osi_queue_t **) &cm_data.aclLRUEndp, &aclp->q);
            aclp++;
        }
    } else {
        aclp = (cm_aclent_t *) cm_data.aclBaseAddress;
        for (i = 0; i < size; i++) {
            aclp->userp = NULL;
            aclp->tgtLifetime = 0;
            aclp++;
        }
    }
    lock_ReleaseWrite(&cm_aclLock);
    return 0;
}
Пример #6
0
/* create a new log, taking a name and a size in entries (not words) */
osi_log_t *osi_LogCreate(char *namep, size_t size)
{
    osi_log_t *logp;
    osi_fdType_t *typep;
    char tbuffer[256];
    LARGE_INTEGER bigFreq;
    LARGE_INTEGER bigTemp;
    LARGE_INTEGER bigJunk;

    if (osi_Once(&osi_logOnce)) {
        QueryPerformanceFrequency(&bigFreq);
        if (bigFreq.LowPart == 0 && bigFreq.HighPart == 0)
            osi_logFreq = 0;
        else {
            /* turn frequency into ticks per 10 micros */
            bigTemp.LowPart = 100000;
            bigTemp.HighPart = 0;
            osi_logTixToMicros = 10;
            bigFreq = LargeIntegerDivide(bigFreq, bigTemp, &bigJunk);

            /* check if resolution is too fine or to gross for this to work */
            if (bigFreq.HighPart > 0 || bigFreq.LowPart < 8)
                osi_logFreq = 0;	/* too big to represent as long */
            else
                osi_logFreq = bigFreq.LowPart;
        }

        /* done with init */
        osi_EndOnce(&osi_logOnce);
    }

    logp = malloc(sizeof(osi_log_t));
    memset(logp, 0, sizeof(osi_log_t));
    {
        size_t namelen = strlen(namep) + 1;

        logp->namep = malloc(namelen * sizeof(char));
        StringCchCopyA(logp->namep, namelen, namep);
    }
    osi_QAdd((osi_queue_t **) &osi_allLogsp, &logp->q);

    /* compute size we'll use */
    if (size == 0) size = osi_logSize;

    /* handle init for this size */
    logp->alloc = size;
    logp->datap = malloc(size * sizeof(osi_logEntry_t));

    /* init strings array */
    logp->maxstringindex = size/3;
    logp->stringindex = 0;
    logp->stringsp = malloc(logp->maxstringindex * OSI_LOG_STRINGSIZE);

    /* and sync */
    thrd_InitCrit(&logp->cs);

    StringCbCopyA(tbuffer, sizeof(tbuffer), "log:");
    StringCbCatA(tbuffer, sizeof(tbuffer), namep);
    typep = osi_RegisterFDType(tbuffer, &osi_logFDOps, logp);
    if (typep) {
        /* add formatting info */
        osi_AddFDFormatInfo(typep, OSI_DBRPC_REGIONINT, 0,
                            "Thread ID", OSI_DBRPC_HEX);
        osi_AddFDFormatInfo(typep, OSI_DBRPC_REGIONSTRING, 1,
                            "Time (mics)", 0);
    }

    return logp;
}
Пример #7
0
/* Initialize the package, should be called while single-threaded.
 * Can be safely called multiple times.
 * Must be called before any osi package calls.
 */
void osi_Init(void)
{
    int i;
    static osi_once_t once;
    unsigned long remainder;		/* for division output */
    osi_fdType_t *typep;
    FILETIME fileTime;
    osi_hyper_t bootTime;

    /* check to see if already initialized; if so, claim success */
    if (!osi_Once(&once))
        return;

    /* setup boot time values */
    GetSystemTimeAsFileTime(&fileTime);

    /* change the base of the time so it won't be negative for a long time */
    fileTime.dwHighDateTime -= 28000000;

    bootTime.HighPart = fileTime.dwHighDateTime;
    bootTime.LowPart = fileTime.dwLowDateTime;
    /* now, bootTime is in 100 nanosecond units, and we'd really rather
     * have it in 1 second units, units 10,000,000 times bigger.
     * So, we divide.
     */
    bootTime = ExtendedLargeIntegerDivide(bootTime, 10000000, &remainder);
    osi_bootTime = bootTime.LowPart;

    /* initialize thread-local storage for sleep Info structures */
    osi_SleepSlot = TlsAlloc();

    /* init FD system */
    osi_InitFD();

    /* initialize critical regions and semaphores */
    for(i=0;i<OSI_SLEEPHASHSIZE; i++) {
        InitializeCriticalSection(&osi_critSec[i]);
        osi_sleepers[i] = NULL;
        osi_sleepersEnd[i] = NULL;
    }

    /* free list CS */
    InitializeCriticalSection(&osi_sleepInfoAllocCS);

    /* initialize cookie system */
    InitializeCriticalSection(&osi_sleepFDCS);

    /* register the FD type */
    typep = osi_RegisterFDType("sleep", &osi_sleepFDOps, NULL);
    if (typep) {
        /* add formatting info */
        osi_AddFDFormatInfo(typep, OSI_DBRPC_REGIONINT, 0,
                             "Sleep address", OSI_DBRPC_HEX);
        osi_AddFDFormatInfo(typep, OSI_DBRPC_REGIONINT, 1,
                             "Thread ID", 0);
        osi_AddFDFormatInfo(typep, OSI_DBRPC_REGIONINT, 2,
                             "States", OSI_DBRPC_HEX);
    }

    osi_BaseInit();

    osi_StatInit();

    osi_InitQueue();

    osi_EndOnce(&once);
}