Beispiel #1
0
int
rsDataGet( rsComm_t *rsComm, dataOprInp_t *dataOprInp,
           portalOprOut_t **portalOprOut ) {
    int status;
    int remoteFlag;
    int l3descInx;
    rodsServerHost_t *rodsServerHost;

    l3descInx = dataOprInp->srcL3descInx;

    if ( getValByKey( &dataOprInp->condInput, EXEC_LOCALLY_KW ) != NULL ) {
        remoteFlag = LOCAL_HOST;
    }
    else {
        rodsServerHost = FileDesc[l3descInx].rodsServerHost;
        if ( rodsServerHost == NULL ) {
            rodsLog( LOG_NOTICE, "rsDataGet: NULL rodsServerHost" );
            return SYS_INTERNAL_NULL_INPUT_ERR;
        }
        remoteFlag = rodsServerHost->localFlag;
    }

    if ( remoteFlag == LOCAL_HOST ) {
        status = _rsDataGet( rsComm, dataOprInp, portalOprOut );
    }
    else {
        addKeyVal( &dataOprInp->condInput, EXEC_LOCALLY_KW, "" );
        status = remoteDataGet( rsComm, dataOprInp, portalOprOut,
                                rodsServerHost );
        clearKeyVal( &dataOprInp->condInput );
    }


    return status;
}
int
dataObjCreateByFusePath( rcComm_t *conn, char *path, int mode,
                         char *irodsPath ) {
    dataObjInp_t dataObjInp;
    int status;

    memset( &dataObjInp, 0, sizeof( dataObjInp ) );
    rstrcpy( dataObjInp.objPath, irodsPath, MAX_NAME_LEN );

    if ( strlen( MyRodsEnv.rodsDefResource ) > 0 ) {
        addKeyVal( &dataObjInp.condInput, RESC_NAME_KW,
                   MyRodsEnv.rodsDefResource );
    }

    addKeyVal( &dataObjInp.condInput, DATA_TYPE_KW, "generic" );
    /* dataObjInp.createMode = DEF_FILE_CREATE_MODE; */
    dataObjInp.createMode = mode;
    dataObjInp.openFlags = O_RDWR;
    dataObjInp.dataSize = -1;

    status = rcDataObjCreate( conn, &dataObjInp );
    clearKeyVal( &dataObjInp.condInput );

    return status;
}
Beispiel #3
0
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;
}
Beispiel #4
0
int irods_reli_putfile ( const char *host, const char *path, const char *local_path )
{
	dataObjInp_t request;
	int result;

	struct irods_server *server = connect_to_host(host);
	if(!server) return -1;

	memset(&request,0,sizeof(request));
	strcpy(request.objPath,path);

	request.numThreads = 0; // server chooses threads
	request.openFlags = O_CREAT|O_WRONLY;

	addKeyVal (&request.condInput, FORCE_FLAG_KW, "");
	addKeyVal (&request.condInput, ALL_KW, "");

	debug(D_IRODS,"rcDataObjPut %s %s %s",host,path,local_path);
	result = rcDataObjPut(server->conn,&request,(char*)local_path);
	debug(D_IRODS,"= %d",result);

	clearKeyVal (&request.condInput);

	if(result<0) {
		errno = irods_reli_errno(result);
		return -1;
	}

	return 0;
}
Beispiel #5
0
            error call(
                plugin_context& _ctx,
                T1              _t1,
                T2              _t2,
                T3              _t3,
                T4              _t4,
                T5              _t5,
                T6              _t6,
                T7              _t7,
                T8              _t8,
                T9              _t9,
                T10             _t10,
                T11             _t11 ) {
                if ( operation_ ) {
                    // =-=-=-=-=-=-=-
                    // get vars from fco
                    keyValPair_t kvp;
                    bzero( &kvp, sizeof( kvp ) );
                    _ctx.fco()->get_re_vars( kvp );

                    // =-=-=-=-=-=-=-
                    // call the pre-rule for this op
                    std::string pre_results;
                    error ret = rule_exec_mgr_->exec_pre_op( _ctx.comm(), kvp, pre_results );
                    if ( !ret.ok() && ret.code() != SYS_RULE_NOT_FOUND ) {
                        return PASS( ret );
                    }

                    // =-=-=-=-=-=-=-
                    // call the actual operation
                    _ctx.rule_results( pre_results );
                    error op_err = ( *operation_ )( _ctx, _t1, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t10, _t11 );

                    // =-=-=-=-=-=-=-
                    // if the op failed, notify the post rule
                    if ( !op_err.ok() ) {
                        _ctx.rule_results( OP_FAILED );
                    }

                    // =-=-=-=-=-=-=-
                    // call the post-rule for this op
                    std::string rule_results =  _ctx.rule_results();
                    rule_exec_mgr_->exec_post_op( _ctx.comm(), kvp, rule_results );

                    // =-=-=-=-=-=-=-
                    // clean up kvp struct
                    clearKeyVal( &kvp );

                    return op_err;

                }
                else {
                    return ERROR( NULL_VALUE_ERR, "null resource operation." );
                }

            } // operator() - T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11
