int irodsTruncate (const char *path, off_t size) { dataObjInp_t dataObjInp; int status; pathCache_t *tmpPathCache; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsTruncate: %s", path); if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { if(tmpPathCache->fileCache != NULL) { LOCK_STRUCT(*tmpPathCache->fileCache); if(tmpPathCache->fileCache->state == HAVE_NEWLY_CREATED_CACHE) { status = truncate (tmpPathCache->fileCache->fileCachePath, size); if (status >= 0) { updatePathCacheStatFromFileCache (tmpPathCache); UNLOCK_STRUCT(*(tmpPathCache->fileCache)); UNLOCK_STRUCT(*tmpPathCache); return (0); } } UNLOCK_STRUCT(*(tmpPathCache->fileCache)); } } UNLOCK_STRUCT(*tmpPathCache); memset (&dataObjInp, 0, sizeof (dataObjInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInp.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsTruncate: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } dataObjInp.dataSize = size; getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcDataObjTruncate (iFuseConn->conn, &dataObjInp)); if (status >= 0) { pathCache_t *tmpPathCache; if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { tmpPathCache->stbuf.st_size = size; } UNLOCK_STRUCT(*tmpPathCache); status = 0; } else { rodsLogError (LOG_ERROR, status, "irodsTruncate: rcDataObjTruncate of %s error", path); status = -ENOENT; } unuseIFuseConn (iFuseConn); return (status); }
/* precond: lock paca */ int _getAndUseConnForPathCache( iFuseConn_t **iFuseConn, pathCache_t *paca ) { int status; /* if connection already closed by connection manager, get new ifuseconn */ if ( paca->iFuseConn != NULL ) { LOCK_STRUCT( *( paca->iFuseConn ) ); if ( paca->iFuseConn->conn != NULL ) { if ( paca->iFuseConn->inuseCnt == 0 ) { _useIFuseConn( paca->iFuseConn ); UNLOCK_STRUCT( *( paca->iFuseConn ) ); /* ifuseReconnect(paca->iFuseConn); */ *iFuseConn = paca->iFuseConn; return 0; } else { UNLOCK_STRUCT( *( paca->iFuseConn ) ); } } else { UNLOCK_STRUCT( *( paca->iFuseConn ) ); /* disconnect by not freed yet */ UNREF( paca->iFuseConn, IFuseConn ); } } iFuseConn_t *tmpIFuseConn; // UNLOCK_STRUCT( *paca ); status = getAndUseIFuseConn( &tmpIFuseConn ); // LOCK_STRUCT( *paca ); if ( status < 0 ) { rodsLog( LOG_ERROR, "ifuseClose: cannot get ifuse connection for %s error, status = %d", paca->localPath, status ); return status; } // if ( paca->iFuseConn != NULL ) { /* has been changed by other threads, or current paca->ifuseconn inuse, * return new ifuseconn without setting paca->ifuseconn */ // *iFuseConn = tmpIFuseConn; //} //else { /* conn in use, cannot be deleted by conn manager * therefore, it is safe to do the following without locking conn */ REF( paca->iFuseConn, tmpIFuseConn ); *iFuseConn = paca->iFuseConn; //} return 0; }
int irodsMkdir (const char *path, mode_t mode) { collInp_t collCreateInp; int status; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsMkdir: %s", path); memset (&collCreateInp, 0, sizeof (collCreateInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, collCreateInp.collName); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsMkdir: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); status = rcCollCreate (iFuseConn->conn, &collCreateInp); if (status < 0) { if (isReadMsgError (status)) { ifuseReconnect (iFuseConn); status = rcCollCreate (iFuseConn->conn, &collCreateInp); } unuseIFuseConn (iFuseConn); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsMkdir: rcCollCreate of %s error", path); return -ENOENT; } #ifdef CACHE_FUSE_PATH } else { struct stat stbuf; uint mytime = time (0); bzero (&stbuf, sizeof (struct stat)); fillDirStat (&stbuf, mytime, mytime, mytime); pathExist ((char *) path, NULL, &stbuf, NULL); #endif unuseIFuseConn (iFuseConn); } return (0); }
int irodsUnlink (const char *path) { dataObjInp_t dataObjInp; int status; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsUnlink: %s", path); memset (&dataObjInp, 0, sizeof (dataObjInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInp.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsUnlink: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } addKeyVal (&dataObjInp.condInput, FORCE_FLAG_KW, ""); getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); status = rcDataObjUnlink (iFuseConn->conn, &dataObjInp); if (status >= 0) { #ifdef CACHE_FUSE_PATH pathNotExist ((char *) path); #endif status = 0; } else { if (isReadMsgError (status)) { ifuseReconnect (iFuseConn); status = rcDataObjUnlink (iFuseConn->conn, &dataObjInp); } if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsUnlink: rcDataObjUnlink of %s error", path); status = -ENOENT; } } unuseIFuseConn (iFuseConn); clearKeyVal (&dataObjInp.condInput); return (status); }
/* getIFuseConnByPath - try to use the same conn as opened desc of the * same path */ iFuseConn_t *getAndUseConnByPath( char *localPath, int *status ) { iFuseConn_t *iFuseConn; /* make sure iFuseConn is not released after getAndLockIFuseDescByPath finishes */ pathCache_t *tmpPathCache = matchPathCache( pctable, localPath ); if ( tmpPathCache ) { LOCK_STRUCT( *tmpPathCache ); *status = _getAndUseConnForPathCache( &iFuseConn, tmpPathCache ); UNLOCK_STRUCT( *tmpPathCache ); } else { /* no match. just assign one */ pathExist( pctable, localPath, NULL, NULL, NULL ); // need to find a way to clean up *status = getAndUseIFuseConn( &iFuseConn ); } return iFuseConn; }
int irodsRmdir (const char *path) { collInp_t collInp; int status; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsRmdir: %s", path); memset (&collInp, 0, sizeof (collInp)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, collInp.collName); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsRmdir: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } addKeyVal (&collInp.condInput, FORCE_FLAG_KW, ""); getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcRmColl (iFuseConn->conn, &collInp, 0)); if (status >= 0) { #ifdef CACHE_FUSE_PATH pathNotExist ((char *) path); #endif status = 0; } else { rodsLogError (LOG_ERROR, status, "irodsRmdir: rcRmColl of %s error", path); status = -ENOENT; } unuseIFuseConn (iFuseConn); clearKeyVal (&collInp.condInput); return (status); }
int irodsChmod (const char *path, mode_t mode) { int status; modDataObjMeta_t modDataObjMetaInp; keyValPair_t regParam; dataObjInfo_t dataObjInfo; char dataMode[SHORT_STR_LEN]; pathCache_t *tmpPathCache; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsChmod: %s", path); matchAndLockPathCache((char *) path, &tmpPathCache); if (tmpPathCache->fileCache != NULL) { LOCK_STRUCT(*tmpPathCache->fileCache); if(tmpPathCache->fileCache->state == HAVE_NEWLY_CREATED_CACHE) { /* has not actually been created yet */ tmpPathCache->fileCache->mode = mode; UNLOCK_STRUCT(*tmpPathCache->fileCache); UNLOCK_STRUCT(*tmpPathCache); return (0); } UNLOCK_STRUCT(*tmpPathCache->fileCache); } UNLOCK_STRUCT(*tmpPathCache); if(tmpPathCache->stbuf.st_nlink != 1) { rodsLog (LOG_NOTICE, "irodsChmod: modification of the mode of non file object is currently not supported", path); return 0; } memset (®Param, 0, sizeof (regParam)); snprintf (dataMode, SHORT_STR_LEN, "%d", mode); addKeyVal (®Param, DATA_MODE_KW, dataMode); addKeyVal (®Param, ALL_KW, ""); memset(&dataObjInfo, 0, sizeof(dataObjInfo)); status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, dataObjInfo.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsChmod: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } modDataObjMetaInp.regParam = ®Param; modDataObjMetaInp.dataObjInfo = &dataObjInfo; getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); RECONNECT_IF_NECESSARY(status, iFuseConn, rcModDataObjMeta(iFuseConn->conn, &modDataObjMetaInp)); if (status >= 0) { #ifdef CACHE_FUSE_PATH pathCache_t *tmpPathCache; if (matchAndLockPathCache ((char *) path, &tmpPathCache) == 1) { tmpPathCache->stbuf.st_mode &= 0xfffffe00; tmpPathCache->stbuf.st_mode |= (mode & 0777); UNLOCK_STRUCT(*tmpPathCache); } #endif status = 0; } else { rodsLogError(LOG_ERROR, status, "irodsChmod: rcModDataObjMeta failure"); status = -ENOENT; } unuseIFuseConn (iFuseConn); clearKeyVal (®Param); return(status); }
int irodsRename (const char *from, const char *to) { dataObjCopyInp_t dataObjRenameInp; int status; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsRename: %s to %s", from, to); /* test rcDataObjRename */ memset (&dataObjRenameInp, 0, sizeof (dataObjRenameInp)); status = parseRodsPathStr ((char *) (from + 1) , &MyRodsEnv, dataObjRenameInp.srcDataObjInp.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsRename: parseRodsPathStr of %s error", from); /* use ENOTDIR for this type of error */ return -ENOTDIR; } status = parseRodsPathStr ((char *) (to + 1) , &MyRodsEnv, dataObjRenameInp.destDataObjInp.objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsRename: parseRodsPathStr of %s error", to); /* use ENOTDIR for this type of error */ return -ENOTDIR; } char *toIrodsPath = strdup(dataObjRenameInp.destDataObjInp.objPath); addKeyVal (&dataObjRenameInp.destDataObjInp.condInput, FORCE_FLAG_KW, ""); dataObjRenameInp.srcDataObjInp.oprType = dataObjRenameInp.destDataObjInp.oprType = RENAME_UNKNOWN_TYPE; getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); /* rodsLog (LOG_ERROR, "irodsRenme: %s -> %s conn: %p", from, to, iFuseConn);*/ status = rcDataObjRename (iFuseConn->conn, &dataObjRenameInp); if (status == CAT_NAME_EXISTS_AS_DATAOBJ || status == SYS_DEST_SPEC_COLL_SUB_EXIST) { rcDataObjUnlink (iFuseConn->conn, &dataObjRenameInp.destDataObjInp); status = rcDataObjRename (iFuseConn->conn, &dataObjRenameInp); } if (status >= 0) { #ifdef CACHE_FUSE_PATH status = renmeLocalPath ((char *) from, (char *) to, (char *) toIrodsPath); #endif } else { if (isReadMsgError (status)) { ifuseReconnect (iFuseConn); status = rcDataObjRename (iFuseConn->conn, &dataObjRenameInp); } if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsRename: rcDataObjRename of %s to %s error", from, to); status = -ENOENT; } } unuseIFuseConn (iFuseConn); free(toIrodsPath); return (status); }
int irodsMknod (const char *path, mode_t mode, dev_t rdev) { pathCache_t *tmpPathCache = NULL; struct stat stbuf; int status = -1; char cachePath[MAX_NAME_LEN]; char objPath[MAX_NAME_LEN]; iFuseConn_t *iFuseConn = NULL; fileCache_t *fileCache = NULL; /* iFuseDesc_t *desc = NULL; */ int localFd; rodsLog (LOG_DEBUG, "irodsMknod: %s", path); if (irodsGetattr (path, &stbuf) >= 0) return -EEXIST; status = irodsMknodWithCache ((char *)path, mode, cachePath); localFd = status; status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, objPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "dataObjCreateByFusePath: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } getAndUseIFuseConn (&iFuseConn, &MyRodsEnv); if (status < 0) { status = dataObjCreateByFusePath (iFuseConn->conn, (char *) path, mode, objPath); if (status < 0) { if (isReadMsgError (status)) { ifuseReconnect (iFuseConn); status = dataObjCreateByFusePath (iFuseConn->conn, (char *) path, mode, objPath); } if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsMknod: rcDataObjCreate of %s error", path); unuseIFuseConn (iFuseConn); return -ENOENT; } } } fileCache = addFileCache(localFd, objPath, (char *) path, cachePath, mode, 0, HAVE_NEWLY_CREATED_CACHE); stbuf.st_mode = mode; pathExist ((char *) path, fileCache, &stbuf, &tmpPathCache); /* desc = newIFuseDesc (objPath, (char *) path, fileCache, &status); */ if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsMknod: allocIFuseDesc of %s error", path); closeIrodsFd (iFuseConn->conn, status); unuseIFuseConn (iFuseConn); return 0; } /* rodsLog (LOG_ERROR, "irodsMknod: %s conn: %p", path, iFuseConn);*/ unuseIFuseConn (iFuseConn); return (0); }