int l3DataPutSingleBuf( rsComm_t* rsComm, dataObjInp_t* dataObjInp, bytesBuf_t* dataObjInpBBuf ) { int bytesWritten; int l1descInx; int status; openedDataObjInp_t dataObjCloseInp; std::string resc_name; /* don't actually physically open the file */ addKeyVal( &dataObjInp->condInput, NO_OPEN_FLAG_KW, "" ); l1descInx = rsDataObjCreate( rsComm, dataObjInp ); if ( l1descInx <= 2 ) { if ( l1descInx >= 0 ) { rodsLog( LOG_ERROR, "l3DataPutSingleBuf: rsDataObjCreate of %s error, status = %d", dataObjInp->objPath, l1descInx ); return SYS_FILE_DESC_OUT_OF_RANGE; } else { return l1descInx; } } bytesWritten = _l3DataPutSingleBuf( rsComm, l1descInx, dataObjInp, dataObjInpBBuf ); memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) ); dataObjCloseInp.l1descInx = l1descInx; L1desc[l1descInx].oprStatus = bytesWritten; L1desc[l1descInx].oprType = PUT_OPR; status = rsDataObjClose( rsComm, &dataObjCloseInp ); if ( status < 0 ) { rodsLog( LOG_DEBUG, "l3DataPutSingleBuf: rsDataObjClose of %d error, status = %d", l1descInx, status ); } if ( bytesWritten >= 0 ) { return status; } return bytesWritten; }
int l3DataPutSingleBuf( rsComm_t* rsComm, dataObjInp_t* dataObjInp, bytesBuf_t* dataObjInpBBuf ) { int bytesWritten; int l1descInx; dataObjInfo_t *myDataObjInfo; char rescGroupName[NAME_LEN]; rescInfo_t *rescInfo = NULL; rescGrpInfo_t *myRescGrpInfo = NULL; rescGrpInfo_t *tmpRescGrpInfo = NULL; rescInfo_t *tmpRescInfo = NULL; int status; openedDataObjInp_t dataObjCloseInp; /* don't actually physically open the file */ addKeyVal( &dataObjInp->condInput, NO_OPEN_FLAG_KW, "" ); l1descInx = rsDataObjCreate( rsComm, dataObjInp ); if ( l1descInx <= 2 ) { if ( l1descInx >= 0 ) { rodsLog( LOG_ERROR, "l3DataPutSingleBuf: rsDataObjCreate of %s error, status = %d", dataObjInp->objPath, l1descInx ); return SYS_FILE_DESC_OUT_OF_RANGE; } else { return l1descInx; } } bytesWritten = _l3DataPutSingleBuf( rsComm, l1descInx, dataObjInp, dataObjInpBBuf ); if ( bytesWritten < 0 ) { myDataObjInfo = L1desc[l1descInx].dataObjInfo; if ( getStructFileType( myDataObjInfo->specColl ) < 0 && strlen( myDataObjInfo->rescGroupName ) > 0 && ( L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY ) == 0 ) { /* getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) == NULL) { */ /* File not in specColl and resc is a resc group and not * overwriting existing data. Save resc info in case the put fail */ rstrcpy( rescGroupName, myDataObjInfo->rescGroupName, NAME_LEN ); rescInfo = myDataObjInfo->rescInfo; } else { rescGroupName[0] = '\0'; rescInfo = NULL; } } memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) ); dataObjCloseInp.l1descInx = l1descInx; L1desc[l1descInx].oprStatus = bytesWritten; status = rsDataObjClose( rsComm, &dataObjCloseInp ); if ( status < 0 ) { rodsLog( LOG_DEBUG, "l3DataPutSingleBuf: rsDataObjClose of %d error, status = %d", l1descInx, status ); } if ( bytesWritten >= 0 ) { return status; } else if ( strlen( rescGroupName ) == 0 ) { return bytesWritten; } /* get here when Put failed. and rescGroupName is a valid resc group. * Try other resc in the resc group */ status = getRescGrpForCreate( rsComm, dataObjInp, &myRescGrpInfo ); if ( status < 0 ) { return bytesWritten; } tmpRescGrpInfo = myRescGrpInfo; while ( tmpRescGrpInfo != NULL ) { tmpRescInfo = tmpRescGrpInfo->rescInfo; if ( rescInfo == tmpRescInfo ) { /* already tried this resc */ tmpRescGrpInfo = tmpRescGrpInfo->next; continue; } l1descInx = _rsDataObjCreateWithRescInfo( rsComm, dataObjInp, tmpRescInfo, myRescGrpInfo->rescGroupName ); if ( l1descInx <= 2 ) { if ( l1descInx >= 0 ) { rodsLog( LOG_ERROR, "l3DataPutSingleBuf:_rsDataObjCreateWithRI %s err,stat = %d", dataObjInp->objPath, l1descInx ); } } else { bytesWritten = _l3DataPutSingleBuf( rsComm, l1descInx, dataObjInp, dataObjInpBBuf ); dataObjCloseInp.l1descInx = l1descInx; L1desc[l1descInx].oprStatus = bytesWritten; status = rsDataObjClose( rsComm, &dataObjCloseInp ); if ( status < 0 ) { rodsLog( LOG_DEBUG, "l3DataPutSingleBuf: rsDataObjClose of %d error, status = %d", l1descInx, status ); } if ( bytesWritten >= 0 ) { bytesWritten = status; break; } } tmpRescGrpInfo = tmpRescGrpInfo->next; } delete myRescGrpInfo->rescInfo; delete myRescGrpInfo; return bytesWritten; }