int _l3Open( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo, int mode, int flags ) { int l3descInx; fileOpenInp_t fileOpenInp; // =-=-=-=-=-=-=- // 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( "l3Open - failed in get_loc_for_hier_string", ret ) ); return -1; } memset( &fileOpenInp, 0, sizeof( fileOpenInp ) ); rstrcpy( fileOpenInp.resc_name_, dataObjInfo->rescName, MAX_NAME_LEN ); rstrcpy( fileOpenInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN ); rstrcpy( fileOpenInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN ); rstrcpy( fileOpenInp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( fileOpenInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); fileOpenInp.mode = mode; fileOpenInp.flags = flags; rstrcpy( fileOpenInp.in_pdmo, dataObjInfo->in_pdmo, MAX_NAME_LEN ); // kv passthru copyKeyVal( &dataObjInfo->condInput, &fileOpenInp.condInput ); l3descInx = rsFileOpen( rsComm, &fileOpenInp ); clearKeyVal( &fileOpenInp.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, 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_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, location.c_str(), NAME_LEN ); rstrcpy( filePutInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN ); filePutInp.mode = getFileMode( dataObjInp ); filePutInp.flags = O_WRONLY | dataObjInp->openFlags; rstrcpy( filePutInp.in_pdmo, L1desc[l1descInx].in_pdmo, MAX_NAME_LEN ); // kv pasthru copyKeyVal( &dataObjInfo->condInput, &filePutInp.condInput ); // =-=-=-=-=-=-=- // 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 _rsDataObjOpenWithObjInfo( rsComm_t *rsComm, dataObjInp_t *dataObjInp, int phyOpenFlag, dataObjInfo_t *dataObjInfo ) { // JMC - backport 4537 int replStatus; int status; int l1descInx; l1descInx = allocL1desc(); if ( l1descInx < 0 ) { return l1descInx; } // kv pasthru copyKeyVal( &dataObjInp->condInput, &dataObjInfo->condInput ); replStatus = dataObjInfo->replStatus | OPEN_EXISTING_COPY; /* the size was set to -1 because we don't know the target size. * For copy and replicate, the calling routine should modify this * dataSize */ fillL1desc( l1descInx, dataObjInp, dataObjInfo, replStatus, -1 ); if ( getValByKey( &dataObjInp->condInput, PURGE_CACHE_KW ) != NULL ) { L1desc[l1descInx].purgeCacheFlag = 1; } if ( phyOpenFlag == DO_NOT_PHYOPEN ) { /* don't actually physically open the file */ status = 0; } else if ( phyOpenFlag == PHYOPEN_BY_SIZE ) { int single_buff_sz; try { single_buff_sz = irods::get_advanced_setting<const int>(irods::CFG_MAX_SIZE_FOR_SINGLE_BUFFER) * 1024 * 1024; } catch ( const irods::exception& e ) { irods::log(e); return e.code(); } /* open for put or get. May do "dataInclude" */ if ( getValByKey( &dataObjInp->condInput, DATA_INCLUDED_KW ) != NULL && dataObjInfo->dataSize <= single_buff_sz ) { status = 0; } else if ( dataObjInfo->dataSize != UNKNOWN_FILE_SZ && dataObjInfo->dataSize <= single_buff_sz ) { status = 0; } else { status = dataOpen( rsComm, l1descInx ); } } else { status = dataOpen( rsComm, l1descInx ); } if ( status < 0 ) { freeL1desc( l1descInx ); return status; } else { return l1descInx; } }
irods::error test_source_replica_for_write_permissions( rsComm_t* _comm, dataObjInfo_t* _data_obj_info ) { if( !_comm || !_data_obj_info ) { return ERROR( SYS_INTERNAL_NULL_INPUT_ERR, "null _data_obj_info or _comm" ); } std::string location; irods::error ret = irods::get_loc_for_hier_string( _data_obj_info->rescHier, location ); if ( !ret.ok() ) { return PASS( ret ); } // test the source hier to determine if we have write access to the data // stored. if not then we cannot unlink that replica and should throw an // error. fileOpenInp_t open_inp; memset( &open_inp, 0, sizeof( open_inp ) ); open_inp.mode = getDefFileMode(); open_inp.flags = O_WRONLY; rstrcpy( open_inp.resc_name_, _data_obj_info->rescName, MAX_NAME_LEN ); rstrcpy( open_inp.resc_hier_, _data_obj_info->rescHier, MAX_NAME_LEN ); rstrcpy( open_inp.objPath, _data_obj_info->objPath, MAX_NAME_LEN ); rstrcpy( open_inp.addr.hostAddr, location.c_str(), NAME_LEN ); rstrcpy( open_inp.fileName, _data_obj_info->filePath, MAX_NAME_LEN ); rstrcpy( open_inp.in_pdmo, _data_obj_info->in_pdmo, MAX_NAME_LEN ); // kv passthru copyKeyVal( &_data_obj_info->condInput, &open_inp.condInput ); int l3_idx = rsFileOpen( _comm, &open_inp ); clearKeyVal( &open_inp.condInput ); if( l3_idx < 0 ) { std::string msg = "unable to open "; msg += _data_obj_info->objPath; msg += " for unlink"; addRErrorMsg( &_comm->rError, SYS_USER_NO_PERMISSION, msg.c_str() ); return ERROR( SYS_USER_NO_PERMISSION, msg ); } fileCloseInp_t close_inp; memset( &close_inp, 0, sizeof( close_inp ) ); close_inp.fileInx = l3_idx; int status = rsFileClose( _comm, &close_inp ); if( status < 0 ) { std::string msg = "failed to close "; msg += _data_obj_info->objPath; return ERROR( status, msg ); } return SUCCESS(); } // test_source_replica_for_write_permissions