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; }
int moveToPreloadedDir (const char *path, const char *iRODSPath) { int status; char preloadCachePath[MAX_NAME_LEN]; off_t cacheSize; if (path == NULL || iRODSPath == NULL) { rodsLog (LOG_DEBUG, "moveToPreloadedDir: input path or iRODSPath is NULL"); return (SYS_INTERNAL_NULL_INPUT_ERR); } status = _getCachePath(iRODSPath, preloadCachePath); if(status < 0) { rodsLog (LOG_DEBUG, "moveToPreloadedDir: failed to get cache path - %s", path); return status; } // make dir makeParentDirs(preloadCachePath); // move the file status = rename(path, preloadCachePath); if(status < 0) { rodsLog (LOG_DEBUG, "moveToPreloadedDir: rename error : %d", status); return status; } // check whether preload cache exceeds limit if(PreloadConfig.cacheMaxSize > 0) { cacheSize = getFileSizeRecursive(PreloadConfig.cachePath); if(cacheSize > (off_t)PreloadConfig.cacheMaxSize) { // evict? status = _evictOldCache(cacheSize - (off_t)PreloadConfig.cacheMaxSize); if(status < 0) { rodsLog (LOG_DEBUG, "moveToPreloadedDir: failed to evict old cache"); return status; } } } return (0); }
static int _download(const char *path, struct stat *stbufIn) { int status; rcComm_t *conn; rodsPathInp_t rodsPathInp; rErrMsg_t errMsg; char preloadCachePath[MAX_NAME_LEN]; char preloadCacheWorkPath[MAX_NAME_LEN]; // set path for getUtil status = _getCachePath(path, preloadCachePath); if(status < 0) { rodsLog (LOG_DEBUG, "_download: failed to get cache path - %s", path); return status; } status = _getCacheWorkPath(path, preloadCacheWorkPath); if(status < 0) { rodsLog (LOG_DEBUG, "_download: failed to get cache work path - %s", path); return status; } rodsLog (LOG_DEBUG, "_download: download %s to %s", path, preloadCachePath); // set src path memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) ); addSrcInPath( &rodsPathInp, (char*)path ); status = parseRodsPath (&rodsPathInp.srcPath[0], PreloadRodsEnv); if(status < 0) { rodsLog (LOG_DEBUG, "_download: parseRodsPath error : %d", status); return status; } // set dest path rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) ); rstrcpy( rodsPathInp.destPath->inPath, preloadCacheWorkPath, MAX_NAME_LEN ); status = parseLocalPath (rodsPathInp.destPath); if(status < 0) { rodsLog (LOG_DEBUG, "_download: parseLocalPath error : %d", status); return status; } // Connect conn = rcConnect (PreloadRodsEnv->rodsHost, PreloadRodsEnv->rodsPort, PreloadRodsEnv->rodsUserName, PreloadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg); if (conn == NULL) { rodsLog (LOG_DEBUG, "_download: error occurred while connecting to irods"); return -EPIPE; } // Login if (strcmp (PreloadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { status = clientLogin(conn); if (status != 0) { rodsLog (LOG_DEBUG, "_download: ClientLogin error : %d", status); rcDisconnect(conn); return status; } } // make dir makeParentDirs(preloadCachePath); // Preload rodsLog (LOG_DEBUG, "_download: download %s", path); status = getUtil (&conn, PreloadRodsEnv, PreloadRodsArgs, &rodsPathInp); rodsLog (LOG_DEBUG, "_download: complete downloading %s", path); // Disconnect rcDisconnect(conn); if(status < 0) { rodsLog (LOG_DEBUG, "_download: getUtil error : %d", status); return status; } // be careful when using Lock LOCK(PreloadLock); status = _completeDownload(preloadCacheWorkPath, preloadCachePath, stbufIn); if(status < 0) { rodsLog (LOG_DEBUG, "_download: _completeDownload error : %d", status); UNLOCK(PreloadLock); return status; } UNLOCK(PreloadLock); return 0; }