Beispiel #6
0
/**
 * \fn rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray )
 *
 * \brief Execute my rule.
 *
 * \user client
 *
 * \ingroup rules
 *
 * \since 1.0
 *
 *
 * \remark none
 *
 * \note none
*
 * \param[in] conn - A rcComm_t connection handle to the server.
 * \param[in] execMyRuleInp
 * \param[out] outParamArray
 *
 * \return integer
 * \retval 0 on success.
 * \sideeffect none
 * \pre none
 * \post none
 * \sa none
**/
int
rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp,
              msParamArray_t **outParamArray ) {

    int status = procApiRequest( conn, EXEC_MY_RULE_AN, execMyRuleInp, NULL,
                                 ( void ** )outParamArray, NULL );

    while ( status == SYS_SVR_TO_CLI_MSI_REQUEST ) {
        /* it is a server request */
        msParam_t *myParam = NULL, *putParam = NULL;

        if ( ( myParam = putParam = getMsParamByLabel( *outParamArray, CL_PUT_ACTION ) ) ||
                ( myParam = getMsParamByLabel( *outParamArray, CL_GET_ACTION ) ) ) {
            //putParam is non-null if it's a put, null if it's a get
            dataObjInp_t * dataObjInp = ( dataObjInp_t * ) myParam->inOutStruct;
            char * locFilePath;
            char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
            // locFilePath should be the return of getValByKey if it exists,
            // otherwise use the filename from splitPathByKey
            if ( ( locFilePath = getValByKey( &dataObjInp->condInput, LOCAL_PATH_KW ) ) ||
                    ( ( status = splitPathByKey( dataObjInp->objPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) >= 0 &&
                      ( locFilePath = ( char * ) myFile ) ) ) {
                status = putParam ?
                         rcDataObjPut( conn, dataObjInp, locFilePath ) :
                         rcDataObjGet( conn, dataObjInp, locFilePath );
                rcOprComplete( conn, status );
            }
            else {
                rodsLogError( LOG_ERROR, status,
                              "rcExecMyRule: splitPathByKey for %s error",
                              dataObjInp->objPath );
                rcOprComplete( conn, USER_FILE_DOES_NOT_EXIST );
            }
            clearKeyVal( &dataObjInp->condInput );
        }
        else {
            rcOprComplete( conn, SYS_SVR_TO_CLI_MSI_NO_EXIST );
        }
        /* free outParamArray */
        clearMsParamArray( *outParamArray, 1 );
        free( *outParamArray );
        *outParamArray = NULL;

        /* read the reply from the earlier call */

        status = branchReadAndProcApiReply( conn, EXEC_MY_RULE_AN,
                                            ( void ** )outParamArray, NULL );
        if ( status < 0 ) {
            rodsLogError( LOG_DEBUG, status,
                          "rcExecMyRule: readAndProcApiReply failed. status = %d",
                          status );
        }
    }

    return status;
}
Beispiel #7
0
/* resolveDataObjReplStatus - a dirty copy may be deleted leaving no
 * dirty copy. In that case, pick the newest copy and mark it dirty
 */
int
resolveDataObjReplStatus( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp ) {
    int status;
    dataObjInfo_t *dataObjInfoHead = NULL;
    dataObjInfo_t *newestDataObjInfo = NULL;
    dataObjInfo_t *tmpDataObjInfo;

    if ( getValByKey( &dataObjUnlinkInp->condInput, RESC_NAME_KW ) == NULL &&
            getValByKey( &dataObjUnlinkInp->condInput, REPL_NUM_KW ) == NULL ) {
        return 0;
    }
    status = getDataObjInfo( rsComm, dataObjUnlinkInp,
                             &dataObjInfoHead, ACCESS_DELETE_OBJECT, 1 );

    if ( status < 0 ) {
        return status;
    }

    tmpDataObjInfo = dataObjInfoHead;
    while ( tmpDataObjInfo != NULL ) {
        if ( tmpDataObjInfo->replStatus == 0 ) {
            if ( newestDataObjInfo == NULL ) {
                newestDataObjInfo = tmpDataObjInfo;
            }
            else if ( atoi( tmpDataObjInfo->dataModify ) >
                      atoi( newestDataObjInfo->dataModify ) ) {
                newestDataObjInfo = tmpDataObjInfo;
            }
        }
        else {
            newestDataObjInfo = NULL;
            break;
        }
        tmpDataObjInfo = tmpDataObjInfo->next;
    }

    /* modify the repl status */
    if ( newestDataObjInfo != NULL ) {
        keyValPair_t regParam;
        char tmpStr[MAX_NAME_LEN];
        modDataObjMeta_t modDataObjMetaInp;

        memset( &regParam, 0, sizeof( regParam ) );
        memset( &modDataObjMetaInp, 0, sizeof( modDataObjMetaInp ) );
        snprintf( tmpStr, MAX_NAME_LEN, "%d", NEWLY_CREATED_COPY );
        addKeyVal( &regParam, REPL_STATUS_KW, tmpStr );
        modDataObjMetaInp.dataObjInfo = newestDataObjInfo;
        modDataObjMetaInp.regParam = &regParam;

        status = rsModDataObjMeta( rsComm, &modDataObjMetaInp );

        clearKeyVal( &regParam );
    }
    freeAllDataObjInfo( dataObjInfoHead );
    return status;
}
Beispiel #8
0
/**
 * \fn msiPropertiesClear( msParam_t *listParam, ruleExecInfo_t *rei )
 *
 * \brief Clear a property list
 *
 * \module properties
 *
 * \since pre-2.1
 *
 * \author  David R. Nadeau / University of California, San Diego
 * \date     2007
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to clear
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect property list is cleared
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiPropertiesClear( msParam_t *listParam, ruleExecInfo_t *rei )
{
	RE_TEST_MACRO( "    Calling msiPropertiesClear" );

	/* Check parameters */
	if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 )
		return USER_PARAM_TYPE_ERR;

	/* Clear list */
	clearKeyVal( (keyValPair_t*)listParam->inOutStruct );
	return 0;
}
int
_rsNcGetVarsByTypeForObj( rsComm_t *rsComm, ncGetVarInp_t *ncGetVarInp,
                         ncGetVarOut_t **ncGetVarOut ) {
    int remoteFlag;
    rodsServerHost_t *rodsServerHost = NULL;
    int l1descInx;
    ncGetVarInp_t myNcGetVarInp;
    int status = 0;

    l1descInx = ncGetVarInp->ncid;
    l1desc_t& my_desc = irods::get_l1desc( l1descInx );
    if ( my_desc.remoteZoneHost != NULL ) {
        myNcGetVarInp = *ncGetVarInp;
        myNcGetVarInp.ncid = my_desc.remoteL1descInx;

        /* cross zone operation */
        status = rcNcGetVarsByType( my_desc.remoteZoneHost->conn,
                                    &myNcGetVarInp, ncGetVarOut );
    }
    else {
        remoteFlag = resoAndConnHostByDataObjInfo( rsComm,
                     my_desc.dataObjInfo, &rodsServerHost );
        if ( remoteFlag < 0 ) {
            return ( remoteFlag );
        }
        else if ( remoteFlag == LOCAL_HOST ) {
            status = _rsNcGetVarsByType( my_desc.l3descInx,
                                         ncGetVarInp, ncGetVarOut );
            if ( status < 0 ) {
                return status;
            }
        }
        else {
            /* execute it remotely */
            myNcGetVarInp = *ncGetVarInp;
            myNcGetVarInp.ncid = my_desc.l3descInx;
            addKeyVal( &myNcGetVarInp.condInput, NATIVE_NETCDF_CALL_KW, "" );
            status = rcNcGetVarsByType( rodsServerHost->conn, &myNcGetVarInp,
                                        ncGetVarOut );
            clearKeyVal( &myNcGetVarInp.condInput );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsNcGetVarsByType: rcNcGetVarsByType %d for %s error, status = %d",
                         my_desc.l3descInx,
                         my_desc.dataObjInfo->objPath, status );
                return ( status );
            }
        }
    }
    return status;
}
Beispiel #10
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);
}
Beispiel #11
0
    /**
    * \fn msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    * \brief Open a fully qualified group name and get the group id.  nc_inq_grp_full_ncid is called to get the grpncid
    * \module core
    *
    * \since 3.2
    *
    * \author  Mike Wan
    * \date    2012
    *
    * \usage See clients/icommands/test/rules3.0/netcdfTest1.r, netcdfTest2.r and netcdfTest3.r.
    * \param[in] rootNcidParam - An INT_MS_T containing the rootNcid.
    * \param[in] fullGrpNameParam - A STR_MS_T containing the full group name
    * \param[out] outParam - An INT_MS_T containing the group ncid
    *
    **/
    int
    msiNcOpenGroup (msParam_t *rootNcidParam, msParam_t *fullGrpNameParam,
    msParam_t *outParam, ruleExecInfo_t *rei)
    {
        rsComm_t *rsComm;
        ncOpenInp_t ncOpenInp;
        int *grpNcid = NULL;

        RE_TEST_MACRO ("    Calling msiNcOpenGroup")

        if (rei == NULL || rei->rsComm == NULL) {
          rodsLog (LOG_ERROR,
            "msiNcOpenGroup: input rei or rsComm is NULL");
          return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        rsComm = rei->rsComm;

        bzero (&ncOpenInp, sizeof (ncOpenInp));
        if (rootNcidParam == NULL) {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: input rootNcidParam is NULL");
            return (SYS_INTERNAL_NULL_INPUT_ERR);
        }
        ncOpenInp.rootNcid = parseMspForPosInt (rootNcidParam);
        if (strcmp (fullGrpNameParam->type, STR_MS_T) == 0) {
            rstrcpy (ncOpenInp.objPath, (char*)fullGrpNameParam->inOutStruct,
              MAX_NAME_LEN);
        } else {
            rodsLog (LOG_ERROR,
              "msiNcOpenGroup: Unsupported input fullGrpNameParam type %s",
              fullGrpNameParam->type);
            return (USER_PARAM_TYPE_ERR);
        }
        rei->status = irods::server_api_call ( NC_OPEN_GROUP_AN, rsComm, &ncOpenInp, &grpNcid);

        clearKeyVal (&ncOpenInp.condInput);
        if (rei->status >= 0) {
            fillIntInMsParam (outParam, *grpNcid);
            free (grpNcid);
        } else {
          rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
            "msiNcOpenGroup: api call to ncOpenGroup failed for rootNcid %d, status = %d",
            ncOpenInp.rootNcid, rei->status);
        }
        return (rei->status);
    }
