int rsDataObjCreate( rsComm_t *rsComm, dataObjInp_t *dataObjInp ) { int l1descInx; int status; rodsObjStat_t *rodsObjStatOut = NULL; int remoteFlag; rodsServerHost_t *rodsServerHost; specCollCache_t *specCollCache = NULL; char *lockType = NULL; // JMC - backport 4604 int lockFd = -1; // JMC - backport 4604 resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache, &dataObjInp->condInput ); remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp, &rodsServerHost, REMOTE_CREATE ); if ( remoteFlag < 0 ) { return ( remoteFlag ); } else if ( remoteFlag == REMOTE_HOST ) { openStat_t *openStat = NULL; addKeyVal( &dataObjInp->condInput, CROSS_ZONE_CREATE_KW, "" ); status = rcDataObjCreateAndStat( rodsServerHost->conn, dataObjInp, &openStat ); /* rm it to avoid confusion */ rmKeyVal( &dataObjInp->condInput, CROSS_ZONE_CREATE_KW ); if ( status < 0 ) { return status; } l1descInx = allocAndSetL1descForZoneOpr( status, dataObjInp, rodsServerHost, openStat ); if ( openStat != NULL ) { free( openStat ); } return ( l1descInx ); } // =-=-=-=-=-=-=- // working on the "home zone", determine if we need to redirect to a different // server in this zone for this operation. if there is a RESC_HIER_STR_KW then // we know that the redirection decision has already been made char* resc_hier = getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW ); if ( NULL == resc_hier ) { std::string hier; irods::error ret = irods::resolve_resource_hierarchy( irods::CREATE_OPERATION, rsComm, dataObjInp, hier ); if ( !ret.ok() ) { std::stringstream msg; msg << "failed in irods::resolve_resource_hierarchy for ["; msg << dataObjInp->objPath << "]"; irods::log( PASSMSG( msg.str(), ret ) ); return ret.code(); } // =-=-=-=-=-=-=- // we resolved the redirect and have a host, set the hier str for subsequent // api calls, etc. addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() ); } // if keyword // =-=-=-=-=-=-=- // JMC - backport 4604 lockType = getValByKey( &dataObjInp->condInput, LOCK_TYPE_KW ); if ( lockType != NULL ) { lockFd = rsDataObjLock( rsComm, dataObjInp ); if ( lockFd >= 0 ) { /* rm it so it won't be done again causing deadlock */ rmKeyVal( &dataObjInp->condInput, LOCK_TYPE_KW ); } else { rodsLogError( LOG_ERROR, lockFd, "rsDataObjCreate: rsDataObjLock error for %s. lockType = %s", dataObjInp->objPath, lockType ); return lockFd; } } // =-=-=-=-=-=-=- // Gets here means local zone operation stat dataObj addKeyVal( &dataObjInp->condInput, SEL_OBJ_TYPE_KW, "dataObj" ); status = rsObjStat( rsComm, dataObjInp, &rodsObjStatOut ); if ( rodsObjStatOut != NULL && rodsObjStatOut->objType == COLL_OBJ_T ) { if ( lockFd >= 0 ) { rsDataObjUnlock( rsComm, dataObjInp, lockFd ); // JMC - backport 4604 } return ( USER_INPUT_PATH_ERR ); } if ( rodsObjStatOut != NULL && rodsObjStatOut->specColl != NULL && rodsObjStatOut->specColl->collClass == LINKED_COLL ) { /* should not be here because if has been translated */ if ( lockFd >= 0 ) { rsDataObjUnlock( rsComm, dataObjInp, lockFd ); // JMC - backport 4604 } return SYS_COLL_LINK_PATH_ERR; } if ( rodsObjStatOut == NULL || ( rodsObjStatOut->objType == UNKNOWN_OBJ_T && rodsObjStatOut->specColl == NULL ) ) { /* does not exist. have to create one */ /* use L1desc[l1descInx].replStatus & OPEN_EXISTING_COPY instead */ /* newly created. take out FORCE_FLAG since it could be used by put */ /* rmKeyVal (&dataObjInp->condInput, FORCE_FLAG_KW); */ l1descInx = _rsDataObjCreate( rsComm, dataObjInp ); } else if ( rodsObjStatOut->specColl != NULL && rodsObjStatOut->objType == UNKNOWN_OBJ_T ) { /* newly created. take out FORCE_FLAG since it could be used by put */ /* rmKeyVal (&dataObjInp->condInput, FORCE_FLAG_KW); */ l1descInx = specCollSubCreate( rsComm, dataObjInp ); } else { /* dataObj exist */ if ( getValByKey( &dataObjInp->condInput, FORCE_FLAG_KW ) != NULL ) { dataObjInp->openFlags |= O_TRUNC | O_RDWR; // =-=-=-=-=-=-=- // re-determine the resource hierarchy since this is an open instead of a create std::string hier; irods::error ret = irods::resolve_resource_hierarchy( irods::WRITE_OPERATION, rsComm, dataObjInp, hier ); if ( !ret.ok() ) { std::stringstream msg; msg << __FUNCTION__; msg << " :: failed in irods::resolve_resource_hierarchy for ["; msg << dataObjInp->objPath << "]"; irods::log( PASSMSG( msg.str(), ret ) ); return ret.code(); } // =-=-=-=-=-=-=- // we resolved the redirect and have a host, set the hier str for subsequent // api calls, etc. addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() ); std::string top_resc; irods::hierarchy_parser parser; parser.set_string( hier ); parser.first_resc( top_resc ); addKeyVal( &dataObjInp->condInput, DEST_RESC_NAME_KW, top_resc.c_str() ); l1descInx = _rsDataObjOpen( rsComm, dataObjInp ); } else { l1descInx = OVERWRITE_WITHOUT_FORCE_FLAG; } } if ( rodsObjStatOut != NULL ) { freeRodsObjStat( rodsObjStatOut ); } // =-=-=-=-=-=-=- // JMC - backport 4604 if ( lockFd >= 0 ) { if ( l1descInx >= 0 ) { L1desc[l1descInx].lockFd = lockFd; } else { rsDataObjUnlock( rsComm, dataObjInp, lockFd ); } } // =-=-=-=-=-=-=- return ( l1descInx ); }
int rsNcCreate( rsComm_t *rsComm, ncOpenInp_t *ncCreateInp, int **ncid ) { int remoteFlag; rodsServerHost_t *rodsServerHost; specCollCache_t *specCollCache = NULL; int status; dataObjInp_t dataObjInp; int l1descInx, myncid; if ( getValByKey( &ncCreateInp->condInput, NATIVE_NETCDF_CALL_KW ) != NULL ) { /* just do nc_open with objPath as file nc file path */ /* must to be called internally */ if ( rsComm->proxyUser.authInfo.authFlag < REMOTE_PRIV_USER_AUTH ) { return( CAT_INSUFFICIENT_PRIVILEGE_LEVEL ); } status = nc_create( ncCreateInp->objPath, ncCreateInp->mode, &myncid ); if ( status == NC_NOERR ) { *ncid = ( int * ) malloc( sizeof( int ) ); *( *ncid ) = myncid; return 0; } else { rodsLog( LOG_ERROR, "rsNccreate: nc_create %s error, status = %d, %s", ncCreateInp->objPath, status, nc_strerror( status ) ); return ( NETCDF_OPEN_ERR + status ); } } bzero( &dataObjInp, sizeof( dataObjInp ) ); rstrcpy( dataObjInp.objPath, ncCreateInp->objPath, MAX_NAME_LEN ); replKeyVal( &ncCreateInp->condInput, &dataObjInp.condInput ); resolveLinkedPath( rsComm, dataObjInp.objPath, &specCollCache, &dataObjInp.condInput ); remoteFlag = getAndConnRemoteZone( rsComm, &dataObjInp, &rodsServerHost, REMOTE_OPEN ); if ( remoteFlag < 0 ) { return ( remoteFlag ); } else if ( remoteFlag == LOCAL_HOST ) { addKeyVal( &dataObjInp.condInput, NO_OPEN_FLAG_KW, "" ); l1descInx = _rsDataObjCreate( rsComm, &dataObjInp ); clearKeyVal( &dataObjInp.condInput ); if ( l1descInx < 0 ) { return l1descInx; } l1desc_t& my_desc = irods::get_l1desc( l1descInx ); remoteFlag = resoAndConnHostByDataObjInfo( rsComm, my_desc.dataObjInfo, &rodsServerHost ); if ( remoteFlag < 0 ) { return ( remoteFlag ); } else if ( remoteFlag == LOCAL_HOST ) { status = nc_create( my_desc.dataObjInfo->filePath, ncCreateInp->mode, &myncid ); if ( status != NC_NOERR ) { rodsLog( LOG_ERROR, "rsNcCreate: nc_open %s error, status = %d, %s", ncCreateInp->objPath, status, nc_strerror( status ) ); freeL1desc( l1descInx ); return ( NETCDF_CREATE_ERR + status ); } } else { /* execute it remotely with dataObjInfo->filePath */ ncOpenInp_t myNcCreateInp; bzero( &myNcCreateInp, sizeof( myNcCreateInp ) ); rstrcpy( myNcCreateInp.objPath, my_desc.dataObjInfo->filePath, MAX_NAME_LEN ); addKeyVal( &myNcCreateInp.condInput, NATIVE_NETCDF_CALL_KW, "" ); status = rcNcCreate( rodsServerHost->conn, &myNcCreateInp, &myncid ); clearKeyVal( &myNcCreateInp.condInput ); if ( status < 0 ) { rodsLog( LOG_ERROR, "rsNcCreate: _rcNcCreate %s error, status = %d", myNcCreateInp.objPath, status ); freeL1desc( l1descInx ); return ( status ); } } my_desc.l3descInx = myncid; /* need to reg here since NO_OPEN_FLAG_KW does not do it */ if ( my_desc.dataObjInfo->specColl == NULL ) { status = svrRegDataObj( rsComm, my_desc.dataObjInfo ); if ( status < 0 ) { ncCloseInp_t myNcCloseInp; bzero( &myNcCloseInp, sizeof( myNcCloseInp ) ); myNcCloseInp.ncid = l1descInx; irods::server_api_call ( NC_CLOSE_AN, rsComm, &myNcCloseInp ); l3Unlink( rsComm, my_desc.dataObjInfo ); rodsLog( LOG_ERROR, "rsNcCreate: svrRegDataObj for %s failed, status = %d", my_desc.dataObjInfo->objPath, status ); freeL1desc( l1descInx ); return ( NETCDF_CREATE_ERR + status ); } } } else { addKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW, "" ); status = rcNcCreate( rodsServerHost->conn, ncCreateInp, &myncid ); /* rm it to avoid confusion */ rmKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW ); if ( status < 0 ) { rodsLog( LOG_ERROR, "rsNcCreate: _rcNcCreate %s error, status = %d", ncCreateInp->objPath, status ); return ( status ); } l1descInx = allocAndSetL1descForZoneOpr( myncid, &dataObjInp, rodsServerHost, NULL ); } l1desc_t& my_desc = irods::get_l1desc( l1descInx ); my_desc.oprType = NC_CREATE; *ncid = ( int * ) malloc( sizeof( int ) ); *( *ncid ) = l1descInx; return 0; }