int
uninitPreload (preloadConfig_t *preloadConfig) {
    int status;
    int i;
    int size;

    // destroy preload thread list
    size = listSize(PreloadThreadList);
    for(i=0;i<size;i++) {
        preloadThreadInfo_t *threadInfo = (preloadThreadInfo_t *)removeFirstElementOfConcurrentList(PreloadThreadList);
        if(threadInfo->running == PRELOAD_THREAD_RUNNING) {        
#ifdef USE_BOOST
            status = threadInfo->thread->join();
#else
            status = pthread_join(threadInfo->thread, NULL);
#endif
        }

        if(threadInfo->path != NULL) {
            free(threadInfo->path);
            threadInfo->path = NULL;
        }
    }

    if(preloadConfig->clearCache) {
        // clear all cache
        _removeAllCaches();
    } else {
        // remove incomplete preload caches
        _removeAllIncompleteCaches(preloadConfig->cachePath);
    }

    FREE_LOCK(PreloadLock);
    return (0);
}
示例#2
0
int
disconnectAll() {
    iFuseConn_t *tmpIFuseConn;
    while ( ( tmpIFuseConn = ( iFuseConn_t * ) removeFirstElementOfConcurrentList( ConnectedConn ) ) != NULL ) {
        ifuseDisconnect( tmpIFuseConn );
    }
    return 0;
}
示例#3
0
int _getAndUseIFuseConn( iFuseConn_t **iFuseConn ) {
    int status;
    iFuseConn_t *tmpIFuseConn;

    *iFuseConn = NULL;

    LOCK( WaitForConnLock );
    while ( listSize( ConnectedConn ) >= MAX_NUM_CONN && listSize( FreeConn ) == 0 ) {
        untimedWait( &connReqWait.mutex, &connReqWait.cond );
    }

    tmpIFuseConn = ( iFuseConn_t * ) removeFirstElementOfConcurrentList( FreeConn );
    if ( tmpIFuseConn == NULL ) {
        if ( listSize( ConnectedConn ) < MAX_NUM_CONN ) {
            tmpIFuseConn = newIFuseConn( &status );
            if ( status < 0 ) {
                _freeIFuseConn( tmpIFuseConn );
                return status;
            }
            _useFreeIFuseConn( tmpIFuseConn );
            addToConcurrentList( ConnectedConn, tmpIFuseConn );
            *iFuseConn = tmpIFuseConn;
        }
        else {
            rodsLog( LOG_ERROR, "failure to acquire fuse connection; maximum fuse connections exceeded." );
            return SYS_MAX_CONNECT_COUNT_EXCEEDED;
        }
    }
    else {
        useIFuseConn( tmpIFuseConn );
        *iFuseConn = tmpIFuseConn;
    }
    UNLOCK( WaitForConnLock );

    if ( ++ConnManagerStarted == HIGH_NUM_CONN ) {
        /* don't do it the first time */

#ifdef USE_BOOST
        ConnManagerThr = new boost::thread( connManager );
#else
        status = pthread_create( &ConnManagerThr, pthread_attr_default, ( void * ( * )( void * ) ) connManager, ( void * ) NULL );
#endif
        if ( status < 0 ) {
            ConnManagerStarted--;
            rodsLog( LOG_ERROR, "pthread_create failure, status = %d", status );
        }
    }
    return 0;
}
int
waitPreloadJobs () {
    int i;
    int size;

    // destroy preload thread list
    size = listSize(PreloadThreadList);
    for(i=0;i<size;i++) {
        LOCK(PreloadLock);
        preloadThreadInfo_t *threadInfo = (preloadThreadInfo_t *)removeFirstElementOfConcurrentList(PreloadThreadList);
        if(threadInfo != NULL) {
            rodsLog (LOG_DEBUG, "waitPreloadJobs: Waiting for a preload job - %s", threadInfo->path);
            UNLOCK(PreloadLock);
#ifdef USE_BOOST
            threadInfo->thread->join();
#else
            pthread_join(threadInfo->thread, NULL);
#endif
        } else {
            UNLOCK(PreloadLock);
        }
    }
    return 0;
}
示例#5
0
void
connManager() {
    time_t curTime;
    iFuseConn_t *tmpIFuseConn;
    ListNode *node;
    List *TimeOutList = newListNoRegion();

    while ( 1 ) {
        curTime = time( NULL );

        /* exceed high water mark for number of connection ? */
        if ( listSize( ConnectedConn ) > HIGH_NUM_CONN ) {

            LOCK_STRUCT( *ConnectedConn );
            int disconnTarget = _listSize( ConnectedConn ) - HIGH_NUM_CONN;
            node = ConnectedConn->list->head;
            while ( node != NULL ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    listAppendNoRegion( TimeOutList, tmpIFuseConn );

                }
                node = node->next;            
            }
            UNLOCK_STRUCT( *ConnectedConn );

            node = TimeOutList->head;
            int disconned = 0;
            while ( node != NULL && disconned < disconnTarget ) {
                tmpIFuseConn = ( iFuseConn_t * ) node->value;
                LOCK_STRUCT( *tmpIFuseConn );
                if ( tmpIFuseConn->inuseCnt == 0 && tmpIFuseConn->pendingCnt == 0 && curTime - tmpIFuseConn->actTime > IFUSE_CONN_TIMEOUT ) {
                    removeFromConcurrentList2( FreeConn, tmpIFuseConn );
                    removeFromConcurrentList2( ConnectedConn, tmpIFuseConn );
                    if ( tmpIFuseConn->status == 0 ) { /* no struct is referring to it, we can unlock it and free it */
                        UNLOCK_STRUCT( *tmpIFuseConn );
                        /* rodsLog(LOG_ERROR, "[FREE IFUSE CONN] %s:%d %p", __FILE__, __LINE__, tmpIFuseConn); */
                        _freeIFuseConn( tmpIFuseConn );
                    }
                    else {   /* set to timed out */
                        _ifuseDisconnect( tmpIFuseConn );
                        UNLOCK_STRUCT( *tmpIFuseConn );
                    }
                    disconned ++;
                }
                else {
                    UNLOCK_STRUCT( *tmpIFuseConn );
                }
                node = node->next;
            }
            clearListNoRegion( TimeOutList );
        }

        while ( listSize( ConnectedConn ) <= MAX_NUM_CONN || listSize( FreeConn ) != 0 ) {
            /* signal one in the wait queue */
            connReqWait_t *myConnReqWait = ( connReqWait_t * ) removeFirstElementOfConcurrentList( ConnReqWaitQue );
            /* if there is no conn req left, exit loop */
            if ( myConnReqWait == NULL ) {
                break;
            }
            myConnReqWait->state = 1;
            notifyTimeoutWait( &myConnReqWait->mutex, &myConnReqWait->cond );
        }
#if 0
        rodsSleep( CONN_MANAGER_SLEEP_TIME, 0 );
#else
        timeoutWait( &ConnManagerLock, &ConnManagerCond, CONN_MANAGER_SLEEP_TIME );
#endif


    }
    deleteListNoRegion( TimeOutList );
}
示例#6
0
int _getAndUseIFuseConn( iFuseConn_t **iFuseConn ) {
    int status;
    iFuseConn_t *tmpIFuseConn;

    *iFuseConn = NULL;

    while ( *iFuseConn == NULL ) {
        /* get a free IFuseConn */

        if ( listSize( ConnectedConn ) >= MAX_NUM_CONN && listSize( FreeConn ) == 0 ) {
            /* have to wait */
            _waitForConn();
            /* start from begining */
            continue;
        }
        else {
            tmpIFuseConn = ( iFuseConn_t * ) removeFirstElementOfConcurrentList( FreeConn );
            if ( tmpIFuseConn == NULL ) {
                if ( listSize( ConnectedConn ) < MAX_NUM_CONN ) {
                    /* may cause num of conn > max num of conn */
                    /* get here when nothing free. make one */
                    tmpIFuseConn = newIFuseConn( &status );
                    if ( status < 0 ) {
                        _freeIFuseConn( tmpIFuseConn );
                        return status;
                    }

                    _useFreeIFuseConn( tmpIFuseConn );
                    addToConcurrentList( ConnectedConn, tmpIFuseConn );

                    *iFuseConn = tmpIFuseConn;
                    break;

                }
                _waitForConn();
                continue;
            }
            else {
                useIFuseConn( tmpIFuseConn );
                *iFuseConn = tmpIFuseConn;
                break;
            }
        }


    }	/* while *iFuseConn */

    if ( ++ConnManagerStarted == HIGH_NUM_CONN ) {
        /* don't do it the first time */

#ifdef USE_BOOST
        ConnManagerThr = new boost::thread( connManager );
#else
        status = pthread_create( &ConnManagerThr, pthread_attr_default, ( void * ( * )( void * ) ) connManager, ( void * ) NULL );
#endif
        if ( status < 0 ) {
            ConnManagerStarted--;
            rodsLog( LOG_ERROR, "pthread_create failure, status = %d", status );
        }
    }
    return 0;
}