Beispiel #12
0
int
filePathRegRepl (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
rescInfo_t *rescInfo)
{
    dataObjInfo_t destDataObjInfo, *dataObjInfoHead = NULL;
    regReplica_t regReplicaInp;
    char *rescGroupName = NULL;
    int status;

    status = getDataObjInfo (rsComm, phyPathRegInp, &dataObjInfoHead,
      ACCESS_READ_OBJECT, 0);

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "filePathRegRepl: getDataObjInfo for %s", phyPathRegInp->objPath);
        return (status);
    }
    status = sortObjInfoForOpen (rsComm, &dataObjInfoHead, NULL, 0);
    if (status < 0) return status;

    destDataObjInfo = *dataObjInfoHead;
    rstrcpy (destDataObjInfo.filePath, filePath, MAX_NAME_LEN);
    destDataObjInfo.rescInfo = rescInfo;
    rstrcpy (destDataObjInfo.rescName, rescInfo->rescName, NAME_LEN);
    if ((rescGroupName = getValByKey (&phyPathRegInp->condInput,
      RESC_GROUP_NAME_KW)) != NULL) {
        rstrcpy (destDataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
    }
    memset (&regReplicaInp, 0, sizeof (regReplicaInp));
    regReplicaInp.srcDataObjInfo = dataObjInfoHead;
    regReplicaInp.destDataObjInfo = &destDataObjInfo;
    if (getValByKey (&phyPathRegInp->condInput, SU_CLIENT_USER_KW) != NULL) {
        addKeyVal (&regReplicaInp.condInput, SU_CLIENT_USER_KW, "");
        addKeyVal (&regReplicaInp.condInput, IRODS_ADMIN_KW, "");
    } else if (getValByKey (&phyPathRegInp->condInput,
      IRODS_ADMIN_KW) != NULL) {
        addKeyVal (&regReplicaInp.condInput, IRODS_ADMIN_KW, "");
    }
    status = rsRegReplica (rsComm, &regReplicaInp);
    clearKeyVal (&regReplicaInp.condInput);
    freeAllDataObjInfo (dataObjInfoHead);

    return status;
}
Beispiel #13
0
int irods_reli_rmdir ( const char *host, const char *path )
{
	collInp_t request;
	int result;
 
        /*
        Note that an irods rmdir will fail silently if you
        attempt to remove a non-directory.  So, first we must
        examine the type and fail explicitly if it is not a dir.
        */

        struct pfs_stat info;

        result = irods_reli_stat(host,path,&info);
        if(result<0) return result;

        if(!S_ISDIR(info.st_mode)) {
                errno = EISDIR;
                return -1;
        }

	struct irods_server *server = connect_to_host(host);
	if(!server) return -1;

	memset(&request,0,sizeof(request));
	strcpy(request.collName,path);

	addKeyVal (&request.condInput, FORCE_FLAG_KW, "");

	debug(D_IRODS,"rcRmColl %s %s",host,path);
	result = rcRmColl(server->conn,&request,0);
	debug(D_IRODS,"= %d",result);

	clearKeyVal (&request.condInput);

	if(result<0) {
		errno = irods_reli_errno(result);
		return -1;
	}

	return result;
}
Beispiel #14
0
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);
}
Beispiel #15
0
int
_rsNcInqIdDataObj( rsComm_t *rsComm, ncInqIdInp_t *ncInqIdInp, int **outId ) {
    int remoteFlag;
    rodsServerHost_t *rodsServerHost = NULL;
    int l1descInx;
    ncInqIdInp_t myNcInqIdInp;
    int status = 0;

    l1descInx = ncInqIdInp->ncid;
    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 = _rsNcInqId( ncInqIdInp->paramType,
                             my_desc.l3descInx, ncInqIdInp->name, outId );
        if ( status < 0 ) {
            return status;
        }
    }
    else {
        /* execute it remotely */
        bzero( &myNcInqIdInp, sizeof( myNcInqIdInp ) );
        myNcInqIdInp.paramType = ncInqIdInp->paramType;
        myNcInqIdInp.ncid = my_desc.l3descInx;
        rstrcpy( myNcInqIdInp.name, ncInqIdInp->name, MAX_NAME_LEN );
        addKeyVal( &myNcInqIdInp.condInput, NATIVE_NETCDF_CALL_KW, "" );
        status = rcNcInqId( rodsServerHost->conn, &myNcInqIdInp, outId );
        clearKeyVal( &myNcInqIdInp.condInput );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "rsNcInqIdDataObj: rcNcInqId %d for %s error, status = %d",
                     my_desc.l3descInx,
                     my_desc.dataObjInfo->objPath, status );
            return ( status );
        }
    }
    return status;
}
int
readAggInfo (rsComm_t *rsComm, char *aggColl, keyValPair_t *condInput,
ncAggInfo_t **ncAggInfo)
{
    int status;
    dataObjInp_t dataObjInp;
    bytesBuf_t packedBBuf;
    portalOprOut_t *portalOprOut = NULL;

    bzero (&dataObjInp, sizeof (dataObjInp));
    bzero (&packedBBuf, sizeof (packedBBuf));
    if (condInput != NULL)
        replKeyVal (condInput, &dataObjInp.condInput);
    snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
      aggColl, NC_AGG_INFO_FILE_NAME);
    dataObjInp.oprType = GET_OPR;
    status = rsDataObjGet (rsComm, &dataObjInp, &portalOprOut, &packedBBuf);
    clearKeyVal (&dataObjInp.condInput);
    if (portalOprOut != NULL) free (portalOprOut);
    if (status < 0) {
        if (status == CAT_NO_ROWS_FOUND) status = NETCDF_AGG_INFO_FILE_ERR;
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: rsDataObjGet error for %s", dataObjInp.objPath);
        return status;
    }
    status = unpackStruct (packedBBuf.buf, (void **) ncAggInfo,
      "NcAggInfo_PI", RodsPackTable, XML_PROT);

    if (status < 0) {
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: unpackStruct error for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    if (*ncAggInfo == NULL || (*ncAggInfo)->numFiles == 0) {
        rodsLog (LOG_ERROR,
          "readAggInfo: No ncAggInfo for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    return status;
}
Beispiel #17
0
int
svrRegDataObj( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo ) {
    int status;
    rodsServerHost_t *rodsServerHost = NULL;

    if ( dataObjInfo->specColl != NULL ) {
        rodsLog( LOG_NOTICE,
                 "svrRegDataObj: Reg path %s is in spec coll",
                 dataObjInfo->objPath );
        return SYS_REG_OBJ_IN_SPEC_COLL;
    }

    status = getAndConnRcatHost( rsComm, MASTER_RCAT, ( const char* )dataObjInfo->objPath,
                                 &rodsServerHost );
    if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
        return status;
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
#ifdef RODS_CAT
        status = _rsRegDataObj( rsComm, dataObjInfo );
#else
        status = SYS_NO_RCAT_SERVER_ERR;
#endif
    }
    else {
        dataObjInfo_t *outDataObjInfo = NULL;
        status = rcRegDataObj( rodsServerHost->conn, dataObjInfo,
                               &outDataObjInfo );
        if ( status >= 0 && NULL != outDataObjInfo ) { // JMC cppcheck - nullptr
            dataObjInfo->dataId = outDataObjInfo->dataId;
            clearKeyVal( &outDataObjInfo->condInput );
            free( outDataObjInfo );
        }
    }

    return status;
}
Beispiel #18
0
int
sendAndProcApiReply( rsComm_t * rsComm, int apiInx, int status,
                     void * myOutStruct, bytesBuf_t * myOutBsBBuf ) {
    int retval;

    retval = sendApiReply( rsComm, apiInx, status, myOutStruct, myOutBsBBuf );

    clearBBuf( myOutBsBBuf );
    if ( myOutStruct != NULL ) {
        free( myOutStruct );
    }
    freeRErrorContent( &rsComm->rError );

    /* check for portal operation */

    if ( rsComm->portalOpr != NULL ) {
        handlePortalOpr( rsComm );
        clearKeyVal( &rsComm->portalOpr->dataOprInp.condInput );
        free( rsComm->portalOpr );
        rsComm->portalOpr = NULL;
    }

    return retval;
}
Beispiel #19
0
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
Beispiel #20
0
int
_rsDataObjPut( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
               bytesBuf_t *dataObjInpBBuf, portalOprOut_t **portalOprOut ) {
    int status;
    int l1descInx;
    int retval;
    openedDataObjInp_t dataObjCloseInp;
    int allFlag;
    transferStat_t *transStat = NULL;
    dataObjInp_t replDataObjInp;

    if ( getValByKey( &dataObjInp->condInput, ALL_KW ) != NULL ) {
        allFlag = 1;
    }
    else {
        allFlag = 0;
    }

    if ( getValByKey( &dataObjInp->condInput, DATA_INCLUDED_KW ) != NULL ) {
        /* single buffer put */
        status = l3DataPutSingleBuf( rsComm, dataObjInp, dataObjInpBBuf );
        if ( status >= 0 && allFlag == 1 ) {
            /* update the rest of copies */
            addKeyVal( &dataObjInp->condInput, UPDATE_REPL_KW, "" );
            status = rsDataObjRepl( rsComm, dataObjInp, &transStat );
            if ( transStat != NULL ) {
                free( transStat );
            }
        }
        if ( status >= 0 ) {
            status = applyRuleForPostProcForWrite(
                    rsComm, dataObjInpBBuf, dataObjInp->objPath );
            if ( status >= 0 ) {
                status = 0;
            }
        }
        return status;
    }

    /* get down here. will do parallel I/O */
    /* so that mmap will work */
    dataObjInp->openFlags |= O_RDWR;
    l1descInx = rsDataObjCreate( rsComm, dataObjInp );

    if ( l1descInx < 0 ) {
        return l1descInx;
    }

    L1desc[l1descInx].oprType = PUT_OPR;
    L1desc[l1descInx].dataSize = dataObjInp->dataSize;

    if ( getStructFileType( L1desc[l1descInx].dataObjInfo->specColl ) >= 0 ) { // JMC - backport 4682
        *portalOprOut = ( portalOprOut_t * ) malloc( sizeof( portalOprOut_t ) );
        bzero( *portalOprOut,  sizeof( portalOprOut_t ) );
        ( *portalOprOut )->l1descInx = l1descInx;
        return l1descInx;
    }


    status = preProcParaPut( rsComm, l1descInx, portalOprOut );

    if ( status < 0 ) {
        memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) );
        dataObjCloseInp.l1descInx = l1descInx;
        L1desc[l1descInx].oprStatus = status;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        return status;
    }

    if ( allFlag == 1 ) {
        /* need to save dataObjInp. get freed in sendAndRecvBranchMsg */
        memset( &replDataObjInp, 0, sizeof( replDataObjInp ) );
        rstrcpy( replDataObjInp.objPath, dataObjInp->objPath, MAX_NAME_LEN );
        addKeyVal( &replDataObjInp.condInput, UPDATE_REPL_KW, "" );
        addKeyVal( &replDataObjInp.condInput, ALL_KW, "" );
    }
    /* return portalOprOut to the client and wait for the rcOprComplete
     * call. That is when the parallel I/O is done */
    retval = sendAndRecvBranchMsg( rsComm, rsComm->apiInx, status,
                                   ( void * ) * portalOprOut, NULL );

    if ( retval < 0 ) {
        memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) );
        dataObjCloseInp.l1descInx = l1descInx;
        L1desc[l1descInx].oprStatus = retval;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        if ( allFlag == 1 ) {
            clearKeyVal( &replDataObjInp.condInput );
        }
    }
    else if ( allFlag == 1 ) {
        status = rsDataObjRepl( rsComm, &replDataObjInp, &transStat );
        if ( transStat != NULL ) {
            free( transStat );
        }
        clearKeyVal( &replDataObjInp.condInput );
    }

    /* already send the client the status */
    return SYS_NO_HANDLER_REPLY_MSG;

}
Beispiel #21
0
int
createPhyBundleDataObj( rsComm_t *rsComm, char *collection,
                        const std::string& _resc_name, const char* rescHier, dataObjInp_t *dataObjInp, // should be able to only use rescHier
                        char* dataType ) { // JMC - backport 4658
    int l1descInx;
    int status;

    /* XXXXXX We do bundle only with UNIX_FILE_TYPE for now */
    if ( _resc_name.empty() ) {
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    std::string type;
    irods::error err = irods::get_resource_property< std::string >(
                           _resc_name,
                           irods::RESOURCE_TYPE,
                           type );
    if ( !err.ok() ) {
        irods::log( PASS( err ) );
    }

    do {
        int loopCnt = 0;
        bzero( dataObjInp, sizeof( dataObjInp_t ) );
        while ( 1 ) {
            status = rsMkBundlePath( rsComm, collection, dataObjInp->objPath,
                                     getRandomInt() );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "createPhyBundleFile: getPhyBundlePath err for %s.stat = %d",
                         collection, status );
                return status;
            }
            /* check if BundlePath already existed */
            if ( isData( rsComm, dataObjInp->objPath, NULL ) >= 0 ) {
                if ( loopCnt >= 100 ) {
                    break;
                }
                else {
                    loopCnt++;
                    continue;
                }
            }
            else {
                break;
            }
        }

        if ( dataType != NULL && strstr( dataType, BUNDLE_STR ) != NULL ) { // JMC - backport 4658
            addKeyVal( &dataObjInp->condInput, DATA_TYPE_KW, dataType );
        }
        else {
            /* assume it is TAR_BUNDLE_DT_STR */
            addKeyVal( &dataObjInp->condInput, DATA_TYPE_KW, TAR_BUNDLE_DT_STR );
        }

        if ( rescHier != NULL ) {
            addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, rescHier );
        }

        if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) { // JMC - backport 4664
            /* zipFile type. must end with .zip */
            int len = strlen( dataObjInp->objPath );
            if ( strcmp( &dataObjInp->objPath[len - 4], ".zip" ) != 0 ) {
                strcat( dataObjInp->objPath, ".zip" );
            }
        }

        l1descInx = _rsDataObjCreateWithResc( rsComm, dataObjInp, _resc_name );

        clearKeyVal( &dataObjInp->condInput );
    }
    while ( l1descInx == OVERWRITE_WITHOUT_FORCE_FLAG );

    if ( l1descInx >= 0 ) {
        l3Close( rsComm, l1descInx );
        L1desc[l1descInx].l3descInx = 0;
        if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) { // JMC - backport 4664
            l3Unlink( rsComm, L1desc[l1descInx].dataObjInfo );
        }
    }

    return l1descInx;
}
Beispiel #22
0
int
bundleAndRegSubFiles( rsComm_t *rsComm, int l1descInx, char *phyBunDir,
                      char *collection, bunReplCacheHeader_t *bunReplCacheHeader, int chksumFlag ) { // JMC - backport 4528
    int status;
    openedDataObjInp_t dataObjCloseInp;
    bunReplCache_t *tmpBunReplCache, *nextBunReplCache;
    regReplica_t regReplicaInp;
    dataObjInp_t dataObjUnlinkInp;
    keyValPair_t regParam; // JMC - backport 4528
    modDataObjMeta_t modDataObjMetaInp; // JMC - backport 4528

    int savedStatus = 0;

    bzero( &dataObjCloseInp, sizeof( dataObjCloseInp ) );
    dataObjCloseInp.l1descInx = l1descInx;
    if ( bunReplCacheHeader->numSubFiles == 0 ) {
        bzero( &dataObjUnlinkInp, sizeof( dataObjUnlinkInp ) );
        rstrcpy( dataObjUnlinkInp.objPath,
                 L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN );
        dataObjUnlinkS( rsComm, &dataObjUnlinkInp,
                        L1desc[l1descInx].dataObjInfo );
        L1desc[l1descInx].bytesWritten = 0;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) );
        return 0;
    }

    status = phyBundle( rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
                        collection, CREATE_TAR_OPR ); // JMC - backport 4643
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "bundleAndRegSubFiles: rsStructFileSync of %s error. stat = %d",
                 L1desc[l1descInx].dataObjInfo->objPath, status );
        rmLinkedFilesInUnixDir( phyBunDir );
        rmdir( phyBunDir );
        rsDataObjClose( rsComm, &dataObjCloseInp );
        tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead;
        while ( tmpBunReplCache != NULL ) {
            nextBunReplCache = tmpBunReplCache->next;
            free( tmpBunReplCache );
            tmpBunReplCache = nextBunReplCache; // JMC - backport 4579
        }
        bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) );
        return status;
    }
    else {
        /* mark it was written so the size would be adjusted */
        L1desc[l1descInx].bytesWritten = 1;
    }

    /* now register a replica for each subfile */
    tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead;

    if ( tmpBunReplCache == NULL ) {
        rmdir( phyBunDir );
        bzero( &dataObjUnlinkInp, sizeof( dataObjUnlinkInp ) );
        rstrcpy( dataObjUnlinkInp.objPath,
                 L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN );
        dataObjUnlinkS( rsComm, &dataObjUnlinkInp,
                        L1desc[l1descInx].dataObjInfo );
        L1desc[l1descInx].bytesWritten = 0;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) );
        return 0;
    }

    bzero( &regReplicaInp, sizeof( regReplicaInp ) );
    regReplicaInp.srcDataObjInfo = ( dataObjInfo_t* )malloc( sizeof( dataObjInfo_t ) );
    regReplicaInp.destDataObjInfo = ( dataObjInfo_t* )malloc( sizeof( dataObjInfo_t ) );
    bzero( regReplicaInp.srcDataObjInfo, sizeof( dataObjInfo_t ) );
    bzero( regReplicaInp.destDataObjInfo, sizeof( dataObjInfo_t ) );
    addKeyVal( &regReplicaInp.condInput, ADMIN_KW, "" );
    rstrcpy( regReplicaInp.destDataObjInfo->rescName, BUNDLE_RESC, NAME_LEN );
    rstrcpy( regReplicaInp.destDataObjInfo->filePath,
             L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN );
    rstrcpy( regReplicaInp.destDataObjInfo->rescHier,
             L1desc[l1descInx].dataObjInfo->rescHier, MAX_NAME_LEN );
    // =-=-=-=-=-=-=-
    // JMC - backport 4528
    if ( chksumFlag != 0 ) {
        bzero( &modDataObjMetaInp, sizeof( modDataObjMetaInp ) );
        bzero( &regParam, sizeof( regParam ) );
        modDataObjMetaInp.dataObjInfo = regReplicaInp.destDataObjInfo;
        modDataObjMetaInp.regParam = &regParam;
    }
    // =-=-=-=-=-=-=-

    /* close here because dataObjInfo is still being used */

    rsDataObjClose( rsComm, &dataObjCloseInp );
    while ( tmpBunReplCache != NULL ) {
        char subPhyPath[MAX_NAME_LEN];

        nextBunReplCache = tmpBunReplCache->next;
        /* rm the hard link here */
        snprintf( subPhyPath, MAX_NAME_LEN, "%s/%lld", phyBunDir,
                  tmpBunReplCache->dataId );
        // =-=-=-=-=-=-=-
        // JMC - backport 4528
        if ( chksumFlag != 0 ) {
            status = fileChksum( rsComm, regReplicaInp.destDataObjInfo->filePath,
                                 subPhyPath, regReplicaInp.destDataObjInfo->rescHier, 0, tmpBunReplCache->chksumStr );
            if ( status < 0 ) {
                savedStatus = status;
                rodsLogError( LOG_ERROR, status, "bundleAndRegSubFiles: fileChksum error for %s", tmpBunReplCache->objPath );
            }
        }
        // =-=-=-=-=-=-=-
        unlink( subPhyPath );
        /* register the replica */
        rstrcpy( regReplicaInp.srcDataObjInfo->objPath,
                 tmpBunReplCache->objPath, MAX_NAME_LEN );
        regReplicaInp.srcDataObjInfo->dataId =
            regReplicaInp.destDataObjInfo->dataId =
                tmpBunReplCache->dataId;
        regReplicaInp.srcDataObjInfo->replNum = tmpBunReplCache->srcReplNum;
        status = rsRegReplica( rsComm, &regReplicaInp );
        if ( status < 0 ) {
            savedStatus = status;
            rodsLog( LOG_ERROR,
                     "bundleAndRegSubFiles: rsRegReplica error for %s. stat = %d",
                     tmpBunReplCache->objPath, status );
        }
        // =-=-=-=-=-=-=-
        // JMC - backport 4528
        if ( chksumFlag != 0 ) {
            addKeyVal( &regParam, CHKSUM_KW, tmpBunReplCache->chksumStr );
            // avoid triggering file operations
            addKeyVal( &regParam, IN_PDMO_KW, "" );
            status = rsModDataObjMeta( rsComm, &modDataObjMetaInp );
            clearKeyVal( &regParam );
            if ( status < 0 ) {
                savedStatus = status;
                rodsLogError( LOG_ERROR, status, "bundleAndRegSubFiles: rsModDataObjMeta error for %s.", tmpBunReplCache->objPath );
            }
        }
        // =-=-=-=-=-=-=-
        free( tmpBunReplCache );
        tmpBunReplCache = nextBunReplCache;
    }
    clearKeyVal( &regReplicaInp.condInput );
    free( regReplicaInp.srcDataObjInfo );
    free( regReplicaInp.destDataObjInfo );
    bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) );
    rmdir( phyBunDir );

    if ( status >= 0 && savedStatus < 0 ) {
        return savedStatus;
    }
    else {
        return status;
    }
}
Beispiel #23
0
int
_rsPhyBundleColl( rsComm_t*                 rsComm,
                  structFileExtAndRegInp_t* phyBundleCollInp,
                  const char *_resc_name ) {

    collInp_t collInp;
    bzero( &collInp, sizeof( collInp ) );
    rstrcpy( collInp.collName, phyBundleCollInp->collection, MAX_NAME_LEN );
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG;

    char* srcRescName = getValByKey( &phyBundleCollInp->condInput, RESC_NAME_KW );
    if ( srcRescName != NULL ) {
        collInp.flags |= INCLUDE_CONDINPUT_IN_QUERY;
        addKeyVal( &collInp.condInput, RESC_NAME_KW, srcRescName );
    }

    int handleInx = rsOpenCollection( rsComm, &collInp );

    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "_rsPhyBundleColl: rsOpenCollection of %s error. status = %d",
                 collInp.collName, handleInx );
        return handleInx;
    }

    if ( CollHandle[handleInx].rodsObjStat->specColl != NULL ) {
        rodsLog( LOG_ERROR,
                 "_rsPhyBundleColl: unable to bundle special collection %s",
                 collInp.collName );
        rsCloseCollection( rsComm, &handleInx );
        return 0;
    }

    /* create the bundle file */
    char* dataType  = getValByKey( &phyBundleCollInp->condInput, DATA_TYPE_KW ); // JMC - backport 4658
    char* rescHier = getValByKey( &phyBundleCollInp->condInput, RESC_HIER_STR_KW );
    dataObjInp_t dataObjInp;
    int   l1descInx = createPhyBundleDataObj( rsComm, phyBundleCollInp->collection,
                      _resc_name, rescHier, &dataObjInp, dataType ); // JMC - backport 4658

    if ( l1descInx < 0 ) {
        return l1descInx;
    }

    // =-=-=-=-=-=-=-
    // JMC - backport 4528
    int chksumFlag    = -1;
    if ( getValByKey( &phyBundleCollInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) {
        L1desc[l1descInx].chksumFlag = VERIFY_CHKSUM;
        chksumFlag = 1;
    }
    else {
        chksumFlag = 0;
    }
    // =-=-=-=-=-=-=-
    // JMC - backport 4771
    int maxSubFileCnt = -1; // JMC - backport 4528, 4771
    if ( getValByKey( &phyBundleCollInp->condInput, MAX_SUB_FILE_KW ) != NULL ) {
        maxSubFileCnt = atoi( getValByKey( &phyBundleCollInp->condInput, MAX_SUB_FILE_KW ) );
    }
    else {
        maxSubFileCnt = MAX_SUB_FILE_CNT;
    }

    rodsLong_t maxBunSize;
    if ( getValByKey( &phyBundleCollInp->condInput, MAX_BUNDLE_SIZE_KW ) != NULL ) {
        maxBunSize = atoi( getValByKey( &phyBundleCollInp->condInput, MAX_BUNDLE_SIZE_KW ) ) * OneGig;
    }
    else {
        maxBunSize = MAX_BUNDLE_SIZE * OneGig;
    }

    // =-=-=-=-=-=-=-
    char phyBunDir[MAX_NAME_LEN];
    createPhyBundleDir( rsComm, L1desc[l1descInx].dataObjInfo->filePath,
                        phyBunDir, L1desc[l1descInx].dataObjInfo->rescHier );

    curSubFileCond_t     curSubFileCond;
    bunReplCacheHeader_t bunReplCacheHeader;
    bzero( &bunReplCacheHeader, sizeof( bunReplCacheHeader ) );
    bzero( &curSubFileCond, sizeof( curSubFileCond ) );

    int        status      = -1;
    int        savedStatus =  0;
    collEnt_t* collEnt     =  NULL;
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( collEnt->objType == DATA_OBJ_T ) {
            if ( curSubFileCond.collName[0] == '\0' ) {
                /* a new dataObj.  */
                rstrcpy( curSubFileCond.collName, collEnt->collName,
                         MAX_NAME_LEN );
                rstrcpy( curSubFileCond.dataName, collEnt->dataName,
                         MAX_NAME_LEN );
                curSubFileCond.dataId = strtoll( collEnt->dataId, 0, 0 );
            }
            else if ( strcmp( curSubFileCond.collName, collEnt->collName ) != 0
                      || strcmp( curSubFileCond.dataName, collEnt->dataName ) != 0 ) {
                /* a new file, need to handle the old one */
                if ( bunReplCacheHeader.numSubFiles >= maxSubFileCnt || // JMC - backport 4771
                        bunReplCacheHeader.totSubFileSize + collEnt->dataSize > maxBunSize ) {
                    /* bundle is full */
                    status = bundleAndRegSubFiles( rsComm, l1descInx,
                                                   phyBunDir, phyBundleCollInp->collection,
                                                   &bunReplCacheHeader, chksumFlag ); // JMC - backport 4528
                    if ( status < 0 ) {
                        rodsLog( LOG_ERROR,
                                 "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stst=%d",
                                 phyBundleCollInp->collection, status );
                        savedStatus = status;
                    }
                    else {
                        /* create a new bundle file */
                        l1descInx = createPhyBundleDataObj( rsComm,
                                                            phyBundleCollInp->collection, _resc_name,
                                                            rescHier, &dataObjInp, dataType ); // JMC - backport 4658

                        if ( l1descInx < 0 ) {
                            rodsLog( LOG_ERROR,
                                     "_rsPhyBundleColl:createPhyBundleDataObj err for %s,stat=%d",
                                     phyBundleCollInp->collection, l1descInx );
                            freeCollEnt( collEnt );
                            return l1descInx;
                        }

                        createPhyBundleDir( rsComm,
                                            L1desc[l1descInx].dataObjInfo->filePath, phyBunDir, L1desc[l1descInx].dataObjInfo->rescHier );
                        /* need to reset subPhyPath since phyBunDir has
                         * changed */
                        /* At this point subPhyPath[0] == 0 if it has gone
                         * through replAndAddSubFileToDir below. != 0 if it has
                         * not and already a good cache copy */
                        if ( curSubFileCond.subPhyPath[0] != '\0' )
                            setSubPhyPath( phyBunDir, curSubFileCond.dataId,
                                           curSubFileCond.subPhyPath );

                    }
                }       /* end of new bundle file */
                status = replAndAddSubFileToDir( rsComm, &curSubFileCond, _resc_name, phyBunDir, &bunReplCacheHeader );
                if ( status < 0 ) {
                    savedStatus = status;
                    rodsLog( LOG_ERROR,
                             "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,sta=%d",
                             curSubFileCond.subPhyPath, status );
                }
                curSubFileCond.bundled = 0;
                curSubFileCond.subPhyPath[0] =
                    curSubFileCond.cachePhyPath[0] = '\0';
                rstrcpy( curSubFileCond.collName, collEnt->collName,
                         MAX_NAME_LEN );
                rstrcpy( curSubFileCond.dataName, collEnt->dataName,
                         MAX_NAME_LEN );
                curSubFileCond.dataId = strtoll( collEnt->dataId, 0, 0 );
            }   /* end of  name compare */

            if ( curSubFileCond.bundled > 0 ) {
                /* already bundled. skip */
            }
            else if ( isDataObjBundled( collEnt ) ) {
                /* already bundled, skip */
                curSubFileCond.bundled = 1;
                curSubFileCond.subPhyPath[0] = '\0';
                curSubFileCond.cachePhyPath[0] = '\0';
                /* XXXX there was a bug that if dataSize == 0, replStatus is 0.
                 * This bug has been fixed since 3.1 */
            }
            else if ( ( collEnt->replStatus > 0 || curSubFileCond.subPhyPath[0] == '\0' ) &&  // JMC - backport 4755
                      strcmp( collEnt->resource, _resc_name ) == 0 ) {
                /* have a good copy in cache resource */
                setSubPhyPath( phyBunDir, curSubFileCond.dataId, curSubFileCond.subPhyPath );
                rstrcpy( curSubFileCond.cachePhyPath, collEnt->phyPath, MAX_NAME_LEN );
                curSubFileCond.cacheReplNum = collEnt->replNum;
                curSubFileCond.subFileSize = collEnt->dataSize;
            }

        } // if data obj

        free( collEnt );    /* just free collEnt but not content */

    } // while
    /* handle any remaining */

    status = replAndAddSubFileToDir( rsComm, &curSubFileCond,
                                     _resc_name, phyBunDir, &bunReplCacheHeader );
    if ( status < 0 ) {
        savedStatus = status;
        rodsLog( LOG_ERROR,
                 "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,stat=%d",
                 curSubFileCond.subPhyPath, status );
    }

    status = bundleAndRegSubFiles( rsComm, l1descInx, phyBunDir,
                                   phyBundleCollInp->collection, &bunReplCacheHeader, chksumFlag ); // JMC - backport 4528
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stat=%d",
                 phyBundleCollInp->collection, status );
    }

    clearKeyVal( &collInp.condInput );
    rsCloseCollection( rsComm, &handleInx );

    if ( status >= 0 && savedStatus < 0 ) {
        return savedStatus;
    }
    else {
        return status;
    }
}
Beispiel #24
0
/* createEmptyRepl - Physically create a zero length file and register
 * as a replica and queue the dataObjInfo on the top of dataObjInfoHead.
 */
