Exemplo n.º 1
0
/* precond: fileCache locked or single thread use */
iFuseDesc_t *newIFuseDesc (char *objPath, char *localPath, fileCache_t *fileCache, int *status) {
	iFuseDesc_t *desc;
	LOCK_STRUCT(*IFuseDescFreeList);
	/*
	printf("******************************************************\n");
	printf("num of desc slots free = %d\n", _listSize(IFuseDescFreeList));
	printf("******************************************************\n"); */
	if(_listSize(IFuseDescFreeList)!=0) {
		ListNode *node = IFuseDescFreeList->list->head;
		desc = (iFuseDesc_t *) node->value;
		listRemoveNoRegion(IFuseDescFreeList->list, node);
		UNLOCK_STRUCT(*IFuseDescFreeList);
        REF_NO_LOCK(desc->fileCache, fileCache);
		desc->objPath = strdup (objPath);
		desc->localPath = strdup (localPath);
        INIT_STRUCT_LOCK(*desc);
        *status = 0;
        return desc;
	} else {
		UNLOCK_STRUCT(*IFuseDescFreeList);
		rodsLog (LOG_ERROR,
		  "allocIFuseDesc: Out of iFuseDesc");
		*status = SYS_OUT_OF_FILE_DESC;

		return NULL;
	}
}
Exemplo n.º 2
0
fl_concurrentList_t *fl_newConcurrentList() {
	fl_List *l = fl_newList();
	fl_concurrentList_t *cl = (fl_concurrentList_t *) malloc(sizeof (fl_concurrentList_t));
	cl->list = l;
	INIT_STRUCT_LOCK(*cl);
	return cl;
}
Exemplo n.º 3
0
concurrentList_t *newConcurrentList() {
	List *l = newListNoRegion();
	concurrentList_t *cl = (concurrentList_t *) malloc(sizeof (concurrentList_t));
	cl->list = l;
	INIT_STRUCT_LOCK(*cl);
	return cl;
}
Exemplo n.º 4
0
fileCache_t *newFileCache(int iFd, char *objPath, char *localPath, char *cacheFilePath, time_t cachedTime, int mode, cacheState_t state) {
	fileCache_t *fileCache = (fileCache_t *) malloc(sizeof(fileCache_t));
	if (fileCache == NULL) return NULL;
	fileCache->fileCachePath = cacheFilePath == NULL?NULL:strdup(cacheFilePath);
    fileCache->localPath = strdup(localPath);
    fileCache->objPath = strdup(objPath);
    fileCache->cachedTime = cachedTime;
    fileCache->mode = mode;
    fileCache->fileSize = 0;
    fileCache->iFd = iFd;
	fileCache->state = state;
	fileCache->status = 0;
    INIT_STRUCT_LOCK(*fileCache);
    return fileCache;
}
Exemplo n.º 5
0
iFuseConn_t *newIFuseConn(int *status) {
    iFuseConn_t *tmpIFuseConn = (iFuseConn_t *) malloc (sizeof (iFuseConn_t));
    if (tmpIFuseConn == NULL) {
        *status = SYS_MALLOC_ERR;
        return NULL;
    }
    bzero (tmpIFuseConn, sizeof (iFuseConn_t));

    INIT_STRUCT_LOCK(*tmpIFuseConn);
    INIT_LOCK(tmpIFuseConn->inuseLock);

    *status = ifuseConnect (tmpIFuseConn, &MyRodsEnv);
	/*rodsLog(LOG_ERROR, "[ NEW IFUSE CONN] %s:%d %p", __FILE__, __LINE__, tmpIFuseConn);*/
    return tmpIFuseConn;

}
int
mknodLazyUploadBufferedFile(const char *path) {
    int status;
    lazyUploadFileInfo_t *lazyUploadFileInfo = NULL;
    char iRODSPath[MAX_NAME_LEN];
    char bufferPath[MAX_NAME_LEN];

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getBufferPath(iRODSPath, bufferPath);
    if(status < 0) {
        rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath);
        return status;
    }

    LOCK(LazyUploadLock);

    // make dir
    makeParentDirs(bufferPath);

    // create an empty file
    rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: create a new Buffered file - %s", iRODSPath);
    int desc = open (bufferPath, O_RDWR|O_CREAT|O_TRUNC, 0755);
    close (desc);

    // add to hash table
    lazyUploadFileInfo = (lazyUploadFileInfo_t *)malloc(sizeof(lazyUploadFileInfo_t));
    lazyUploadFileInfo->path = strdup(iRODSPath);
    lazyUploadFileInfo->accmode = 0; // clear
    lazyUploadFileInfo->localHandle = -1; // clear
    lazyUploadFileInfo->commitCount = 0; // clear
    lazyUploadFileInfo->curLocalOffsetStart = 0; // clear
    lazyUploadFileInfo->curOffset = 0; // clear
    INIT_STRUCT_LOCK((*lazyUploadFileInfo));

    insertIntoHashTable(LazyUploadBufferedFileTable_Created, iRODSPath, lazyUploadFileInfo);

    UNLOCK(LazyUploadLock);

    return status;
}
Exemplo n.º 7
0
/* precond: fileCache locked or single thread use */
pathCache_t *newPathCache (char *inPath, fileCache_t *fileCache, struct stat *stbuf, time_t cachedTime) {
    pathCache_t *tmpPathCache;

    tmpPathCache = (pathCache_t *) malloc (sizeof (pathCache_t));
    if (tmpPathCache == NULL) return NULL;

    tmpPathCache->localPath = strdup (inPath);
    tmpPathCache->cachedTime = cachedTime;
    tmpPathCache->expired = 0;
    REF_NO_LOCK(tmpPathCache->fileCache, fileCache);
    tmpPathCache->iFuseConn = NULL;
	INIT_STRUCT_LOCK(*tmpPathCache);
    if (stbuf != NULL) {
    	tmpPathCache->stbuf = *stbuf;
    } else {
    	bzero(&(tmpPathCache->stbuf), sizeof(struct stat));
    }
    return tmpPathCache;
}
Exemplo n.º 8
0
int
initIFuseDesc ()
{
#ifndef USE_BOOST
    pthread_mutex_init (&PathCacheLock, NULL);
    pthread_mutex_init (&ConnManagerLock, NULL);
    pthread_cond_init (&ConnManagerCond, NULL);
    IFuseDescFreeList = newConcurrentList();
    int i;
    for(i=0;i<MAX_IFUSE_DESC;i++) {
    	INIT_STRUCT_LOCK(IFuseDesc[i]);
    	IFuseDesc[i].index = i;
    	if(i>=3) {
    		addToConcurrentList(IFuseDescFreeList, &IFuseDesc[i]);
    	}
    }
#endif
    // JMC - overwrites objects construction? -  memset (IFuseDesc, 0, sizeof (iFuseDesc_t) * MAX_IFUSE_DESC);
    return (0);
}
Exemplo n.º 9
0
int
openPreloadedFile (const char *path) {
    int status;
    char iRODSPath[MAX_NAME_LEN];
    char preloadCachePath[MAX_NAME_LEN];
    preloadFileHandleInfo_t *preloadFileHandleInfo = NULL;
    int desc;

    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getiRODSPath error.");
        rodsLog (LOG_ERROR, "openPreloadedFile: failed to get iRODS path - %s", path);
        return status;
    }

    status = _getCachePath(iRODSPath, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getCachePath error.");
        rodsLog (LOG_ERROR, "openPreloadedFile: failed to get cache path - %s", path);
        return status;
    }

    LOCK(PreloadLock);

    desc = -1;

    preloadFileHandleInfo = (preloadFileHandleInfo_t *)lookupFromHashTable(PreloadFileHandleTable, iRODSPath);
    if(preloadFileHandleInfo != NULL) {
        // has preload file handle opened
        if(preloadFileHandleInfo->handle > 0) {
            // reuse handle
            desc = preloadFileHandleInfo->handle;
            rodsLog (LOG_DEBUG, "openPreloadedFile: file is already opened - %s", iRODSPath);
        } else {
            // reuse handleinfo
            if(_hasCache(iRODSPath) >= 0) {
                desc = open (preloadCachePath, O_RDONLY);

                if(desc > 0) {
                    preloadFileHandleInfo->handle = desc;
                    rodsLog (LOG_DEBUG, "openPreloadedFile: opens a file handle - %s", iRODSPath);
                }
            }
        }
    } else {
        // if preloaded cache file is not opened
        // open new
        if(_hasCache(iRODSPath) >= 0) {
            desc = open (preloadCachePath, O_RDONLY);
            rodsLog (LOG_DEBUG, "openPreloadedFile: open a preloaded cache path - %s", iRODSPath);

            if(desc > 0) {
                preloadFileHandleInfo = (preloadFileHandleInfo_t *)malloc(sizeof(preloadFileHandleInfo_t));
                preloadFileHandleInfo->path = strdup(iRODSPath);
                preloadFileHandleInfo->handle = desc;
                INIT_STRUCT_LOCK((*preloadFileHandleInfo));

                insertIntoHashTable(PreloadFileHandleTable, iRODSPath, preloadFileHandleInfo);
            }
        }
    }

    UNLOCK(PreloadLock);

    return desc;
}
Exemplo n.º 10
0
int
preloadFile (const char *path, struct stat *stbuf) {
    int status;
    preloadThreadInfo_t *existingThreadInfo = NULL;
    preloadThreadInfo_t *threadInfo = NULL;
    preloadThreadData_t *threadData = NULL;
    char iRODSPath[MAX_NAME_LEN];
    off_t cacheSize;

    // convert input path to iRODSPath
    status = _getiRODSPath(path, iRODSPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "preloadFile: _getiRODSPath error.");
        rodsLog (LOG_ERROR, "preloadFile: failed to get iRODS path - %s", path);
        return status;
    }

    // check the given file is already preloaded or preloading
    LOCK(PreloadLock);

    // check the given file is preloading
    existingThreadInfo = (preloadThreadInfo_t *)lookupFromHashTable(PreloadThreadTable, iRODSPath);
    if(existingThreadInfo != NULL) {
        rodsLog (LOG_DEBUG, "preloadFile: preloading is already running - %s", iRODSPath);
        UNLOCK(PreloadLock);
        return 0;
    }

    if(_hasValidCache(iRODSPath, stbuf) != 0) {
        // invalidate cache - this may fail if cache file does not exists
        // if old cache exists in local, invalidate it
        _invalidateCache(iRODSPath);

        if(stbuf->st_size < PreloadConfig.preloadMinSize) {
            rodsLog (LOG_DEBUG, "preloadFile: given file is smaller than preloadMinSize, canceling preloading - %s", iRODSPath);
            UNLOCK(PreloadLock);
            return (0);
        }

        // check whether preload cache exceeds limit
        if(PreloadConfig.cacheMaxSize > 0) {
            // cache max size is set
            if(stbuf->st_size > (off_t)PreloadConfig.cacheMaxSize) {
                rodsLog (LOG_DEBUG, "preloadFile: given file is bigger than cacheMaxSize, canceling preloading - %s", iRODSPath);
                UNLOCK(PreloadLock);
                return (0);
            }

            cacheSize = getFileSizeRecursive(PreloadConfig.cachePath);
            if((cacheSize + stbuf->st_size) > (off_t)PreloadConfig.cacheMaxSize) {
                // evict?
                status = _evictOldCache((cacheSize + stbuf->st_size) - (off_t)PreloadConfig.cacheMaxSize);
                if(status < 0) {
                    rodsLog (LOG_ERROR, "preloadFile: failed to evict old cache");
                    UNLOCK(PreloadLock);
                    return status;
                }
            }
        }

        // does not have valid cache. now, start a new preloading

        // create a new thread to preload
        threadInfo = (preloadThreadInfo_t *)malloc(sizeof(preloadThreadInfo_t));
        threadInfo->path = strdup(iRODSPath);
        threadInfo->running = PRELOAD_THREAD_RUNNING;
        INIT_STRUCT_LOCK((*threadInfo));

        insertIntoHashTable(PreloadThreadTable, iRODSPath, threadInfo);

        // prepare thread argument
        threadData = (preloadThreadData_t *)malloc(sizeof(preloadThreadData_t));
        threadData->path = strdup(iRODSPath);
        memcpy(&threadData->stbuf, stbuf, sizeof(struct stat));
        threadData->threadInfo = threadInfo;

        rodsLog (LOG_DEBUG, "preloadFile: start preloading - %s", iRODSPath);
#ifdef USE_BOOST
        status = threadInfo->thread = new boost::thread(_preloadThread, (void *)threadData);
#else
        status = pthread_create(&threadInfo->thread, NULL, _preloadThread, (void *)threadData);
#endif
    } else {
        rodsLog (LOG_DEBUG, "preloadFile: given file is already preloaded - %s", iRODSPath);
        status = 0;
    }

    UNLOCK(PreloadLock);
    return status;
}