int initDataObjInfoWithInp (dataObjInfo_t *dataObjInfo, dataObjInp_t *dataObjInp) { char *rescName, *dataType, *filePath; keyValPair_t *condInput; condInput = &dataObjInp->condInput; memset (dataObjInfo, 0, sizeof (dataObjInfo_t)); rstrcpy (dataObjInfo->objPath, dataObjInp->objPath, MAX_NAME_LEN); rescName = getValByKey (condInput, RESC_NAME_KW); if (rescName != NULL) { rstrcpy (dataObjInfo->rescName, rescName, LONG_NAME_LEN); } snprintf (dataObjInfo->dataMode, SHORT_STR_LEN, "%d", dataObjInp->createMode); dataType = getValByKey (condInput, DATA_TYPE_KW); if (dataType != NULL) { rstrcpy (dataObjInfo->dataType, dataType, NAME_LEN); } else { rstrcpy (dataObjInfo->dataType, "generic", NAME_LEN); } filePath = getValByKey (condInput, FILE_PATH_KW); if (filePath != NULL) { rstrcpy (dataObjInfo->filePath, filePath, MAX_NAME_LEN); } #ifdef FILESYSTEM_META /* copy over the source file metadata if provided */ copyFilesystemMetadata(condInput, &dataObjInfo->condInput); #endif /* FILESYSTEM_META */ return (0); }
int _rsRegColl (rsComm_t *rsComm, collInp_t *collCreateInp) { #ifdef RODS_CAT int status; collInfo_t collInfo; char *tmpStr; memset (&collInfo, 0, sizeof (collInfo)); rstrcpy (collInfo.collName, collCreateInp->collName, MAX_NAME_LEN); if ((tmpStr = getValByKey (&collCreateInp->condInput, COLLECTION_TYPE_KW)) != NULL) { rstrcpy (collInfo.collType, tmpStr, NAME_LEN); if ((tmpStr = getValByKey (&collCreateInp->condInput, COLLECTION_INFO1_KW)) != NULL) { rstrcpy (collInfo.collInfo1, tmpStr, NAME_LEN); } if ((tmpStr = getValByKey (&collCreateInp->condInput, COLLECTION_INFO2_KW)) != NULL) { rstrcpy (collInfo.collInfo2, tmpStr, NAME_LEN); } } #ifdef FILESYSTEM_META /* if the "collection" keyword has been set, it provides the name of another collection to retrieve directory metadata from (usually during a icp or irsync operation */ tmpStr = getValByKey(&collCreateInp->condInput, COLLECTION_KW); if (tmpStr != NULL) { rsQueryDirectoryMeta(rsComm, tmpStr, &collInfo.condInput); } else { /* otherwise copy over the source directory metadata if provided */ copyFilesystemMetadata(&collCreateInp->condInput, &collInfo.condInput); } #endif /* FILESYSTEM_META */ status = chlRegColl (rsComm, &collInfo); return (status); #else return (SYS_NO_RCAT_SERVER_ERR); #endif }
int l3CreateByObjInfo( rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t *dataObjInfo ) { int l3descInx; int retryCnt = 0; int chkType = 0; // JMC - backport 4774 // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3CreateByObjInfo - failed in get_loc_for_hier_String", ret ) ); return -1; } fileCreateInp_t fileCreateInp; memset( &fileCreateInp, 0, sizeof( fileCreateInp ) ); rstrcpy( fileCreateInp.resc_name_, location.c_str(), MAX_NAME_LEN ); rstrcpy( fileCreateInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileCreateInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN ); rstrcpy( fileCreateInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); fileCreateInp.mode = getFileMode( dataObjInp ); // =-=-=-=-=-=-=- // JMC - backport 4774 chkType = getchkPathPerm( rsComm, dataObjInp, dataObjInfo ); copyFilesystemMetadata( &dataObjInfo->condInput, &fileCreateInp.condInput ); if ( chkType == DISALLOW_PATH_REG ) { clearKeyVal( &fileCreateInp.condInput ); return PATH_REG_NOT_ALLOWED; } else if ( chkType == NO_CHK_PATH_PERM ) { fileCreateInp.otherFlags |= NO_CHK_PERM_FLAG; // JMC - backport 4758 } rstrcpy( fileCreateInp.in_pdmo, dataObjInfo->in_pdmo, MAX_NAME_LEN ); // =-=-=-=-=-=-=- // fileCreateOut_t* create_out = 0; std::string prev_resc_hier = fileCreateInp.resc_hier_; l3descInx = rsFileCreate( rsComm, &fileCreateInp, &create_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, fileCreateInp.resc_hier_, MAX_NAME_LEN ); rstrcpy( dataObjInfo->filePath, create_out->file_name, MAX_NAME_LEN ); /* file already exists ? */ while ( l3descInx <= 2 && retryCnt < 100 && getErrno( l3descInx ) == EEXIST ) { if ( resolveDupFilePath( rsComm, dataObjInfo, dataObjInp ) < 0 ) { break; } rstrcpy( fileCreateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); free( create_out ); l3descInx = rsFileCreate( rsComm, &fileCreateInp, &create_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, fileCreateInp.resc_hier_, MAX_NAME_LEN ); rstrcpy( dataObjInfo->filePath, create_out->file_name, MAX_NAME_LEN ); retryCnt ++; } clearKeyVal( &fileCreateInp.condInput ); return ( l3descInx ); }
int l3FilePutSingleBuf( rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjInpBBuf ) { dataObjInfo_t *dataObjInfo; fileOpenInp_t filePutInp; int bytesWritten; dataObjInp_t *dataObjInp; int retryCnt = 0; int chkType = 0; // JMC - backport 4774 dataObjInfo = L1desc[l1descInx].dataObjInfo; dataObjInp = L1desc[l1descInx].dataObjInp; // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "l3FilePutSingleBuf - failed in get_loc_for_hier_String", ret ) ); return -1; } if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) { subFile_t subFile; memset( &subFile, 0, sizeof( subFile ) ); rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN ); //rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc,NAME_LEN); rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN ); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode( dataObjInp ); subFile.flags = O_WRONLY | dataObjInp->openFlags; if ( ( L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY ) != 0 ) { subFile.flags |= FORCE_FLAG; } bytesWritten = rsSubStructFilePut( rsComm, &subFile, dataObjInpBBuf ); return ( bytesWritten ); } // struct file type >= 0 std::string prev_resc_hier; memset( &filePutInp, 0, sizeof( filePutInp ) ); rstrcpy( filePutInp.resc_name_, dataObjInfo->rescInfo->rescName, MAX_NAME_LEN ); rstrcpy( filePutInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( filePutInp.objPath, dataObjInp->objPath, MAX_NAME_LEN ); if ( ( L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY ) != 0 ) { filePutInp.otherFlags |= FORCE_FLAG; } //rstrcpy (filePutInp.addr.hostAddr, dataObjInfo->rescInfo->rescLoc,NAME_LEN); rstrcpy( filePutInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); filePutInp.mode = getFileMode( dataObjInp ); copyFilesystemMetadata( &dataObjInfo->condInput, &filePutInp.condInput ); filePutInp.flags = O_WRONLY | dataObjInp->openFlags; rstrcpy( filePutInp.in_pdmo, L1desc[l1descInx].in_pdmo, MAX_NAME_LEN ); // =-=-=-=-=-=-=- // JMC - backport 4774 chkType = getchkPathPerm( rsComm, L1desc[l1descInx].dataObjInp, L1desc[l1descInx].dataObjInfo ); if ( chkType == DISALLOW_PATH_REG ) { clearKeyVal( &filePutInp.condInput ); return PATH_REG_NOT_ALLOWED; } else if ( chkType == NO_CHK_PATH_PERM ) { // =-=-=-=-=-=-=- filePutInp.otherFlags |= NO_CHK_PERM_FLAG; // JMC - backport 4758 } filePutOut_t* put_out = 0; prev_resc_hier = filePutInp.resc_hier_; bytesWritten = rsFilePut( rsComm, &filePutInp, dataObjInpBBuf, &put_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, filePutInp.resc_hier_, MAX_NAME_LEN ); if( put_out ) { rstrcpy( dataObjInfo->filePath, put_out->file_name, MAX_NAME_LEN ); free( put_out ); } /* file already exists ? */ while ( bytesWritten < 0 && retryCnt < 10 && ( filePutInp.otherFlags & FORCE_FLAG ) == 0 && getErrno( bytesWritten ) == EEXIST ) { if ( resolveDupFilePath( rsComm, dataObjInfo, dataObjInp ) < 0 ) { break; } rstrcpy( filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); filePutOut_t* put_out = 0; bytesWritten = rsFilePut( rsComm, &filePutInp, dataObjInpBBuf, &put_out ); // update the dataObjInfo with the potential changes made by the resource - hcj rstrcpy( dataObjInfo->rescHier, filePutInp.resc_hier_, MAX_NAME_LEN ); if( put_out ) { rstrcpy( dataObjInfo->filePath, put_out->file_name, MAX_NAME_LEN ); free( put_out ); } retryCnt ++; } // while clearKeyVal( &filePutInp.condInput ); return ( bytesWritten ); } // l3FilePutSingleBuf
int l3FilePutSingleBuf (rsComm_t *rsComm, int l1descInx, bytesBuf_t *dataObjInpBBuf) { dataObjInfo_t *dataObjInfo; int rescTypeInx; fileOpenInp_t filePutInp; int bytesWritten; dataObjInp_t *dataObjInp; int retryCnt = 0; int chkType; dataObjInfo = L1desc[l1descInx].dataObjInfo; dataObjInp = L1desc[l1descInx].dataObjInp; if (getStructFileType (dataObjInfo->specColl) >= 0) { subFile_t subFile; memset (&subFile, 0, sizeof (subFile)); rstrcpy (subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN); rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); subFile.specColl = dataObjInfo->specColl; subFile.mode = getFileMode (dataObjInp); subFile.flags = O_WRONLY | dataObjInp->openFlags; #if 0 if (getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) { #else if ((L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY) != 0) { #endif subFile.flags |= FORCE_FLAG; } bytesWritten = rsSubStructFilePut (rsComm, &subFile, dataObjInpBBuf); return (bytesWritten); } rescTypeInx = dataObjInfo->rescInfo->rescTypeInx; switch (RescTypeDef[rescTypeInx].rescCat) { case FILE_CAT: memset (&filePutInp, 0, sizeof (filePutInp)); #if 0 if (getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) { #else if ((L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY) != 0) { #endif filePutInp.otherFlags |= FORCE_FLAG; } filePutInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (filePutInp.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN); rstrcpy (filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN); filePutInp.mode = getFileMode (dataObjInp); #ifdef FILESYSTEM_META copyFilesystemMetadata(&dataObjInfo->condInput, &filePutInp.condInput); #endif filePutInp.flags = O_WRONLY | dataObjInp->openFlags; chkType = getchkPathPerm (rsComm, L1desc[l1descInx].dataObjInp, L1desc[l1descInx].dataObjInfo); if (chkType == DISALLOW_PATH_REG) { return PATH_REG_NOT_ALLOWED; } else if (chkType == NO_CHK_PATH_PERM) { filePutInp.otherFlags |= NO_CHK_PERM_FLAG; } bytesWritten = rsFilePut (rsComm, &filePutInp, dataObjInpBBuf); /* file already exists ? */ while (bytesWritten < 0 && retryCnt < 10 && (filePutInp.otherFlags & FORCE_FLAG) == 0 && getErrno (bytesWritten) == EEXIST) { if (resolveDupFilePath (rsComm, dataObjInfo, dataObjInp) < 0) { break; } rstrcpy (filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN); bytesWritten = rsFilePut (rsComm, &filePutInp, dataObjInpBBuf); retryCnt ++; } break; default: rodsLog (LOG_NOTICE, "l3Open: rescCat type %d is not recognized", RescTypeDef[rescTypeInx].rescCat); bytesWritten = SYS_INVALID_RESC_TYPE; break; } return (bytesWritten); }
int rsDataObjCopy( rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, transferStat_t **transStat ) { dataObjInp_t *srcDataObjInp, *destDataObjInp; int srcL1descInx, destL1descInx; int status; int existFlag; uint createMode; int remoteFlag; rodsServerHost_t *rodsServerHost; specCollCache_t *specCollCache = NULL; srcDataObjInp = &dataObjCopyInp->srcDataObjInp; destDataObjInp = &dataObjCopyInp->destDataObjInp; resolveLinkedPath( rsComm, srcDataObjInp->objPath, &specCollCache, &srcDataObjInp->condInput ); resolveLinkedPath( rsComm, destDataObjInp->objPath, &specCollCache, &destDataObjInp->condInput ); remoteFlag = getAndConnRemoteZoneForCopy( rsComm, dataObjCopyInp, &rodsServerHost ); if ( remoteFlag < 0 ) { return ( remoteFlag ); } else if ( remoteFlag == REMOTE_HOST ) { status = _rcDataObjCopy( rodsServerHost->conn, dataObjCopyInp, transStat ); return status; } if ( strcmp( srcDataObjInp->objPath, destDataObjInp->objPath ) == 0 ) { rodsLog( LOG_ERROR, "rsDataObjCopy: same src and dest objPath %s not allowed", srcDataObjInp->objPath ); return ( USER_INPUT_PATH_ERR ); } addKeyVal( &srcDataObjInp->condInput, PHYOPEN_BY_SIZE_KW, "" ); srcL1descInx = rsDataObjOpen( rsComm, srcDataObjInp ); if ( srcL1descInx < 0 ) { std::stringstream msg; char* sys_error; char* rods_error = rodsErrorName( srcL1descInx, &sys_error ); msg << __FUNCTION__; msg << " - Failed to open source object: \""; msg << srcDataObjInp->objPath; msg << "\" - "; msg << rods_error << " " << sys_error; irods::log( LOG_ERROR, msg.str() ); return srcL1descInx; } /* have to set L1desc[srcL1descInx].dataSize because open set this to -1 */ destDataObjInp->dataSize = L1desc[srcL1descInx].dataSize = L1desc[srcL1descInx].dataObjInfo->dataSize; createMode = atoi( L1desc[srcL1descInx].dataObjInfo->dataMode ); if ( createMode >= 0100 ) { destDataObjInp->createMode = createMode; } L1desc[srcL1descInx].oprType = COPY_SRC; if ( L1desc[srcL1descInx].l3descInx <= 2 ) { /* dataSingleBuf */ addKeyVal( &destDataObjInp->condInput, NO_OPEN_FLAG_KW, "" ); } /* copy file metadata if the source object has it */ copyFilesystemMetadata( &( L1desc[srcL1descInx].dataObjInfo->condInput ), &destDataObjInp->condInput ); destL1descInx = rsDataObjCreate( rsComm, destDataObjInp ); if ( destL1descInx == CAT_UNKNOWN_COLLECTION ) { /* collection does not exist. make one */ char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN]; splitPathByKey( destDataObjInp->objPath, parColl, child, '/' ); rsMkCollR( rsComm, "/", parColl ); destL1descInx = rsDataObjCreate( rsComm, destDataObjInp ); } if ( destL1descInx < 0 ) { std::stringstream msg; char* sys_error; char* rods_error = rodsErrorName( destL1descInx, &sys_error ); msg << __FUNCTION__; msg << " - Failed to create destination object: \""; msg << destDataObjInp->objPath; msg << "\" - "; msg << rods_error << " " << sys_error; irods::log( LOG_ERROR, msg.str() ); return ( destL1descInx ); } if ( L1desc[destL1descInx].replStatus == NEWLY_CREATED_COPY ) { existFlag = 0; } else { existFlag = 1; } L1desc[destL1descInx].oprType = COPY_DEST; L1desc[destL1descInx].srcL1descInx = srcL1descInx; rstrcpy( L1desc[destL1descInx].dataObjInfo->dataType, L1desc[srcL1descInx].dataObjInfo->dataType, NAME_LEN ); /* set dataSize for verification in _rsDataObjClose */ L1desc[destL1descInx].dataSize = L1desc[srcL1descInx].dataObjInfo->dataSize; status = _rsDataObjCopy( rsComm, destL1descInx, existFlag, transStat ); return ( status ); }