int
createEmptyRepl( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
                 dataObjInfo_t **dataObjInfoHead ) {
    int status;
    regReplica_t regReplicaInp;
    keyValPair_t *condInput = &dataObjInp->condInput;
    dataObjInfo_t *myDataObjInfo;

    std::string resc_name;

    if ( getValByKey( condInput, DEST_RESC_NAME_KW ) == NULL &&
            getValByKey( condInput, BACKUP_RESC_NAME_KW ) == NULL &&
            getValByKey( condInput, DEF_RESC_NAME_KW ) == NULL ) {
        return USER_NO_RESC_INPUT_ERR;
    }

    status = getRescForCreate( rsComm, dataObjInp, resc_name );
    if ( status < 0 || resc_name.empty() ) {
        return status;    // JMC cppcheck
    }

    myDataObjInfo = ( dataObjInfo_t* )malloc( sizeof( dataObjInfo_t ) );
    *myDataObjInfo = *( *dataObjInfoHead );

    rstrcpy( myDataObjInfo->rescName, ( *dataObjInfoHead )->rescName, NAME_LEN );

    char* resc_hier = getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW );
    if ( resc_hier ) {
        rstrcpy( myDataObjInfo->rescHier, resc_hier, MAX_NAME_LEN ); // hier sent from upper level code
    }
    else {
        rodsLog( LOG_NOTICE, "createEmptyRepl :: using rescName for hier" );
        rstrcpy( myDataObjInfo->rescHier, ( *dataObjInfoHead )->rescName, MAX_NAME_LEN ); // in kw else
    }

    rodsLong_t resc_id;
    irods::error ret = resc_mgr.hier_to_leaf_id( myDataObjInfo->rescHier, resc_id );
    myDataObjInfo->rescId = resc_id;

    status = getFilePathName( rsComm, myDataObjInfo, dataObjInp );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "getFilePathName failed in %s with status %d", __FUNCTION__, status );
        return status;
    }

    status = l3CreateByObjInfo( rsComm, dataObjInp, myDataObjInfo );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "l3CreateByObjInfo failed in %s with status %d", __FUNCTION__, status );
        return status;
    }

    /* close it */
    _l3Close( rsComm, status );

    /* register the replica */
    memset( &regReplicaInp, 0, sizeof( regReplicaInp ) );
    regReplicaInp.srcDataObjInfo = *dataObjInfoHead;
    regReplicaInp.destDataObjInfo = myDataObjInfo;
    if ( getValByKey( &dataObjInp->condInput, ADMIN_KW ) != NULL ) {
        addKeyVal( &regReplicaInp.condInput, ADMIN_KW, "" );
    }
    status = rsRegReplica( rsComm, &regReplicaInp );
    clearKeyVal( &regReplicaInp.condInput );


    if ( status < 0 ) {
        free( myDataObjInfo );
    }
    else {
        /* queue it on top */
        myDataObjInfo->next = *dataObjInfoHead;
        *dataObjInfoHead = myDataObjInfo;
    }
    return status;
}
Beispiel #25
0
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 = NULL;
        const 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() );
        free( sys_error );
        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, "" );
    }

    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, MAX_NAME_LEN, child, MAX_NAME_LEN, '/' );
        rsMkCollR( rsComm, "/", parColl );
        destL1descInx = rsDataObjCreate( rsComm, destDataObjInp );
    }

    if ( destL1descInx < 0 ) {
        clearKeyVal( &destDataObjInp->condInput );
        std::stringstream msg;
        char* sys_error = NULL;
        const 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() );
        free( sys_error );
        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 );

    clearKeyVal( &destDataObjInp->condInput );

    return status;
}
Beispiel #26
0
    int
    rsNcGetAggInfo( rsComm_t *rsComm, ncOpenInp_t *ncOpenInp,
                    ncAggInfo_t **ncAggInfo ) {
        specCollCache_t *specCollCache = NULL;
        collInp_t collInp;
        int handleInx;
        collEnt_t *collEnt;
        int status = 0;
        int status2 = 0;
        int savedStatus = 0;
        ncOpenInp_t childNcOpenInp;
        ncAggElement_t *ncAggElement = NULL;
        bytesBuf_t *packedBBuf = NULL;

        bzero( &collInp, sizeof( collInp ) );
        rstrcpy( collInp.collName, ncOpenInp->objPath, MAX_NAME_LEN );
        resolveLinkedPath( rsComm, collInp.collName, &specCollCache,
                           &ncOpenInp->condInput );
        collInp.flags = VERY_LONG_METADATA_FG;
        handleInx = irods::server_api_call ( OPEN_COLLECTION_AN, rsComm, &collInp );
        if ( handleInx < 0 ) {
            rodsLog( LOG_ERROR,
                     "rsNcGetAggInfo: rsOpenCollection of %s error. status = %d",
                     collInp.collName, handleInx );
            return ( handleInx );
        }
        bzero( &childNcOpenInp, sizeof( childNcOpenInp ) );
        *ncAggInfo = ( ncAggInfo_t * ) calloc( 1, sizeof( ncAggInfo_t ) );
        rstrcpy( ( *ncAggInfo )->ncObjectName, ncOpenInp->objPath, MAX_NAME_LEN );
        while ( ( status2 = irods::server_api_call ( READ_COLLECTION_AN, rsComm, &handleInx, &collEnt ) ) >= 0 ) {
            if ( collEnt->objType != DATA_OBJ_T ) {
                free( collEnt );
                continue;
            }
            else if ( strcmp( collEnt->dataType, "netcdf" ) != 0 ) {
                if ( strcmp( collEnt->dataName, NC_AGG_INFO_FILE_NAME ) != 0 ) {
                    rodsLog( LOG_NOTICE,
                             "rsNcGetAggInfo: dataType of %s in %s is not 'netcdf' type",
                             collEnt->dataName, collInp.collName );
                    savedStatus = NETCDF_INVALID_DATA_TYPE;
                }
                free( collEnt );
                continue;
            }
            snprintf( childNcOpenInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, collEnt->dataName );
            status = irods::server_api_call ( NC_GET_AGG_ELEMENT_AN, rsComm, &childNcOpenInp, &ncAggElement );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsNcGetAggElement of %s error.",
                              childNcOpenInp.objPath );
                free( collEnt );
                break;
            }
            else {
                status = addNcAggElement( ncAggElement, *ncAggInfo );
                free( ncAggElement );
                if ( status < 0 ) {
                    free( collEnt );
                    break;
                }
            }
            free( collEnt );
        }
        irods::server_api_call ( CLOSE_COLLECTION_AN, rsComm, &handleInx );
        if ( status2 < 0 && status2 != CAT_NO_ROWS_FOUND && status >= 0 ) {
            status = status2;
        }
        if ( status >= 0 && ( ncOpenInp->mode & NC_WRITE ) != 0 ) {
            dataObjInp_t dataObjInp;
            portalOprOut_t *portalOprOut = NULL;
            status = packStruct( ( void * ) * ncAggInfo, &packedBBuf, "NcAggInfo_PI",
                                 RodsPackTable, 0, XML_PROT );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: packStruct error for %s",
                              childNcOpenInp.objPath );
                return status;
            }
            /* write it */
            bzero( &dataObjInp, sizeof( dataObjInp ) );
            replKeyVal( &ncOpenInp->condInput, &dataObjInp.condInput );
            snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, NC_AGG_INFO_FILE_NAME );
            dataObjInp.dataSize = packedBBuf->len;
            dataObjInp.oprType = PUT_OPR;
            addKeyVal( &dataObjInp.condInput, DATA_INCLUDED_KW, "" );
            addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
            status = irods::server_api_call ( DATA_OBJ_PUT_AN, rsComm, &dataObjInp, packedBBuf, &portalOprOut );
            clearBBuf( packedBBuf );
            clearKeyVal( &dataObjInp.condInput );
            if ( portalOprOut != NULL ) {
                free( portalOprOut );
            }
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsDataObjPut error for %s", dataObjInp.objPath );
            }
        }
        if ( status < 0 ) {
            return status;
        }
        else {
            return savedStatus;
        }
    }
int
rsNcGetVarsByType (rsComm_t *rsComm, ncGetVarInp_t *ncGetVarInp,
ncGetVarOut_t **ncGetVarOut)
{
    int remoteFlag;
    rodsServerHost_t *rodsServerHost = NULL;
    int l1descInx;
    ncGetVarInp_t myNcGetVarInp;
    int status = 0;

    if (getValByKey (&ncGetVarInp->condInput, NATIVE_NETCDF_CALL_KW) != 
      NULL) {
	/* just do nc_inq_YYYY */
	status = _rsNcGetVarsByType (ncGetVarInp->ncid, ncGetVarInp,
	  ncGetVarOut);
        return status;
    }
    l1descInx = ncGetVarInp->ncid;
    if (l1descInx < 2 || l1descInx >= NUM_L1_DESC) {
        rodsLog (LOG_ERROR,
          "rsNcGetVarsByType: l1descInx %d out of range",
          l1descInx);
        return (SYS_FILE_DESC_OUT_OF_RANGE);
    }
    if (L1desc[l1descInx].inuseFlag != FD_INUSE) return BAD_INPUT_DESC_INDEX;
    if (L1desc[l1descInx].remoteZoneHost != NULL) {
	myNcGetVarInp = *ncGetVarInp;
	myNcGetVarInp.ncid = L1desc[l1descInx].remoteL1descInx;

        /* cross zone operation */
	status = rcNcGetVarsByType (L1desc[l1descInx].remoteZoneHost->conn,
	  &myNcGetVarInp, ncGetVarOut);
    } else {
        remoteFlag = resoAndConnHostByDataObjInfo (rsComm,
	  L1desc[l1descInx].dataObjInfo, &rodsServerHost);
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else if (remoteFlag == LOCAL_HOST) {
	    status = _rsNcGetVarsByType (L1desc[l1descInx].l3descInx,  
	      ncGetVarInp, ncGetVarOut);
            if (status < 0) {
                return status;
            }
        } else {
	    /* execute it remotely */
	    myNcGetVarInp = *ncGetVarInp;
	    myNcGetVarInp.ncid = L1desc[l1descInx].l3descInx;
	    addKeyVal (&myNcGetVarInp.condInput, NATIVE_NETCDF_CALL_KW, "");
            status = rcNcGetVarsByType (rodsServerHost->conn, &myNcGetVarInp, 
	      ncGetVarOut);
	    clearKeyVal (&myNcGetVarInp.condInput);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "rsNcGetVarsByType: rcNcGetVarsByType %d for %s error, status = %d",
                  L1desc[l1descInx].l3descInx,
                  L1desc[l1descInx].dataObjInfo->objPath, status);
                return (status);
            }
	}
    }
    return status;
}
Beispiel #28
0
int _rsStructFileBundle( rsComm_t*                 rsComm,
                         structFileExtAndRegInp_t* structFileBundleInp ) {
    int status;
    int handleInx;
    char phyBunDir[MAX_NAME_LEN];
    char tmpPath[MAX_NAME_LEN];
    int l1descInx;
    char* dataType = 0; // JMC - backport 4664
    openedDataObjInp_t dataObjCloseInp;

    // =-=-=-=-=-=-=-
    // create an empty data obj
    dataObjInp_t dataObjInp;
    memset( &dataObjInp, 0, sizeof( dataObjInp ) );
    dataObjInp.openFlags = O_WRONLY;

    // =-=-=-=-=-=-=-
    // get the data type of the structured file
    dataType = getValByKey( &structFileBundleInp->condInput, DATA_TYPE_KW );

    // =-=-=-=-=-=-=-
    // ensure that the file name will end in .zip, if necessary
    if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
        int len = strlen( structFileBundleInp->objPath );
        if ( strcmp( &structFileBundleInp->objPath[len - 4], ".zip" ) != 0 ) {
            strcat( structFileBundleInp->objPath, ".zip" );
        }
    }

    // =-=-=-=-=-=-=-
    // capture the object path in the data obj struct
    rstrcpy( dataObjInp.objPath, structFileBundleInp->objPath, MAX_NAME_LEN );

    // =-=-=-=-=-=-=-
    // replicate the condInput. may have resource input
    replKeyVal( &structFileBundleInp->condInput, &dataObjInp.condInput );

    // =-=-=-=-=-=-=-
    // open the file if we are in an add operation, otherwise create the new file
    if ( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR ) != 0 ) { // JMC - backport 4643
        l1descInx = rsDataObjOpen( rsComm, &dataObjInp );

    }
    else {
        l1descInx = rsDataObjCreate( rsComm, &dataObjInp );

    }

    // =-=-=-=-=-=-=-
    // error check create / open
    if ( l1descInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsDataObjCreate of %s error. status = %d",
                 dataObjInp.objPath, l1descInx );
        return l1descInx;
    }

    // =-=-=-=-=-=-=-
    // FIXME :: Why, when we replicate them above?
    clearKeyVal( &dataObjInp.condInput ); // JMC - backport 4637
    // ???? l3Close (rsComm, l1descInx);

    // =-=-=-=-=-=-=-
    // zip does not like a zero length file as target
    //L1desc[ l1descInx ].l3descInx = 0;
    //if( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
    //    if( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR) == 0 ) { // JMC - backport 4643
    //        l3Unlink( rsComm, L1desc[l1descInx].dataObjInfo );
    //    }
    //}

    // =-=-=-=-=-=-=-
    // check object permissions / stat
    chkObjPermAndStat_t chkObjPermAndStatInp;
    memset( &chkObjPermAndStatInp, 0, sizeof( chkObjPermAndStatInp ) );
    rstrcpy( chkObjPermAndStatInp.objPath, structFileBundleInp->collection, MAX_NAME_LEN );
    chkObjPermAndStatInp.flags = CHK_COLL_FOR_BUNDLE_OPR;
    addKeyVal( &chkObjPermAndStatInp.condInput, RESC_NAME_KW,     L1desc[l1descInx].dataObjInfo->rescName );

    // =-=-=-=-=-=-=-
    // get the resc hier string
    std::string resc_hier;
    char* resc_hier_ptr = getValByKey( &structFileBundleInp->condInput, RESC_HIER_STR_KW );
    if ( !resc_hier_ptr ) {
        rodsLog( LOG_NOTICE, "_rsStructFileBundle :: RESC_HIER_STR_KW is NULL" );
    }
    else {
        addKeyVal( &chkObjPermAndStatInp.condInput, RESC_HIER_STR_KW, resc_hier_ptr );
        resc_hier = resc_hier_ptr;
    }

    status = rsChkObjPermAndStat( rsComm, &chkObjPermAndStatInp );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsChkObjPermAndStat of %s error. stat = %d",
                 chkObjPermAndStatInp.objPath, status );
        dataObjCloseInp.l1descInx = l1descInx;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        return status;
    }

    clearKeyVal( &chkObjPermAndStatInp.condInput );

    // =-=-=-=-=-=-=-
    // create the special hidden directory where the bundling happens
    createPhyBundleDir( rsComm, L1desc[ l1descInx ].dataObjInfo->filePath, phyBunDir, L1desc[ l1descInx ].dataObjInfo->rescHier );

    // =-=-=-=-=-=-=-
    // build a collection open input structure
    collInp_t collInp;
    bzero( &collInp, sizeof( collInp ) );
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG | INCLUDE_CONDINPUT_IN_QUERY;
    rstrcpy( collInp.collName, structFileBundleInp->collection, MAX_NAME_LEN );
    addKeyVal( &collInp.condInput, RESC_NAME_KW, L1desc[ l1descInx ].dataObjInfo->rescName );

    rodsLog( LOG_DEBUG, "rsStructFileBundle: calling rsOpenCollection for [%s]", structFileBundleInp->collection );

    // =-=-=-=-=-=-=-
    // open the collection from which we will bundle
    handleInx = rsOpenCollection( rsComm, &collInp );
    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsOpenCollection of %s error. status = %d",
                 collInp.collName, handleInx );
        rmdir( phyBunDir );
        return handleInx;
    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    int collLen = 0;
    if ( ( structFileBundleInp->oprType & PRESERVE_COLL_PATH ) != 0 ) {
        // =-=-=-=-=-=-=-
        // preserve the last entry of the coll path
        char* tmpPtr = collInp.collName;
        int   tmpLen = 0;
        collLen = 0;

        // =-=-=-=-=-=-=-
        // find length to the last '/'
        while ( *tmpPtr != '\0' ) {
            if ( *tmpPtr == '/' ) {
                collLen = tmpLen;
            }

            tmpLen++;
            tmpPtr++;
        }

    }
    else {
        collLen = strlen( collInp.collName );

    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    collEnt_t* collEnt = NULL;
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( NULL == collEnt ) {
            rodsLog(
                LOG_ERROR,
                "rsStructFileBundle: collEnt is NULL" );
            continue;
        }

        // =-=-=-=-=-=-=-
        // entry is a data object
        if ( collEnt->objType == DATA_OBJ_T ) {
            // =-=-=-=-=-=-=-
            // filter out any possible replicas that are not on this resource
            if ( resc_hier != collEnt->resc_hier ) {
                rodsLog(
                    LOG_DEBUG,
                    "_rsStructFileBundle - skipping [%s] on resc [%s]",
                    collEnt->phyPath,
                    collEnt->resc_hier );
                free( collEnt );
                collEnt = NULL;
                continue;
            }

            if ( collEnt->collName[collLen] == '\0' ) {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN,
                    "%s/%s",
                    phyBunDir,
                    collEnt->dataName );
            }
            else {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN, "%s/%s/%s",
                    phyBunDir,
                    collEnt->collName + collLen + 1,
                    collEnt->dataName );
                status = mkDirForFilePath(
                             rsComm,
                             strlen( phyBunDir ),
                             tmpPath,
                             collEnt->resc_hier,
                             getDefDirMode() );
                if ( status < 0 ) {
                    rodsLog(
                        LOG_ERROR,
                        "mkDirForFilePath failed in _rsStructFileBundle with status %d",
                        status );
                    free( collEnt );
                    return status;
                }
            }

            // =-=-=-=-=-=-=-
            // add a link
            status = link( collEnt->phyPath, tmpPath );
            if ( status < 0 ) {
                rodsLog(
                    LOG_ERROR,
                    "rsStructFileBundle: link error %s to %s. errno = %d",
                    collEnt->phyPath,
                    tmpPath,
                    errno );
                rmLinkedFilesInUnixDir( phyBunDir );
                rmdir( phyBunDir );
                free( collEnt );
                return UNIX_FILE_LINK_ERR - errno;
            }
            else {
                rodsLog(
                    LOG_DEBUG,
                    "_rsStructFileBundle - LINK  [%s] on resc [%s]",
                    collEnt->phyPath,
                    collEnt->resc_hier );
            }
        }
        else {
            // =-=-=-=-=-=-=-
            // entry is a collection
            if ( ( int ) strlen( collEnt->collName ) + 1 <= collLen ) {
                free( collEnt );
                collEnt = NULL;
                continue;
            }
            snprintf( tmpPath, MAX_NAME_LEN, "%s/%s", phyBunDir, collEnt->collName + collLen );
            status = mkFileDirR( rsComm, strlen( phyBunDir ), tmpPath, resc_hier.c_str(), getDefDirMode() );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR, "mkFileDirR failed in _rsStructFileBundle with status %d", status );
                free( collEnt );
                return status;
            }
        } // else

        free( collEnt );
        collEnt = NULL;

    } // while

    // =-=-=-=-=-=-=-
    // clean up key vals and close the collection
    clearKeyVal( &collInp.condInput );
    rsCloseCollection( rsComm, &handleInx );

    // =-=-=-=-=-=-=-
    // call the helper function to do the actual bundling
    status = phyBundle( rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
                        collInp.collName, structFileBundleInp->oprType ); // JMC - backport 4643

    int savedStatus = 0;
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: phyBundle of %s error. stat = %d",
                 L1desc[ l1descInx ].dataObjInfo->objPath, status );
        L1desc[ l1descInx ].bytesWritten = 0;
        savedStatus = status;
    }
    else {
        // mark it was written so the size would be adjusted
        L1desc[ l1descInx ].bytesWritten = 1;
    }

    // =-=-=-=-=-=-=-
    // clean up after the bundle directory
    rmLinkedFilesInUnixDir( phyBunDir );
    rmdir( phyBunDir );

    dataObjCloseInp.l1descInx = l1descInx;
    status = rsDataObjClose( rsComm, &dataObjCloseInp );
    if ( status >= 0 ) {
        return savedStatus;
    }

    return status;
}
Beispiel #29
0
int
rsMkCollR( rsComm_t *rsComm, const char *startColl, const char *destColl ) {
    int status;
    int startLen;
    int pathLen, tmpLen;
    char tmpPath[MAX_NAME_LEN];

    startLen = strlen( startColl );
    pathLen = strlen( destColl );

    rstrcpy( tmpPath, destColl, MAX_NAME_LEN );

    tmpLen = pathLen;

    while ( tmpLen > startLen ) {
        if ( isCollAllKinds( rsComm, tmpPath, NULL ) >= 0 ) {
            break;
        }

        /* Go backward */

        while ( tmpLen && tmpPath[tmpLen] != '/' ) {
            tmpLen --;
        }
        tmpPath[tmpLen] = '\0';
    }

    /* Now we go forward and make the required coll */
    while ( tmpLen < pathLen ) {
        collInp_t collCreateInp;

        /* Put back the '/' */
        tmpPath[tmpLen] = '/';
        memset( &collCreateInp, 0, sizeof( collCreateInp ) );
        rstrcpy( collCreateInp.collName, tmpPath, MAX_NAME_LEN );
        status = rsCollCreate( rsComm, &collCreateInp );

        if ( status == CAT_NAME_EXISTS_AS_DATAOBJ && isTrashPath( tmpPath ) ) {
            /* name conflict with a data object in the trash collection */
            dataObjCopyInp_t dataObjRenameInp;
            memset( &dataObjRenameInp, 0, sizeof( dataObjRenameInp ) );

            dataObjRenameInp.srcDataObjInp.oprType =
                dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;
            rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, tmpPath,
                     MAX_NAME_LEN );
            rstrcpy( dataObjRenameInp.destDataObjInp.objPath, tmpPath,
                     MAX_NAME_LEN );
            appendRandomToPath( dataObjRenameInp.destDataObjInp.objPath );

            status = rsDataObjRename( rsComm, &dataObjRenameInp );
            if ( status >= 0 ) {
                status = rsCollCreate( rsComm, &collCreateInp );
            }
        }
        /* something may be added by rsCollCreate */
        clearKeyVal( &collCreateInp.condInput );
        if ( status < 0 ) {
            // =-=-=-=-=-=-=-
            // JMC - backport 4819
            if ( status == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                rodsLog( LOG_DEBUG,
                         "rsMkCollR: rsCollCreate - coll %s already exist.stat = %d",
                         tmpPath, status );
                status = 0;
            }
            else {
                rodsLog( LOG_ERROR,
                         "rsMkCollR: rsCollCreate failed for %s, status =%d",
                         tmpPath, status );
            }
            // =-=-=-=-=-=-=-
            return status;
        }
        while ( tmpLen && tmpPath[tmpLen] != '\0' ) {
            tmpLen ++;
        }
    }
    return 0;
}
Beispiel #30
0
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 );
}