Example #1
0
int
rsMkBundlePath( rsComm_t *rsComm, char *collection, char *bundlePath,
                int myRanNum ) {
    int status;
    char *tmpStr;
    char startBundlePath[MAX_NAME_LEN];
    char destBundleColl[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
    char *bundlePathPtr;

    bundlePathPtr = bundlePath;
    *bundlePathPtr = '/';
    bundlePathPtr++;
    tmpStr = collection + 1;
    /* copy the zone */
    while ( *tmpStr != '\0' ) {
        *bundlePathPtr = *tmpStr;
        bundlePathPtr ++;
        if ( *tmpStr == '/' ) {
            tmpStr ++;
            break;
        }
        tmpStr ++;
    }

    if ( *tmpStr == '\0' ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: input path %s too short", collection );
        return USER_INPUT_PATH_ERR;
    }

    /* cannot bundle trash and bundle */
    if ( strncmp( tmpStr, "trash/", 6 ) == 0 ||
            strncmp( tmpStr, "bundle/", 7 ) == 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: cannot bundle trash or bundle path %s", collection );
        return USER_INPUT_PATH_ERR;
    }


    /* don't want to go back beyond /myZone/bundle/home */
    *bundlePathPtr = '\0';
    rstrcpy( startBundlePath, bundlePath, MAX_NAME_LEN );

    snprintf( bundlePathPtr, MAX_NAME_LEN, "bundle/%s.%u", tmpStr, ( unsigned int )myRanNum );

    if ( ( status = splitPathByKey( bundlePath, destBundleColl, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) )
            < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: splitPathByKey error for %s ", bundlePath );
        return USER_INPUT_PATH_ERR;
    }

    status = rsMkCollR( rsComm, startBundlePath, destBundleColl );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: rsMkCollR error for startPath %s, destPath %s ",
                 startBundlePath, destBundleColl );
    }

    return status;
}
Example #2
0
/* resolveRodsTarget - based on srcPath and destPath, fill in targPath.
 * oprType - 
 *	MOVE_OPR - do not create the target coll or dir because rename will
 *	  take care of it.
 *	RSYNC_OPR - udes the destPath and the targPath if the src is a 
 *	  collection
 *	All other oprType will be treated as normal.
 */
int
resolveRodsTarget (rcComm_t *conn, rodsEnv *myRodsEnv,
rodsPathInp_t *rodsPathInp, int oprType) 
{
    rodsPath_t *srcPath, *destPath;
    char srcElement[MAX_NAME_LEN], destElement[MAX_NAME_LEN];
    int status;
    int srcInx;
    rodsPath_t *targPath;

    if (rodsPathInp == NULL) {
       rodsLog (LOG_ERROR,
	  "resolveRodsTarget: NULL rodsPathInp or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    destPath = rodsPathInp->destPath;
    if (destPath != NULL && destPath->objState == UNKNOWN_ST) {
        getRodsObjType (conn, destPath);
    }

    for (srcInx = 0; srcInx < rodsPathInp->numSrc; srcInx++) {
        srcPath = &rodsPathInp->srcPath[srcInx];
        targPath = &rodsPathInp->targPath[srcInx];

        /* we don't do wild card yet */ 

        if (srcPath->objState == UNKNOWN_ST) {
            getRodsObjType (conn, srcPath);
	    if (srcPath->objState == NOT_EXIST_ST) {
	        rodsLog (LOG_ERROR,
                  "resolveRodsTarget: srcPath %s does not exist",
                  srcPath->outPath);
	        return (USER_INPUT_PATH_ERR);
	    }
        }
	
        if (destPath->objType >= UNKNOWN_FILE_T && 
         strcmp (destPath->outPath, STDOUT_FILE_NAME) == 0) {
	    /* pipe to stdout */
	    if (srcPath->objType != DATA_OBJ_T) {
                rodsLog (LOG_ERROR, 
                  "resolveRodsTarget: src %s is the wrong type for dest -",
                  srcPath->outPath);
		return (USER_INPUT_PATH_ERR);
	    }
            *targPath = *destPath;
            targPath->objType = LOCAL_FILE_T;
        } else if (srcPath->objType == DATA_OBJ_T || 
	    srcPath->objType == LOCAL_FILE_T) {
	    /* file type source */

	    if ((destPath->objType == COLL_OBJ_T || 
	      destPath->objType == LOCAL_DIR_T) && 
	      destPath->objState == EXIST_ST) {
                if (destPath->objType <= COLL_OBJ_T) {
                    targPath->objType = DATA_OBJ_T;
                } else {
                    targPath->objType = LOCAL_FILE_T;
                }

	        /* collection */
	        getLastPathElement (srcPath->inPath, srcElement);
	        if (strlen (srcElement) > 0) {
		    snprintf (targPath->outPath, MAX_NAME_LEN, "%s/%s",
		      destPath->outPath, srcElement);
		    if (destPath->objType <= COLL_OBJ_T)
		        getRodsObjType (conn, destPath);
	        } else {
		    rstrcpy (targPath->outPath, destPath->outPath, 
		      MAX_NAME_LEN);
	        }
	    } else if (destPath->objType == DATA_OBJ_T || 
	      destPath->objType == LOCAL_FILE_T || rodsPathInp->numSrc == 1) {
		*targPath = *destPath;
                if (destPath->objType <= COLL_OBJ_T) {
                    targPath->objType = DATA_OBJ_T;
                } else {
                    targPath->objType = LOCAL_FILE_T;
                }
	    } else {
                rodsLogError (LOG_ERROR, USER_FILE_DOES_NOT_EXIST,
                  "resolveRodsTarget: target %s does not exist",
                  destPath->outPath);
                return (USER_FILE_DOES_NOT_EXIST);
            }
        } else if (srcPath->objType == COLL_OBJ_T || 
          srcPath->objType == LOCAL_DIR_T) {
	    /* directory type source */

            if (destPath->objType <= COLL_OBJ_T) {
                targPath->objType = COLL_OBJ_T;
            } else {
                targPath->objType = LOCAL_DIR_T;
            }

	    if (destPath->objType == DATA_OBJ_T ||
	      destPath->objType == LOCAL_FILE_T) {
	        rodsLog (LOG_ERROR, 
                  "resolveRodsTarget: input destPath %s is a datapath",
                  destPath->outPath);
	        return (USER_INPUT_PATH_ERR);
	    } else if ((destPath->objType == COLL_OBJ_T ||
	      destPath->objType == LOCAL_DIR_T) && 
	      destPath->objState == EXIST_ST) {
	        /* the collection exist */
                getLastPathElement (srcPath->inPath, srcElement);
                if (strlen (srcElement) > 0) {
		    if (rodsPathInp->numSrc == 1 && oprType == RSYNC_OPR) {
			getLastPathElement (destPath->inPath, destElement);
			/* RSYNC_OPR. Just use the same path */
			if (strlen (destElement) > 0) {
			    rstrcpy (targPath->outPath, destPath->outPath,
			      MAX_NAME_LEN);
			}
		    }
		    if (targPath->outPath[0] == '\0') {
                        snprintf (targPath->outPath, MAX_NAME_LEN, "%s/%s",
                          destPath->outPath, srcElement);
		        /* make the collection */
		        if (destPath->objType == COLL_OBJ_T) {
		            if (oprType != MOVE_OPR) {
			        /* rename does not need to mkColl */
#ifndef FILESYSTEM_META
		                status = mkColl (conn, targPath->outPath);
#else
                                if (srcPath->objType <= COLL_OBJ_T) {
                                    status = mkCollWithSrcCollMeta (conn, destPath->outPath, srcPath->outPath);
                                } else {
                                    status = mkCollWithDirMeta (conn, targPath->outPath, srcPath->inPath);
                                }
#endif
		            } else {
			        status = 0;
		            }
		        } else {
#ifdef windows_platform
		            status = iRODSNt_mkdir (targPath->outPath, 0750);
#else
			    status = mkdir (targPath->outPath, 0750);
#endif
		            if (status < 0 && errno == EEXIST) {
			        status = 0;
		            }
		        }
		        if (status < 0) {
		            rodsLogError (LOG_ERROR, status,
		             "resolveRodsTarget: mkColl/mkdir for %s,status=%d",
		              targPath->outPath, status);
		            return (status);
		        }
		    }
                } else {
                    rstrcpy (targPath->outPath, destPath->outPath, 
		      MAX_NAME_LEN);
                }
	    } else {
	        /* dest coll does not exist */
	        if (destPath->objType <= COLL_OBJ_T) { 
                    if (oprType != MOVE_OPR) {
                        /* rename does not need to mkColl */
#ifndef FILESYSTEM_META
                        status = mkColl (conn, destPath->outPath);
#else
                        if (srcPath->objType <= COLL_OBJ_T) {
                            status = mkCollWithSrcCollMeta (conn, destPath->outPath, srcPath->outPath);
                        } else {
                            status = mkCollWithDirMeta (conn, destPath->outPath, srcPath->inPath);
                        }
#endif
		    } else {
		        status = 0;
		    }
	        } else {
                    /* use destPath. targPath->outPath not defined.
		     *  status = mkdir (targPath->outPath, 0750); */
#ifdef windows_platform
		    status = iRODSNt_mkdir (destPath->outPath, 0750);
#else
		    status = mkdir (destPath->outPath, 0750);
#endif
	        }
                if (status < 0) {
                    return (status);
                }

	        if (rodsPathInp->numSrc == 1) {
                    rstrcpy (targPath->outPath, destPath->outPath, 
		      MAX_NAME_LEN);
                } else {
                    rodsLogError (LOG_ERROR, USER_FILE_DOES_NOT_EXIST,
                      "resolveRodsTarget: target %s does not exist",
                      destPath->outPath);
                    return (USER_FILE_DOES_NOT_EXIST);
                }
	    }
	    targPath->objState = EXIST_ST;
        } else {	/* should not be here */
	    if (srcPath->objState == NOT_EXIST_ST) { 
                rodsLog (LOG_ERROR,
                  "resolveRodsTarget: source %s does not exist",
                  srcPath->outPath);
	    } else {
	         rodsLog (LOG_ERROR,
                  "resolveRodsTarget: cannot handle objType %d for srcPath %s",
                  srcPath->objType, srcPath->outPath);
	    }
	    return (USER_INPUT_PATH_ERR);
        }
    }
    return (0);
}
Example #3
0
int
collStat( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
          rodsObjStat_t **rodsObjStatOut ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int status;
    char condStr[MAX_NAME_LEN];
    sqlResult_t *dataId;
    sqlResult_t *ownerName;
    sqlResult_t *ownerZone;
    sqlResult_t *createTime;
    sqlResult_t *modifyTime;
    sqlResult_t *collType;
    sqlResult_t *collInfo1;
    sqlResult_t *collInfo2;

    /* see if objPath is a collection */
    memset( &genQueryInp, 0, sizeof( genQueryInp ) );

    snprintf( condStr, MAX_NAME_LEN, "='%s'", dataObjInp->objPath );
    addInxVal( &genQueryInp.sqlCondInp, COL_COLL_NAME, condStr );

    addInxIval( &genQueryInp.selectInp, COL_COLL_ID, 1 );
    /* XXXX COL_COLL_NAME added for queueSpecColl */
    addInxIval( &genQueryInp.selectInp, COL_COLL_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1 );
    /* XXXX may want to do this if spec coll is supported */
    addInxIval( &genQueryInp.selectInp, COL_COLL_TYPE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO1, 1 );
    addInxIval( &genQueryInp.selectInp, COL_COLL_INFO2, 1 );

    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( status >= 0 ) {
        *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) );
        memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) );
        ( *rodsObjStatOut )->objType = COLL_OBJ_T;
        status = ( int )COLL_OBJ_T;
        if ( ( dataId = getSqlResultByInx( genQueryOut,
                                           COL_COLL_ID ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat: getSqlResultByInx for COL_COLL_ID failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( ownerName = getSqlResultByInx( genQueryOut,
                                COL_COLL_OWNER_NAME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_NAME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( ownerZone = getSqlResultByInx( genQueryOut,
                                COL_COLL_OWNER_ZONE ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( createTime = getSqlResultByInx( genQueryOut,
                                 COL_COLL_CREATE_TIME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_CREATE_TIME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( modifyTime = getSqlResultByInx( genQueryOut,
                                 COL_COLL_MODIFY_TIME ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collType = getSqlResultByInx( genQueryOut,
                               COL_COLL_TYPE ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_TYPE failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collInfo1 = getSqlResultByInx( genQueryOut,
                                COL_COLL_INFO1 ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_INFO1 failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else if ( ( collInfo2 = getSqlResultByInx( genQueryOut,
                                COL_COLL_INFO2 ) ) == NULL ) {
            rodsLog( LOG_ERROR,
                     "_rsObjStat:getSqlResultByInx for COL_COLL_INFO2 failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }
        else {
            rstrcpy( ( *rodsObjStatOut )->dataId, dataId->value, NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->ownerName, ownerName->value,
                     NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->ownerZone, ownerZone->value,
                     NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->createTime, createTime->value,
                     TIME_LEN );
            rstrcpy( ( *rodsObjStatOut )->modifyTime, modifyTime->value,
                     TIME_LEN );

            if ( strlen( collType->value ) > 0 ) {
                specCollCache_t *specCollCache = 0;

                if ( ( specCollCache =
                            matchSpecCollCache( dataObjInp->objPath ) ) != NULL ) {
                    replSpecColl( &specCollCache->specColl,
                                  &( *rodsObjStatOut )->specColl );
                }
                else {
                    status = queueSpecCollCache( rsComm, genQueryOut, // JMC - backport 4680?
                                                 dataObjInp->objPath );
                    if ( status < 0 ) {
                        return status;
                    }
                    replSpecColl( &SpecCollCacheHead->specColl,
                                  &( *rodsObjStatOut )->specColl );
                }


            }
        }
    }

    clearGenQueryInp( &genQueryInp );
    freeGenQueryOut( &genQueryOut );

    return status;
}
Example #4
0
    int msiobjput_slink(
        msParam_t*      inMSOPath,
        msParam_t*      inCacheFilename,
        msParam_t*      inFileSize,
        ruleExecInfo_t* rei ) {

        RE_TEST_MACRO( "    Calling msiobjput_slink" );

        /*  check for input parameters */
        if ( inMSOPath ==  NULL ||
                strcmp( inMSOPath->type , STR_MS_T ) != 0 ||
                inMSOPath->inOutStruct == NULL ) {
            return USER_PARAM_TYPE_ERR;
        }

        if ( inCacheFilename ==  NULL ||
                strcmp( inCacheFilename->type , STR_MS_T ) != 0 ||
                inCacheFilename->inOutStruct == NULL ) {
            return USER_PARAM_TYPE_ERR;
        }

        if ( inFileSize ==  NULL ||
                strcmp( inFileSize->type , STR_MS_T ) != 0 ||
                inFileSize->inOutStruct == NULL ) {
            return USER_PARAM_TYPE_ERR;
        }

        /*  coerce input to local variables */
        char * str = strdup( ( char * ) inMSOPath->inOutStruct );
        char * reqStr = strstr( str, ":" );
        if ( reqStr == NULL ) {
            free( str );
            return USER_INPUT_FORMAT_ERR;
        }
        reqStr = reqStr + 1;

        dataObjInp_t dataObjInp;
        memset( &dataObjInp, 0, sizeof( dataObjInp_t ) );
        rstrcpy( dataObjInp.objPath, reqStr, MAX_NAME_LEN );
        addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
        free( str );

        rsComm_t * rsComm = rei->rsComm;
        int outDesc = rsDataObjCreate( rsComm, &dataObjInp );
        if ( outDesc < 0 ) {
            printf( "msiputobj_slink: Unable to open file %s:%i\n", dataObjInp.objPath, outDesc );
            return outDesc;
        }

        /* Read the cache and Do the upload*/
        char * cacheFilename = ( char * ) inCacheFilename->inOutStruct;
        int srcFd = open( cacheFilename, O_RDONLY, 0 );
        if ( srcFd < 0 ) {
            int status = UNIX_FILE_OPEN_ERR - errno;
            printf( "msiputobj_slink: open error for %s, status = %d\n",
                    cacheFilename, status );
            return status;
        }

        int single_buff_sz = 0;
        irods::error ret = irods::get_advanced_setting<int>(
                               irods::CFG_MAX_SIZE_FOR_SINGLE_BUFFER,
                               single_buff_sz );
        if( !ret.ok() ) {
            irods::log( PASS( ret ) );
            return ret.code();
        }
        single_buff_sz *= 1024 * 1024;

        size_t dataSize  = atol( ( char * ) inFileSize->inOutStruct );
        if ( dataSize > single_buff_sz ) {
            dataSize = single_buff_sz;
        }

        openedDataObjInp_t dataObjWriteInp;
        memset( &dataObjWriteInp, 0, sizeof( dataObjWriteInp ) );
        dataObjWriteInp.l1descInx = outDesc;

        openedDataObjInp_t dataObjCloseInp;
        memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) );
        dataObjCloseInp.l1descInx = outDesc;

        char * myBuf = ( char * ) malloc( dataSize );
        bytesBuf_t writeBuf;
        writeBuf.buf = myBuf;

        int bytesRead;
        for ( bytesRead = read( srcFd, ( void * ) myBuf, dataSize ); bytesRead > 0;
                bytesRead = read( srcFd, ( void * ) myBuf, dataSize ) ) {
            writeBuf.len = bytesRead;
            dataObjWriteInp.len = bytesRead;
            int bytesWritten = rsDataObjWrite( rsComm, &dataObjWriteInp, &writeBuf );
            if ( bytesWritten != bytesRead ) {
                free( myBuf );
                close( srcFd );
                rsDataObjClose( rsComm, &dataObjCloseInp );
                printf( "msiputobj_slink: Write Error: bytesRead %d != bytesWritten %d\n",
                        bytesRead, bytesWritten );
                return SYS_COPY_LEN_ERR;
            }
        }
        free( myBuf );
        close( srcFd );
        return rsDataObjClose( rsComm, &dataObjCloseInp );
    }
Example #5
0
int
parseCmdLinePath (int argc, char **argv, int optInd, rodsEnv *myRodsEnv, 
int srcFileType, int destFileType, int flag, rodsPathInp_t *rodsPathInp)
{
    int nInput;
    int i, status;
    int numSrc;

    nInput = argc - optInd;

    if (rodsPathInp == NULL) {
	rodsLog (LOG_ERROR, 
	  "parseCmdLinePath: NULL rodsPathInp input");
	return (USER__NULL_INPUT_ERR);
    }

    memset (rodsPathInp, 0, sizeof (rodsPathInp_t));

    if (nInput <= 0) {
        if ((flag & ALLOW_NO_SRC_FLAG) == 0) {
	    return (USER__NULL_INPUT_ERR);
	} else {
	    numSrc = 1;
	}
    } else if (nInput == 1) {
	numSrc = 1;
    } else if (destFileType == NO_INPUT_T) {		/* no dest input */
	numSrc = nInput;
    } else {
	numSrc = nInput - 1;
    }

    for (i = 0; i < numSrc; i++) {
	if (nInput <= 0) {
	    /* just add cwd */
            addSrcInPath (rodsPathInp, ".");
	} else {
            addSrcInPath (rodsPathInp, argv[optInd + i]);
	}
        if (srcFileType <= COLL_OBJ_T) {
            status = parseRodsPath (&rodsPathInp->srcPath[i], myRodsEnv);
        } else {
            status = parseLocalPath (&rodsPathInp->srcPath[i]);
        }
        if (status < 0) {
            return (status);
        }
    }

    if (destFileType != NO_INPUT_T) {
	rodsPathInp->destPath = (rodsPath_t*)malloc (sizeof (rodsPath_t));
	memset (rodsPathInp->destPath, 0, sizeof (rodsPath_t));
        if (nInput > 1) {
	    rstrcpy (rodsPathInp->destPath->inPath, argv[argc - 1], 
	      MAX_NAME_LEN);
	} else {
            rstrcpy (rodsPathInp->destPath->inPath, ".", MAX_NAME_LEN);
	}

        if (destFileType <= COLL_OBJ_T) {
            status = parseRodsPath (rodsPathInp->destPath, myRodsEnv);
        } else {
            status = parseLocalPath (rodsPathInp->destPath);
        }
    }

    return (status);
}
Example #6
0
int
initCondForGet (rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjOprInp, rodsRestart_t *rodsRestart)
{
#ifdef RBUDP_TRANSFER
    char *tmpStr;
#endif  /* RBUDP_TRANSFER */

    if (dataObjOprInp == NULL) {
       rodsLog (LOG_ERROR,
          "initCondForGet: NULL dataObjOprInp input");
        return (USER__NULL_INPUT_ERR);
    }

    memset (dataObjOprInp, 0, sizeof (dataObjInp_t));

    if (rodsArgs == NULL) {
	return (0);
    }

    dataObjOprInp->oprType = GET_OPR;

    if (rodsArgs->force == True) { 
        addKeyVal (&dataObjOprInp->condInput, FORCE_FLAG_KW, "");
    }

    if (rodsArgs->verifyChecksum == True) {
        addKeyVal (&dataObjOprInp->condInput, VERIFY_CHKSUM_KW, "");
    }

#ifdef windows_platform
    dataObjOprInp->numThreads = NO_THREADING;
#else
    if (rodsArgs->number == True) {
	if (rodsArgs->numberValue == 0) {
	    dataObjOprInp->numThreads = NO_THREADING;
	} else {
	    dataObjOprInp->numThreads = rodsArgs->numberValue;
	}
    }
#endif

    if (rodsArgs->replNum == True) {
        addKeyVal (&dataObjOprInp->condInput, REPL_NUM_KW, 
	  rodsArgs->replNumValue);
    }

    if (rodsArgs->resource == True) {
        if (rodsArgs->resourceString == NULL) {
            rodsLog (LOG_ERROR,
              "initCondForPut: NULL resourceString error");
            return (USER__NULL_INPUT_ERR);
        } else {
            addKeyVal (&dataObjOprInp->condInput, RESC_NAME_KW,
              rodsArgs->resourceString);
        }
    }

    if (rodsArgs->ticket == True) {
       if (rodsArgs->ticketString == NULL) {
	  rodsLog (LOG_ERROR,
		   "initCondForPut: NULL ticketString error");
	  return (USER__NULL_INPUT_ERR);
       } else {
	  addKeyVal (&dataObjOprInp->condInput, TICKET_KW,
		     rodsArgs->ticketString);
       }
    }

#ifdef RBUDP_TRANSFER
    if (rodsArgs->rbudp == True) {
        /* use -Q for rbudp transfer */
        addKeyVal (&dataObjOprInp->condInput, RBUDP_TRANSFER_KW, "");
    }

    if (rodsArgs->veryVerbose == True) {
        addKeyVal (&dataObjOprInp->condInput, VERY_VERBOSE_KW, "");
    }

    if ((tmpStr = getenv (RBUDP_SEND_RATE_KW)) != NULL) {
        addKeyVal (&dataObjOprInp->condInput, RBUDP_SEND_RATE_KW, tmpStr);
    }

    if ((tmpStr = getenv (RBUDP_PACK_SIZE_KW)) != NULL) {
        addKeyVal (&dataObjOprInp->condInput, RBUDP_PACK_SIZE_KW, tmpStr);
    }
#else   /* RBUDP_TRANSFER */
    if (rodsArgs->rbudp == True) {
        rodsLog (LOG_NOTICE,
          "initCondForGet: RBUDP_TRANSFER (-d) not supported");
    }
#endif  /* RBUDP_TRANSFER */

    if (rodsArgs->purgeCache == True) {
        addKeyVal (&dataObjOprInp->condInput, PURGE_CACHE_KW, "");
    }
    memset (rodsRestart, 0, sizeof (rodsRestart_t));
    if (rodsArgs->restart == True) {
        int status;
        status = openRestartFile (rodsArgs->restartFileString, rodsRestart,
          rodsArgs);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "initCondForPut: openRestartFile of %s errno",
            rodsArgs->restartFileString);
            return (status);
        }
    }

    if (rodsArgs->retries == True && rodsArgs->restart == False &&
      rodsArgs->lfrestart == False) {
        rodsLog (LOG_ERROR,
          "initCondForGet: --retries must be used with -X option");
        return USER_INPUT_OPTION_ERR;
    }

    if (rodsArgs->lfrestart == True) {
        if (rodsArgs->rbudp == True) {
            rodsLog (LOG_NOTICE,
              "initCondForPut: --lfrestart cannot be used with -Q option");
        } else {
            conn->fileRestart.flags = FILE_RESTART_ON;
            rstrcpy (conn->fileRestart.infoFile, rodsArgs->lfrestartFileString,
              MAX_NAME_LEN);
        }
    }
    if (rodsArgs->rlock == True) {
        addKeyVal (&dataObjOprInp->condInput, LOCK_TYPE_KW, READ_LOCK_TYPE);
    }
    if (rodsArgs->wlock == True) {
        rodsLog (LOG_ERROR,
          "initCondForPut: --wlock not supported, changing it to --rlock");
        addKeyVal (&dataObjOprInp->condInput, LOCK_TYPE_KW, READ_LOCK_TYPE);
    }
    dataObjOprInp->openFlags = O_RDONLY;

    return (0);
}
Example #7
0
int
getCollUtil (rcComm_t **myConn, char *srcColl, char *targDir, 
rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp,
rodsRestart_t *rodsRestart)
{
    int status = 0; 
    int savedStatus = 0;
    char srcChildPath[MAX_NAME_LEN], targChildPath[MAX_NAME_LEN];
#if 0
    int collLen;
#else
    char parPath[MAX_NAME_LEN], childPath[MAX_NAME_LEN];
#endif
    collHandle_t collHandle;
    collEnt_t collEnt;
    dataObjInp_t childDataObjInp;
    rcComm_t *conn;

    if (srcColl == NULL || targDir == NULL) {
       rodsLog (LOG_ERROR,
          "getCollUtil: NULL srcColl or targDir input");
        return (USER__NULL_INPUT_ERR);
    }

    if (rodsArgs->recursive != True) {
        rodsLog (LOG_ERROR,
        "getCollUtil: -r option must be used for getting %s collection",
         targDir);
        return (USER_INPUT_OPTION_ERR);
    }

    if (rodsArgs->redirectConn == True) {
        int reconnFlag;
        if (rodsArgs->reconnect == True) {
            reconnFlag = RECONN_TIMEOUT;
        } else {
            reconnFlag = NO_RECONN;
        }
        /* reconnect to the resource server */
        rstrcpy (dataObjOprInp->objPath, srcColl, MAX_NAME_LEN);
        redirectConnToRescSvr (myConn, dataObjOprInp, myRodsEnv, reconnFlag);
        rodsArgs->redirectConn = 0;    /* only do it once */
    }
    conn = *myConn;

    printCollOrDir (targDir, LOCAL_DIR_T, rodsArgs, dataObjOprInp->specColl);
#if 0
    status = rclOpenCollection (conn, srcColl, RECUR_QUERY_FG, 
      &collHandle);
#else
    status = rclOpenCollection (conn, srcColl, 0, &collHandle);
#endif

    if (status < 0) {
	rodsLog (LOG_ERROR,
          "getCollUtil: rclOpenCollection of %s error. status = %d",
          srcColl, status);
        return status;
    }
#if 0
    collLen = strlen (srcColl);
    collLen = getOpenedCollLen (&collHandle);
#endif
    while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) {
        if (collEnt.objType == DATA_OBJ_T) {
            rodsLong_t mySize;

            mySize = collEnt.dataSize;    /* have to save it. May be freed */  

#if 0
            snprintf (targChildPath, MAX_NAME_LEN, "%s%s/%s",
              targDir, collEnt.collName + collLen,
              collEnt.dataName);
#else
            snprintf (targChildPath, MAX_NAME_LEN, "%s/%s",
              targDir, collEnt.dataName);
#endif
            snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s",
              collEnt.collName, collEnt.dataName);

            status = chkStateForResume (conn, rodsRestart, targChildPath,
              rodsArgs, LOCAL_FILE_T, &dataObjOprInp->condInput, 1);

            if (status < 0) {
                /* restart failed */
                break;
            } else if (status == 0) {
                continue;
            }

            status = getDataObjUtil (conn, srcChildPath,
             targChildPath, mySize, collEnt.dataMode, myRodsEnv, rodsArgs, 
	     dataObjOprInp);
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                  "getCollUtil: getDataObjUtil failed for %s. status = %d",
                  srcChildPath, status);
                savedStatus = status;
                if (rodsRestart->fd > 0) break;
            } else {
                status = procAndWrriteRestartFile (rodsRestart, targChildPath);
            }
	} else if (collEnt.objType == COLL_OBJ_T) {
            if ((status = splitPathByKey (
              collEnt.collName, parPath, childPath, '/')) < 0) {
                rodsLogError (LOG_ERROR, status,
                  "getCollUtil:: splitPathByKey for %s error, status = %d",
                  collEnt.collName, status);
                return (status);
            }
            snprintf (targChildPath, MAX_NAME_LEN, "%s/%s",
              targDir, childPath);

            mkdirR (targDir, targChildPath, 0750);

            /* the child is a spec coll. need to drill down */
            childDataObjInp = *dataObjOprInp;
            if (collEnt.specColl.collClass != NO_SPEC_COLL)
                childDataObjInp.specColl = &collEnt.specColl;
	    else 
	        childDataObjInp.specColl = NULL;
            status = getCollUtil (myConn, collEnt.collName, targChildPath,
              myRodsEnv, rodsArgs, &childDataObjInp, rodsRestart);
	    if (status < 0 && status != CAT_NO_ROWS_FOUND) {
                rodsLogError (LOG_ERROR, status,
                  "getCollUtil: getCollUtil failed for %s. status = %d",
                  collEnt.collName, status);
                savedStatus = status;
                if (rodsRestart->fd > 0) break;
	    }
        }
    }
    rclCloseCollection (&collHandle);

    if (savedStatus < 0) {
	return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND || 
      status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
	return (0);
    } else {
        return (status);
    }
}
Example #8
0
/**
 * \fn msiDigestMonStat(msParam_t *cpu_wght, msParam_t *mem_wght, msParam_t *swap_wght,
 *       msParam_t *runq_wght, msParam_t *disk_wght, msParam_t *netin_wght,
 *       msParam_t *netout_wght, ruleExecInfo_t *rei)
 *
 * \brief  This microservice calculates and stores a load factor for each connected
 *    resource based on the weighting values passed in as parameters.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2009-06
 *
 * \note  The following values are loaded from R_LOAD_SERVER:
 *    \li cpu_used
 *    \li mem_used
 *    \li swap_used
 *    \li runq_load
 *    \li disk_space
 *    \li net_input
 *    \li net_output
 *
 * \note  The stored load factor is calculated as such:
 *    \li load_factor = cpu_wght*cpu_used + mem_wght*mem_used + swap_wght*swap_used +
 *        runq_wght*runq_load + disk_wght*disk_space + netin_wght*net_input +
 *        netout_wght*net_output
 *
 * \usage See clients/icommands/test/rules3.0/ and https://wiki.irods.org/index.php/Resource_Monitoring_System
 *
 * \param[in] cpu_wght - Required - a msParam of type STR_MS_T defining relative CPU weighting.
 * \param[in] mem_wght - Required - a msParam of type STR_MS_T defining relative memory weighting
 * \param[in] swap_wght - Required - a msParam of type STR_MS_T defining relative swap weighting
 * \param[in] runq_wght - Required - a msParam of type STR_MS_T defining relative run queue weighting
 * \param[in] disk_wght - Required - a msParam of type STR_MS_T defining relative disk space weighting
 * \param[in] netin_wght - Required - a msParam of type STR_MS_T defining relative inbound network weighting
 * \param[in] netout_wght - Required - a msParam of type STR_MS_T defining relative outbound network weighting
 * \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 R_SERVER_LOAD table content
 * \iCatAttrModified R_SERVER_LOAD_DIGEST table content
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa  N/A
 **/
int msiDigestMonStat( msParam_t *cpu_wght, msParam_t *mem_wght, msParam_t *swap_wght, msParam_t *runq_wght,
                      msParam_t *disk_wght, msParam_t *netin_wght, msParam_t *netout_wght,
                      ruleExecInfo_t *rei ) {
    char rescList[MAX_NSERVERS][MAX_NAME_LEN], *tResult,
         timeList[MAX_NSERVERS][MAX_NAME_LEN];
    char condStr1[MAX_NAME_LEN], condStr2[MAX_NAME_LEN], loadStr[MAX_NAME_LEN];
    int i, j, loadFactor, nresc, rc, status, totalWeight, weight[NRESULT];
    rsComm_t *rsComm;
    generalRowInsertInp_t generalRowInsertInp;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;

    RE_TEST_MACRO( "    Calling msiDigestMonStat" );

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

    rsComm = rei->rsComm;

    if ( cpu_wght == NULL || mem_wght == NULL || swap_wght == NULL || runq_wght == NULL
            || disk_wght == NULL || netin_wght == NULL || netout_wght == NULL ) {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: at least one of the input param is NULL" );
        return rei->status;
    }

    if ( strcmp( cpu_wght->type, STR_MS_T ) == 0 ) {
        weight[0] = atoi( ( const char* )cpu_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input cpu_wght type %s",
                            cpu_wght->type );
        return rei->status;
    }

    if ( strcmp( mem_wght->type, STR_MS_T ) == 0 ) {
        weight[1] = atoi( ( const char* )mem_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input mem_wght type %s",
                            mem_wght->type );
        return rei->status;
    }

    if ( strcmp( swap_wght->type, STR_MS_T ) == 0 ) {
        weight[2] = atoi( ( const char* )swap_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input swap_wght type %s",
                            swap_wght->type );
        return rei->status;
    }

    if ( strcmp( runq_wght->type, STR_MS_T ) == 0 ) {
        weight[3] = atoi( ( const char* )runq_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input runq_wght type %s",
                            runq_wght->type );
        return rei->status;
    }

    if ( strcmp( disk_wght->type, STR_MS_T ) == 0 ) {
        weight[4] = atoi( ( const char* )disk_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input disk_wght type %s",
                            disk_wght->type );
        return rei->status;
    }

    if ( strcmp( netin_wght->type, STR_MS_T ) == 0 ) {
        weight[5] = atoi( ( const char* )netin_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input netin_wght type %s",
                            netin_wght->type );
        return rei->status;
    }

    if ( strcmp( netout_wght->type, STR_MS_T ) == 0 ) {
        weight[6] = atoi( ( const char* )netout_wght->inOutStruct );
    }
    else {
        rodsLogAndErrorMsg( LOG_ERROR, &rsComm->rError, rei->status,
                            "msiDigestMonStat: Unsupported input netout_wght type %s",
                            netout_wght->type );
        return rei->status;
    }

    totalWeight = 0;
    for ( i = 0; i < NRESULT; i++ ) {
        totalWeight += weight[i];
    }

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_SL_RESC_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_CREATE_TIME, SELECT_MAX );
    genQueryInp.maxRows = MAX_SQL_ROWS;
    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( NULL == genQueryOut ) { // JMC cppcheck - nullptr
        rodsLog( LOG_ERROR, "msiDigestMonStat :: &genQueryOut is NULL" );
        return rei->status;
    }
    if ( status == 0 ) {
        nresc = genQueryOut->rowCnt;
        for ( i = 0; i < genQueryOut->attriCnt; i++ ) {
            for ( j = 0; j < nresc; j++ ) {
                tResult = genQueryOut->sqlResult[i].value;
                tResult += j * genQueryOut->sqlResult[i].len;
                if ( i == 0 ) {
                    rstrcpy( rescList[j], tResult, genQueryOut->sqlResult[i].len );
                }
                if ( i == 1 ) {
                    rstrcpy( timeList[j], tResult, genQueryOut->sqlResult[i].len );
                }
            }
        }
    }
    else {
        rodsLog( LOG_ERROR, "msiDigestMonStat: Unable to retrieve information \
                        from R_SERVER_LOAD" );
        return rei->status;
    }

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_SL_CPU_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_MEM_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_SWAP_USED, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_RUNQ_LOAD, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_DISK_SPACE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_NET_INPUT, 1 );
    addInxIval( &genQueryInp.selectInp, COL_SL_NET_OUTPUT, 1 );
    genQueryInp.maxRows = 1;
    generalRowInsertInp.tableName = "serverloaddigest";
    for ( i = 0; i < nresc; i++ ) {
        memset( &genQueryInp.sqlCondInp, 0, sizeof( genQueryInp.sqlCondInp ) );
        snprintf( condStr1, MAX_NAME_LEN, "= '%s'", rescList[i] );
        addInxVal( &genQueryInp.sqlCondInp, COL_SL_RESC_NAME, condStr1 );
        snprintf( condStr2, MAX_NAME_LEN, "= '%s'", timeList[i] );
        addInxVal( &genQueryInp.sqlCondInp, COL_SL_CREATE_TIME, condStr2 );
        status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            loadFactor = 0;
            for ( j = 0; j < genQueryOut->attriCnt; j++ ) {
                tResult = genQueryOut->sqlResult[j].value;
                loadFactor += atoi( tResult ) * weight[j];
            }
            loadFactor = loadFactor / totalWeight;
            generalRowInsertInp.arg1 = rescList[i];
            snprintf( loadStr, MAX_NAME_LEN, "%i", loadFactor );
            generalRowInsertInp.arg2 = loadStr;
            rc = rsGeneralRowInsert( rsComm, &generalRowInsertInp );
            if ( rc != 0 ) {
                rodsLog( LOG_ERROR, "msiDigestMonStat: Unable to ingest\
        information into from R_SERVER_LOAD_DIGEST table" );
            }
        }
Example #9
0
int
myS3Init (void)
{
    int status = -1;
    char *tmpPtr;

    if (S3Initialized) return 0;

    S3Initialized = 1;

#ifdef libs3_3_1_4
    if ((status = S3_initialize ("s3", S3_INIT_ALL)) != S3StatusOK) {
#else
    if ((status = S3_initialize ("s3", S3_INIT_ALL, NULL)) != S3StatusOK) {
#endif
        status = myS3Error (status, S3_INIT_ERROR);
    }

    bzero (&S3Auth, sizeof (S3Auth));

    if ((tmpPtr = getenv("S3_ACCESS_KEY_ID")) != NULL) {
	rstrcpy (S3Auth.accessKeyId, tmpPtr, MAX_NAME_LEN);
        if ((tmpPtr = getenv("S3_SECRET_ACCESS_KEY")) != NULL) {
	    rstrcpy (S3Auth.secretAccessKey, tmpPtr, MAX_NAME_LEN);
	    return 0;
	}
    }

    if ((status = readS3AuthInfo ()) < 0) {
        rodsLog (LOG_ERROR,
          "initHpssAuth: readHpssAuthInfo error. status = %d", status);
        return status;
    }

    return status;
}

int
readS3AuthInfo (void)
{
    FILE *fptr;
    char s3AuthFile[MAX_NAME_LEN];
    char inbuf[MAX_NAME_LEN];
    int lineLen, bytesCopied;
    int linecnt = 0;

    snprintf (s3AuthFile, MAX_NAME_LEN, "%-s/%-s",
      getConfigDir(), S3_AUTH_FILE);

    fptr = fopen (s3AuthFile, "r");

    if (fptr == NULL) {
        rodsLog (LOG_ERROR,
          "readS3AuthInfo: open S3_AUTH_FILE file %s err. ernro = %d",
          s3AuthFile, errno);
        return (SYS_CONFIG_FILE_ERR);
    }
    while ((lineLen = getLine (fptr, inbuf, MAX_NAME_LEN)) > 0) {
        char *inPtr = inbuf;
        if (linecnt == 0) {
            while ((bytesCopied = getStrInBuf (&inPtr, 
	      S3Auth.accessKeyId, &lineLen, LONG_NAME_LEN)) > 0) {
                linecnt ++;
                break;
            }
        } else if (linecnt == 1) {
            while ((bytesCopied = getStrInBuf (&inPtr, 
	      S3Auth.secretAccessKey, &lineLen, LONG_NAME_LEN)) > 0) {
                linecnt ++;
                break;
            }
        }
    }
    if (linecnt != 2)  {
        rodsLog (LOG_ERROR,
          "readS3AuthInfo: read %d lines in S3_AUTH_FILE file",
          linecnt);
        return (SYS_CONFIG_FILE_ERR);
    }
    return 0;
}
Example #10
0
int getListOfResc( rsComm_t *rsComm, char serverList[MAX_VALUE][MAX_NAME_LEN], int nservers,
                   monInfo_t monList[MAX_NSERVERS], int *nlist ) {
    /**********************************************************
     * search in the database, the list of resources with      *
     * their associated server. If config file exist, restrict *
     * the list to serverList                                  *
     ***********************************************************/
    int i, j, k, index[MAX_NSERVERS], l, status;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    char condStr[MAX_NAME_LEN];

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    memset( &index, -1, MAX_NSERVERS * sizeof( int ) );
    genQueryInp.maxRows = MAX_SQL_ROWS;

    //clearGenQueryInp( &genQueryInp );
    addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_LOC, "!='EMPTY_RESC_HOST'" );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_VAULT_PATH, "!='EMPTY_RESC_PATH'" );
    snprintf( condStr, MAX_NAME_LEN, "!='%s'", BUNDLE_RESC );
    addInxVal( &genQueryInp.sqlCondInp, COL_R_RESC_NAME, condStr );

    status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
    if ( status < 0 ) {
        irods::log( ERROR( status, "rsGenQuery failed." ) );
    }
    if ( genQueryOut->rowCnt > 0 ) {
        l = 0;
        for ( i = 0; i < genQueryOut->attriCnt; i++ ) {
            for ( j = 0; j < genQueryOut->rowCnt; j++ ) {
                char *tResult;
                tResult = genQueryOut->sqlResult[i].value;
                tResult += j * genQueryOut->sqlResult[i].len;
                switch ( i ) {
                case 0:
                    if ( nservers >= 0 ) {
                        for ( k = 0; k < nservers; k++ ) {
                            if ( strcmp( serverList[k], tResult ) == 0 ) {
                                index[j] = l;
                                l++;
                            }
                        }
                    }
                    else {
                        index[j] = l;
                        l++;
                    }
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].serverName, tResult, LONG_NAME_LEN );
                    }
                    break;
                case 1:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].rescName, tResult, MAX_NAME_LEN );
                    }
                    break;
                case 2:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].rescType, tResult, LONG_NAME_LEN );
                    }
                    break;
                case 3:
                    if ( index[j] != -1 ) {
                        rstrcpy( monList[index[j]].vaultPath, tResult, LONG_NAME_LEN );
                    }
                    break;
                }
            }
        }
        ( *nlist ) = l;
        clearGenQueryInp( &genQueryInp );
        freeGenQueryOut( &genQueryOut );
        return 0;
    }
    return -1;
}
Example #11
0
/**
 * \fn msiServerMonPerf (msParam_t *verb, msParam_t *ptime, ruleExecInfo_t *rei)
 *
 * \brief  This microservice monitors the servers' activity and performance.
 *
 * \module core
 *
 * \since pre-2.1
 *
 * \author Jean-Yves Nief
 * \date 2009-06
 *
 * \note  This microservice monitors the servers' activity and performance
 *    for CPU, network, memory and more.  It retrieves the list of servers
 *    to monitor from the MON_CFG_FILE if it exists, or the iCAT if the
 *    configuration file does not exist.
 *
 * \note The MON_PERF_SCRIPT is executed on each host. The result is put
 *    in the OUTPUT_MON_PERF file and will also be put in the iCAT in the
 *    near future.
 *
 * \usage See clients/icommands/test/rules3.0/ and https://wiki.irods.org/index.php/Resource_Monitoring_System
 *
 * \param[in] verb - a msParam of type STR_MS_T defining verbose mode:
 *    \li "default" - not verbose
 *    \li "verbose" - verbose mode
 * \param[in] ptime - a msParam of type STR_MS_T defining probe time
 *    in seconds. "default" is equal to 10 seconds.
 * \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 resource status flag, resource free space available,
 table R_SERVER_LOAD
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre N/A
 * \post N/A
 * \sa N/A
 **/
int msiServerMonPerf( msParam_t *verb, msParam_t *ptime, ruleExecInfo_t *rei ) {
    char line[MAX_VALUE], *verbosity;
    char serverList[MAX_VALUE][MAX_NAME_LEN];
    char cmd[MAX_NAME_LEN]; /* cmd => name of the Perl script */
    char probtime[LEN_SECONDS], measTime[LEN_SECONDS];
    FILE *filein; /* file pointers */
    const char *delim = " \n";
    char valinit[MAX_NAME_LEN] = "";
    char val[MAX_NAME_LEN] = ""; /* val => arguments for the script */
    int check, i, indx, j, looptime, maxtime, nresc, nservers, thrCount, threadsNotfinished;
    const char *probtimeDef = "10"; /* default value used by the monitoring script for the amount
                                       of time for this measurement (in s) */
    rsComm_t *rsComm;
    monInfo_t rescList[MAX_NSERVERS];
    thrInp_t *thrInput;
    int addPathToArgv = 0;
    char *hintPath = "";

    RE_TEST_MACRO( "    Calling msiServerMonPerf" )

    /* the above line is needed for loop back testing using irule -i option */

    rsComm = rei->rsComm;

    if ( verb->inOutStruct != NULL ) {
        verbosity = ( char * ) verb->inOutStruct;
        if ( strcmp( verbosity, "verbose" ) == 0 ) {
            strcat( valinit, "-v " );
        }
    }

    strcat( valinit, " -t " );

    strncpy( probtime, ( char * ) ptime->inOutStruct,  LEN_SECONDS );
    if ( atoi( probtime ) > 0 ) {
        strcat( valinit, probtime );
        strncpy( measTime, probtime, LEN_SECONDS );
    }
    else {
        strcat( valinit, probtimeDef );
        strncpy( measTime, probtimeDef, LEN_SECONDS );
    }

    rstrcpy( val, "", MAX_NAME_LEN );

    /* read the config file or the iCAT to know the servers list to monitor */
    nresc = 0;

    nservers = -1;  /* nservers = -1, no config file available, consider all ressources for the monitoring */
    /* nservers >= 0, config file available, consider all resources hosted on the list of servers */
    if ( ( filein = fopen( MON_CFG_FILE, "r" ) ) != NULL ) {
        i = 0;
        while ( fgets( line, sizeof line, filein ) != NULL ) { /* for each line of the file */
            /* if begin of line = # => ignore */
            if ( line[0] != '#' ) {
                std::vector<std::string> tokens;
                boost::algorithm::split( tokens, line, boost::is_any_of( delim ) );
                snprintf( serverList[i], MAX_NAME_LEN, "%s", tokens[0].c_str() );
                i++;
            }
        }
        /* number of servers... useful for the threads */
        nservers = i;
        /* close the configuration file */
        fclose( filein );
    }
    getListOfResc( rsComm, serverList, nservers, rescList, &nresc );

    strcpy( cmd, MON_PERF_SCRIPT );
#ifndef windows_platform
    pthread_t *threads = ( pthread_t* )malloc( sizeof( pthread_t ) * nresc );
    pthread_mutex_init( &my_mutex, NULL );
#endif
    thrInput = ( thrInp_t* )malloc( sizeof( thrInp_t ) * nresc );
    thrCount = 0;

    for ( i = 0; i < nresc; i++ ) {
        /* for each server, build the proxy command to be executed.
           it will be put in a thrInp structure to be given to the thread.
           then start one thread for each server to be monitored */
        check = 0;
        indx = 0;
        for ( j = 0; j < thrCount; j++ ) {
            if ( strcmp( thrInput[j].execAddr, rescList[i].serverName ) == 0 ) {
                indx = j;
                check = 1;
            }
        }
        if ( check == 0 ) {
            strcpy( thrInput[thrCount].cmdArgv, valinit );
            strcat( thrInput[thrCount].cmdArgv, " -fs " );
            if ( strcmp( rescList[thrCount].rescType, "unixfilesystem" ) == 0 ) {
                strcat( thrInput[thrCount].cmdArgv, rescList[i].vaultPath );
            }
            else {
                strcat( thrInput[thrCount].cmdArgv, "none" );
            }
            rstrcpy( thrInput[thrCount].cmd, cmd, LONG_NAME_LEN );
            rstrcpy( thrInput[thrCount].execAddr, rescList[i].serverName, LONG_NAME_LEN );
            rstrcpy( thrInput[thrCount].hintPath, hintPath, MAX_NAME_LEN );
            thrInput[thrCount].addPathToArgv = addPathToArgv;
            thrInput[thrCount].threadId = thrCount;
            rstrcpy( thrInput[thrCount].rescName, rescList[i].rescName, MAX_NAME_LEN );
            memcpy( &( thrInput[thrCount].rei ), rei, sizeof( ruleExecInfo_t ) );
            thrCount += 1;
        }
        else {
            rstrcat( thrInput[indx].rescName, ",", MAX_NAME_LEN );
            rstrcat( thrInput[indx].rescName, rescList[i].rescName, MAX_NAME_LEN );
            if ( strcmp( rescList[i].rescType, "unixfilesystem" ) == 0 ) {
                strcat( thrInput[indx].cmdArgv, "," );
                strcat( thrInput[indx].cmdArgv, rescList[i].vaultPath );
            }
            else {
                strcat( thrInput[indx].cmdArgv, ",none" );
            }
        }
        rstrcpy( val, "", MAX_NAME_LEN );
    }

    for ( i = 0; i < thrCount; i++ ) {
#ifndef windows_platform
        if ( pthread_create( &threads[i], NULL, *startMonScript, ( void * ) &thrInput[i] ) < 0 ) {
            rodsLog( LOG_ERROR, "msiServerMonPerf: pthread_create error\n" );
            exit( 1 );
        }
#endif
    }

    maxtime = atoi( measTime ) + TIMEOUT;
    looptime = 0;
    while ( 1 ) {
        sleep( 1 );
        looptime += 1;
        if ( looptime >= maxtime ) {
            for ( i = 0; i < thrCount; i++ ) {
                if ( !threadIsAlive[i] ) {
#ifndef windows_platform
                    int rc = pthread_cancel( threads[i] );
                    if ( rc == 0 ) {
                        char noanswer[MAXSTR] = MON_OUTPUT_NO_ANSWER;
                        threadIsAlive[i] = 1;
                        rodsMonPerfLog( thrInput[i].execAddr,
                                        thrInput[i].rescName,
                                        noanswer,
                                        &( thrInput[i].rei ) );
                    }
#endif
                }
            }
        }
        threadsNotfinished = 1;
        for ( i = 0; i < thrCount; i++ ) {
            if ( threadIsAlive[i] == 0 ) {
                threadsNotfinished = 0;
            }
        }
        if ( threadsNotfinished ) {
            break;
        }
    }

#ifndef windows_platform
    free( threads );
#endif
    free( thrInput );

    return rei->status;

}
Example #12
0
int _ifuseFileCacheWrite( fileCache_t *fileCache, char *buf, size_t size, off_t offset ) {
    int status, myError;
    openedDataObjInp_t dataObjWriteInp;
    bytesBuf_t dataObjWriteInpBBuf;
    iFuseConn_t *conn;

    bzero( &dataObjWriteInp, sizeof( dataObjWriteInp ) );
    /* lseek to the right offset in case this cache is share by multiple descs */
    status = _iFuseFileCacheLseek( fileCache, offset );
    if ( status < 0 ) {
        if ( ( myError = getErrno( status ) ) > 0 ) {
            return -myError;
        }
        else {
            return -ENOENT;
        }
    }


    if ( fileCache->state == NO_FILE_CACHE ) {
        /* no file cache */
        dataObjWriteInpBBuf.buf = ( void * ) buf;
        dataObjWriteInpBBuf.len = size;
        dataObjWriteInp.l1descInx = fileCache->iFd;
        dataObjWriteInp.len = size;

        conn = getAndUseConnByPath( fileCache->localPath, &status );
        status = rcDataObjWrite( conn->conn, &dataObjWriteInp, &dataObjWriteInpBBuf );
        unuseIFuseConn( conn );
        if ( status < 0 ) {
            if ( ( myError = getErrno( status ) ) > 0 ) {
                return -myError;
            }
            else {
                return -ENOENT;
            }
        }
        else if ( status != ( int ) size ) {
            rodsLog( LOG_ERROR,
                     "ifuseWrite: IFuseDesc[descInx].conn for %s is NULL", fileCache->localPath );
            return -ENOENT;
        }
        fileCache->offset += status;
        if ( fileCache->offset > fileCache->fileSize ) {
            fileCache->fileSize = fileCache->offset;
        }
    }
    else {
        status = write( fileCache->iFd, buf, size );
        if ( status < 0 ) {
            return errno ? ( -1 * errno ) : -1;
        }
        fileCache->offset += status;
        if ( fileCache->offset > fileCache->fileSize ) {
            fileCache->fileSize = fileCache->offset;
        }
        if ( fileCache->offset >= MAX_NEWLY_CREATED_CACHE_SIZE ) {
            _iFuseFileCacheFlush( fileCache );
            fileCache->iFd = 0;
            /* reopen file */
            dataObjInp_t dataObjOpenInp;
            memset( &dataObjOpenInp, 0, sizeof( dataObjOpenInp ) );
            rstrcpy( dataObjOpenInp.objPath, fileCache->objPath, MAX_NAME_LEN );
            dataObjOpenInp.openFlags = O_RDWR;

            int status;
            conn = getAndUseConnByPath( fileCache->localPath, &status );
            status = rcDataObjOpen( conn->conn, &dataObjOpenInp );
            unuseIFuseConn( conn );

            if ( status < 0 ) {
                rodsLog( LOG_ERROR, "iFuseWrite: rcDataObjOpen of %s error. status = %d", fileCache->objPath, status );
                return -ENOENT;
            }

            fileCache->iFd = status;
        }
    }
    return status;
}
static int
_findOldestCache(const char *path, char *oldCachePath, struct stat *oldStatbuf) {
    int status;    
    DIR *dir = NULL;
    char filepath[MAX_NAME_LEN];
    char tempPath[MAX_NAME_LEN];
    struct stat tempStatBuf;
    char oldestCachePath[MAX_NAME_LEN];
    struct stat oldestStatBuf;
    struct dirent *entry;
    struct stat statbuf;

    memset(oldestCachePath, 0, MAX_NAME_LEN);
    memset(&oldestStatBuf, 0, sizeof(struct stat));

    dir = opendir(path);
    if (dir != NULL) {
        while ((entry = readdir(dir)) != NULL) {
            if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
                continue;
            }

            snprintf(filepath, MAX_NAME_LEN, "%s/%s", path, entry->d_name);
            
            if (!stat(filepath, &statbuf)) {
                // has entry
                if (S_ISDIR(statbuf.st_mode)) {
                    // directory
                    status = _findOldestCache(filepath, tempPath, &tempStatBuf);
                    if (status == 0) {
                        if (strlen(oldestCachePath) == 0) {
                            // just set
                            rstrcpy (oldestCachePath, tempPath, MAX_NAME_LEN);
                            memcpy (&oldestStatBuf, &tempStatBuf, sizeof(struct stat));
                        } else {
                            // compare
                            if(oldestStatBuf.st_atime > tempStatBuf.st_atime) {
                                rstrcpy (oldestCachePath, tempPath, MAX_NAME_LEN);
                                memcpy (&oldestStatBuf, &tempStatBuf, sizeof(struct stat));                                
                            }
                        }           
                    }
                } else {
                    // file
                    if (strlen(oldestCachePath) == 0) {
                        // just set
                        rstrcpy (oldestCachePath, filepath, MAX_NAME_LEN);
                        memcpy (&oldestStatBuf, &statbuf, sizeof(struct stat));
                    } else {
                        // compare
                        if(oldestStatBuf.st_atime > statbuf.st_atime) {
                            rstrcpy (oldestCachePath, filepath, MAX_NAME_LEN);
                            memcpy (&oldestStatBuf, &statbuf, sizeof(struct stat));                                
                        }
                    }
                }
            }
        }
        closedir(dir);
    }

    if (strlen(oldestCachePath) == 0) {
        return -1;
    }

    rstrcpy (oldCachePath, oldestCachePath, MAX_NAME_LEN);
    memcpy (oldStatbuf, &oldestStatBuf, sizeof(struct stat));

    return (0);
}
static int
_download(const char *path, struct stat *stbufIn) {
    int status;
    rcComm_t *conn;
    rodsPathInp_t rodsPathInp;
    rErrMsg_t errMsg;
    char preloadCachePath[MAX_NAME_LEN];
    char preloadCacheWorkPath[MAX_NAME_LEN];

    // set path for getUtil
    status = _getCachePath(path, preloadCachePath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _getCachePath error.");
        rodsLog (LOG_ERROR, "_download: failed to get cache path - %s", path);
        return status;
    }

    status = _getCacheWorkPath(path, preloadCacheWorkPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _getCacheWorkPath error.");
        rodsLog (LOG_ERROR, "_download: failed to get cache work path - %s", path);
        return status;
    }

    rodsLog (LOG_DEBUG, "_download: download %s to %s", path, preloadCachePath);

    // set src path
    memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) );
    addSrcInPath( &rodsPathInp, (char*)path );
    status = parseRodsPath (&rodsPathInp.srcPath[0], PreloadRodsEnv);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: parseRodsPath error.");
        return status;
    }

    // set dest path
    rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) );
    memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) );
    rstrcpy( rodsPathInp.destPath->inPath, preloadCacheWorkPath, MAX_NAME_LEN );
    status = parseLocalPath (rodsPathInp.destPath);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: parseLocalPath error.");
        return status;
    }

    // Connect
    conn = rcConnect (PreloadRodsEnv->rodsHost, PreloadRodsEnv->rodsPort, PreloadRodsEnv->rodsUserName, PreloadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg);
    if (conn == NULL) {
        rodsLog (LOG_ERROR, "_download: error occurred while connecting to irods");
        return -EPIPE;
    }

    // Login
    if (strcmp (PreloadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { 
        status = clientLogin(conn);
        if (status != 0) {
            rodsLogError(LOG_ERROR, status, "_download: ClientLogin error.");
            rcDisconnect(conn);
            return status;
        }
    }

    // make dir
    prepareDir(preloadCachePath);

    // Preload
    rodsLog (LOG_DEBUG, "_download: download %s", path);
    status = getUtil (&conn, PreloadRodsEnv, PreloadRodsArgs, &rodsPathInp);
    rodsLog (LOG_DEBUG, "_download: complete downloading %s", path);

    // Disconnect 
    rcDisconnect(conn);

    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: getUtil error.");
        return status;
    }

    // be careful when using Lock
    LOCK(PreloadLock);
    status = _completeDownload(preloadCacheWorkPath, preloadCachePath, stbufIn);
    if(status < 0) {
        rodsLogError(LOG_ERROR, status, "_download: _completeDownload error.");
        UNLOCK(PreloadLock);
        return status;
    }

    UNLOCK(PreloadLock);
    return 0;
}
Example #15
0
int
rsSendXmsg (rsComm_t *rsComm, sendXmsgInp_t *sendXmsgInp)
{
  int status, i;
    ticketMsgStruct_t *ticketMsgStruct = NULL;
    irodsXmsg_t *irodsXmsg;
    char *miscInfo;

    status = getTicketMsgStructByTicket (sendXmsgInp->ticket.rcvTicket, 
      &ticketMsgStruct);

    if (status < 0) {
	clearSendXmsgInfo (&sendXmsgInp->sendXmsgInfo);
	return status;
    }

    /* match sendTicket */
    if (ticketMsgStruct->ticket.sendTicket != sendXmsgInp->ticket.sendTicket) {
	/* unmatched sendTicket */
	rodsLog (LOG_ERROR,
	  "rsSendXmsg: sendTicket mismatch, input %d, in cache %d",
	    sendXmsgInp->ticket.sendTicket, ticketMsgStruct->ticket.sendTicket);
	return (SYS_UNMATCHED_XMSG_TICKET);
    }

    /* added by Raja Jun 30, 2010 for dropping and clearing a messageStream */
    miscInfo = sendXmsgInp->sendXmsgInfo.miscInfo;
    if (miscInfo != NULL && strlen(miscInfo) > 0) {
      if(!strcmp(miscInfo,"CLEAR_STREAM")) {
	i = clearAllXMessages(ticketMsgStruct);
	return(i);
      }
      else if (!strcmp(miscInfo,"DROP_STREAM")) {
	if(sendXmsgInp->ticket.rcvTicket > 5) {
	  i = clearAllXMessages(ticketMsgStruct);
	  if (i < 0) return (i);
	  i = rmTicketMsgStructFromHQue (ticketMsgStruct,
					 (ticketHashQue_t *) ticketMsgStruct->ticketHashQue);
	  return(i);
	}
      }
      else if (!strcmp(miscInfo,"ERASE_MESSAGE")) {
	/* msgNumber actually is the sequence Number in the queue*/
	i = clearOneXMessage(ticketMsgStruct, sendXmsgInp->sendXmsgInfo.msgNumber);
	return(i);
      }
    }

    /* create a irodsXmsg_t */

    irodsXmsg = (irodsXmsg_t*)calloc (1, sizeof (irodsXmsg_t));
    irodsXmsg->sendXmsgInfo = (sendXmsgInfo_t*)calloc (1, sizeof (sendXmsgInfo_t));
    *irodsXmsg->sendXmsgInfo = sendXmsgInp->sendXmsgInfo;
    irodsXmsg->sendTime = time (0);
    /*    rstrcpy (irodsXmsg->sendUserName, rsComm->clientUser.userName, NAME_LEN);*/
    snprintf(irodsXmsg->sendUserName,NAME_LEN,"%s@%s",rsComm->clientUser.userName,rsComm->clientUser.rodsZone);
    rstrcpy (irodsXmsg->sendAddr,sendXmsgInp->sendAddr, NAME_LEN);
    /*** moved to xmsgLib.c RAJA Nov 29 2010 ***
    addXmsgToXmsgQue (irodsXmsg, &XmsgQue);
    status = addXmsgToTicketMsgStruct (irodsXmsg, ticketMsgStruct);
    ***  moved to xmsgLib.c RAJA Nov 29 2010 ***/
    status = addXmsgToQues(irodsXmsg,  ticketMsgStruct);
    return (status);
}
Example #16
0
int
statPathInSpecColl( rsComm_t *rsComm, char *objPath,
                    int inCachOnly, rodsObjStat_t **rodsObjStatOut ) {
    int status;
    dataObjInfo_t *dataObjInfo = NULL;
    specColl_t *specColl;
    specCollCache_t *specCollCache;

    if ( ( status = getSpecCollCache( rsComm, objPath, inCachOnly,
                                      &specCollCache ) ) < 0 ) {
        if ( status != SYS_SPEC_COLL_NOT_IN_CACHE &&
                status != CAT_NO_ROWS_FOUND ) {
            rodsLog( LOG_ERROR,
                     "statPathInSpecColl: getSpecCollCache for %s, status = %d",
                     objPath, status );
        }
        return status;
    }

    if ( *rodsObjStatOut == NULL ) {
        *rodsObjStatOut = ( rodsObjStat_t * ) malloc( sizeof( rodsObjStat_t ) );
    }
    memset( *rodsObjStatOut, 0, sizeof( rodsObjStat_t ) );
    specColl = &specCollCache->specColl;
    rstrcpy( ( *rodsObjStatOut )->dataId, specCollCache->collId, NAME_LEN );
    rstrcpy( ( *rodsObjStatOut )->ownerName, specCollCache->ownerName, NAME_LEN );
    rstrcpy( ( *rodsObjStatOut )->ownerZone, specCollCache->ownerZone, NAME_LEN );

    status = specCollSubStat( rsComm, specColl, objPath, UNKNOWN_COLL_PERM, &dataObjInfo );

    if ( status < 0 ) {
        if ( dataObjInfo != NULL ) {
            if ( dataObjInfo->specColl != NULL ) {
                ( *rodsObjStatOut )->specColl = dataObjInfo->specColl;
            }
            else {
                replSpecColl( &specCollCache->specColl,
                              &( *rodsObjStatOut )->specColl );
            }
            if ( specColl->collClass == LINKED_COLL ) {
                rstrcpy( ( *rodsObjStatOut )->specColl->objPath,
                         dataObjInfo->objPath, MAX_NAME_LEN );
            }
            else {
                ( *rodsObjStatOut )->specColl->objPath[0] = '\0';
            }
            dataObjInfo->specColl = NULL;
        }
        ( *rodsObjStatOut )->objType = UNKNOWN_OBJ_T;
        rstrcpy( ( *rodsObjStatOut )->createTime, specCollCache->createTime,
                 TIME_LEN );
        rstrcpy( ( *rodsObjStatOut )->modifyTime, specCollCache->modifyTime,
                 TIME_LEN );
        freeAllDataObjInfo( dataObjInfo );
        /* XXXXX 0 return is creating a problem for fuse */
        return 0;
    }
    else {
        ( *rodsObjStatOut )->specColl = dataObjInfo->specColl;
        dataObjInfo->specColl = NULL;

        if ( specColl->collClass == LINKED_COLL ) {
            rstrcpy( ( *rodsObjStatOut )->ownerName, dataObjInfo->dataOwnerName,
                     NAME_LEN );
            rstrcpy( ( *rodsObjStatOut )->ownerZone, dataObjInfo->dataOwnerZone,
                     NAME_LEN );
            snprintf( ( *rodsObjStatOut )->dataId, NAME_LEN, "%lld",
                      dataObjInfo->dataId );
            /* save the linked path here */
            rstrcpy( ( *rodsObjStatOut )->specColl->objPath,
                     dataObjInfo->objPath, MAX_NAME_LEN );
        }
        ( *rodsObjStatOut )->objType = ( objType_t )status;
        ( *rodsObjStatOut )->objSize = dataObjInfo->dataSize;
        rstrcpy( ( *rodsObjStatOut )->createTime, dataObjInfo->dataCreate,
                 TIME_LEN );
        rstrcpy( ( *rodsObjStatOut )->modifyTime, dataObjInfo->dataModify,
                 TIME_LEN );
        freeAllDataObjInfo( dataObjInfo );
    }

    return status;
}
Example #17
0
int
getDataObjUtil (rcComm_t *conn, char *srcPath, char *targPath,
rodsLong_t srcSize, uint dataMode, rodsEnv *myRodsEnv, 
rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp)
{
    int status;
    struct timeval startTime, endTime;
 
    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "getDataObjUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    if (conn->fileRestart.info.status == FILE_RESTARTED &&
      strcmp (conn->fileRestart.info.objPath, srcPath) == 0) {
        /* it was restarted */
        conn->fileRestart.info.status = FILE_NOT_RESTART;
        return 0;
    }

    if (rodsArgs->verbose == True) {
        (void) gettimeofday(&startTime, (struct timezone *)0);
    }

    if (gGuiProgressCB != NULL) {
	rstrcpy (conn->operProgress.curFileName, srcPath, MAX_NAME_LEN);
	conn->operProgress.curFileSize = srcSize;
	conn->operProgress.curFileSizeDone = 0;
	conn->operProgress.flag = 0;
	gGuiProgressCB (&conn->operProgress); 
    }

    rstrcpy (dataObjOprInp->objPath, srcPath, MAX_NAME_LEN);
    /* rcDataObjGet verifies dataSize if given */
    if (rodsArgs->replNum == True || rodsArgs->resource == True) {
	/* don't verify because it may be an old copy and hence the size  
	 * could be wrong */
	dataObjOprInp->dataSize = 0;
    } else {
        dataObjOprInp->dataSize = srcSize;
    }

    status = rcDataObjGet (conn, dataObjOprInp, targPath);

    if (status >= 0) {
        /* old objState use numCopies in place of dataMode.
         * Just a sanity check */
	myChmod (targPath, dataMode);
	if (rodsArgs->verbose == True) {
            (void) gettimeofday(&endTime, (struct timezone *)0);
            printTiming (conn, dataObjOprInp->objPath, srcSize, targPath,
             &startTime, &endTime);
	}
        if (gGuiProgressCB != NULL) {
	    conn->operProgress.totalNumFilesDone++;
	    conn->operProgress.totalFileSizeDone += srcSize;
	}
    }

    return (status);
}
Example #18
0
int
specCollSubStat( rsComm_t *rsComm, specColl_t *specColl,
                 char *subPath, specCollPerm_t specCollPerm, dataObjInfo_t **dataObjInfo ) {
    int status;
    int objType;
    rodsStat_t *rodsStat = NULL;
    dataObjInfo_t *myDataObjInfo = NULL;;

    if ( dataObjInfo == NULL ) {
        return USER__NULL_INPUT_ERR;
    }
    *dataObjInfo = NULL;

    if ( specColl->collClass == MOUNTED_COLL ) {
        /* a mount point */
        myDataObjInfo = *dataObjInfo = ( dataObjInfo_t * ) malloc( sizeof( dataObjInfo_t ) );

        memset( myDataObjInfo, 0, sizeof( dataObjInfo_t ) );

        /*status = resolveResc (specColl->resource, &myDataObjInfo->rescInfo);
        if (status < 0) {
            rodsLog( LOG_ERROR,"specCollSubStat: resolveResc error for %s, status = %d",
                     specColl->resource, status);
            freeDataObjInfo (myDataObjInfo);
            *dataObjInfo = NULL;
            return status;
        }*/

        rstrcpy( myDataObjInfo->objPath, subPath, MAX_NAME_LEN );
        rstrcpy( myDataObjInfo->subPath, subPath, MAX_NAME_LEN );
        rstrcpy( myDataObjInfo->rescName, specColl->resource, NAME_LEN );
        rstrcpy( myDataObjInfo->rescHier, specColl->rescHier, MAX_NAME_LEN );
        rstrcpy( myDataObjInfo->dataType, "generic", NAME_LEN );

        status = getMountedSubPhyPath( specColl->collection,
                                       specColl->phyPath, subPath, myDataObjInfo->filePath );
        if ( status < 0 ) {
            freeDataObjInfo( myDataObjInfo );
            *dataObjInfo = NULL;
            return status;
        }
        replSpecColl( specColl, &myDataObjInfo->specColl );
    }
    else if ( specColl->collClass == LINKED_COLL ) {

        /* a link point */
        specCollCache_t *specCollCache = NULL;
        char newPath[MAX_NAME_LEN];
        specColl_t *curSpecColl;
        char *accessStr;
        dataObjInp_t myDataObjInp;
        rodsObjStat_t *rodsObjStatOut = NULL;

        *dataObjInfo = NULL;
        curSpecColl = specColl;

        status = getMountedSubPhyPath( curSpecColl->collection,
                                       curSpecColl->phyPath, subPath, newPath );
        if ( status < 0 ) {
            return status;
        }

        status = resolveLinkedPath( rsComm, newPath, &specCollCache, NULL );
        if ( status < 0 ) {
            return status;
        }
        if ( specCollCache != NULL &&
                specCollCache->specColl.collClass != LINKED_COLL ) {

            status = specCollSubStat( rsComm, &specCollCache->specColl,
                                      newPath, specCollPerm, dataObjInfo );
            return status;
        }
        bzero( &myDataObjInp, sizeof( myDataObjInp ) );
        rstrcpy( myDataObjInp.objPath, newPath, MAX_NAME_LEN );

        status = collStat( rsComm, &myDataObjInp, &rodsObjStatOut );
        if ( status >= 0 && NULL != rodsObjStatOut ) {      /* a collection */ // JMC cppcheck - nullptr
            myDataObjInfo = *dataObjInfo =
                                ( dataObjInfo_t * ) malloc( sizeof( dataObjInfo_t ) );
            memset( myDataObjInfo, 0, sizeof( dataObjInfo_t ) );
            replSpecColl( curSpecColl, &myDataObjInfo->specColl );
            rstrcpy( myDataObjInfo->objPath, newPath, MAX_NAME_LEN );
            myDataObjInfo->dataId = strtoll( rodsObjStatOut->dataId, 0, 0 );
            rstrcpy( myDataObjInfo->dataOwnerName, rodsObjStatOut->ownerName, NAME_LEN );
            rstrcpy( myDataObjInfo->dataOwnerZone, rodsObjStatOut->ownerZone, NAME_LEN );
            rstrcpy( myDataObjInfo->dataCreate,    rodsObjStatOut->createTime, TIME_LEN );
            rstrcpy( myDataObjInfo->dataModify,    rodsObjStatOut->modifyTime, TIME_LEN );
            freeRodsObjStat( rodsObjStatOut );
            return COLL_OBJ_T;
        }
        freeRodsObjStat( rodsObjStatOut );

        /* data object */
        if ( specCollPerm == READ_COLL_PERM ) {
            accessStr = ACCESS_READ_OBJECT;
        }
        else if ( specCollPerm == WRITE_COLL_PERM ) {
            accessStr = ACCESS_DELETE_OBJECT;
        }
        else {
            accessStr = NULL;
        }

        status = getDataObjInfo( rsComm, &myDataObjInp, dataObjInfo,
                                 accessStr, 0 );
        if ( status < 0 ) {
            myDataObjInfo = *dataObjInfo =
                                ( dataObjInfo_t * ) malloc( sizeof( dataObjInfo_t ) );
            memset( myDataObjInfo, 0, sizeof( dataObjInfo_t ) );
            replSpecColl( curSpecColl, &myDataObjInfo->specColl );
            rstrcpy( myDataObjInfo->objPath, newPath, MAX_NAME_LEN );
            rodsLog( LOG_DEBUG,
                     "specCollSubStat: getDataObjInfo error for %s, status = %d",
                     newPath, status );
            return status;
        }
        else {
            replSpecColl( curSpecColl, &( *dataObjInfo )->specColl );
            return DATA_OBJ_T;
        }
    }
    else if ( getStructFileType( specColl ) >= 0 ) {

        /* bundle */
        dataObjInp_t myDataObjInp;
        dataObjInfo_t *tmpDataObjInfo;

        bzero( &myDataObjInp, sizeof( myDataObjInp ) );
        rstrcpy( myDataObjInp.objPath, specColl->objPath, MAX_NAME_LEN );
        // add the resource hierarchy to the condInput of the inp
        addKeyVal( &myDataObjInp.condInput, RESC_HIER_STR_KW, specColl->rescHier );
        status = getDataObjInfo( rsComm, &myDataObjInp, dataObjInfo, NULL, 1 );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "specCollSubStat: getDataObjInfo error for %s, status = %d",
                     myDataObjInp.objPath, status );
            *dataObjInfo = NULL;
            return status;
        }

        /* screen out any stale copies */
        status = sortObjInfoForOpen( dataObjInfo, &myDataObjInp.condInput, 0 );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "specCollSubStat: sortObjInfoForOpen error for %s. status = %d",
                     myDataObjInp.objPath, status );
            return status;
        }

        if ( strlen( specColl->resource ) > 0 ) {
            if ( requeDataObjInfoByResc( dataObjInfo, specColl->resource,
                                         0, 1 ) >= 0 ) {
                if ( strcmp( specColl->resource,
                             ( *dataObjInfo )->rescName ) != 0 ) {
                    rodsLog( LOG_ERROR,
                             "specCollSubStat: %s in %s does not match cache resc %s",
                             myDataObjInp.objPath, ( *dataObjInfo )->rescName,
                             specColl->resource );
                    freeAllDataObjInfo( *dataObjInfo );
                    *dataObjInfo = NULL;
                    return SYS_CACHE_STRUCT_FILE_RESC_ERR;
                }
            }
            else {
                rodsLog( LOG_ERROR,
                         "specCollSubStat: requeDataObjInfoByResc %s, resc %s error",
                         myDataObjInp.objPath, specColl->resource );
                freeAllDataObjInfo( *dataObjInfo );
                *dataObjInfo = NULL;
                return SYS_CACHE_STRUCT_FILE_RESC_ERR;
            }
        }

        /* free all the other dataObjInfo */
        if ( ( *dataObjInfo )->next != NULL ) {
            freeAllDataObjInfo( ( *dataObjInfo )->next );
            ( *dataObjInfo )->next = NULL;
        }

        /* fill in DataObjInfo */
        tmpDataObjInfo = *dataObjInfo;
        replSpecColl( specColl, &tmpDataObjInfo->specColl );
        rstrcpy( specColl->resource, tmpDataObjInfo->rescName, NAME_LEN );
        rstrcpy( specColl->rescHier, tmpDataObjInfo->rescHier, MAX_NAME_LEN );
        rstrcpy( specColl->phyPath, tmpDataObjInfo->filePath, MAX_NAME_LEN );
        rstrcpy( tmpDataObjInfo->subPath, subPath, MAX_NAME_LEN );
        specColl->replNum = tmpDataObjInfo->replNum;

        if ( strcmp( ( *dataObjInfo )->subPath, specColl->collection ) == 0 ) {
            /* no need to go down */
            return COLL_OBJ_T;
        }
    }
    else {
        rodsLog( LOG_ERROR,
                 "specCollSubStat: Unknown specColl collClass = %d",
                 specColl->collClass );
        return SYS_UNKNOWN_SPEC_COLL_CLASS;
    }
    status = l3Stat( rsComm, *dataObjInfo, &rodsStat );

    if ( status < 0 ) {
        return status;
    }

    if ( rodsStat->st_ctim != 0 ) {
        snprintf( ( *dataObjInfo )->dataCreate, TIME_LEN, "%d", rodsStat->st_ctim );
        snprintf( ( *dataObjInfo )->dataModify, TIME_LEN, "%d", rodsStat->st_mtim );
    }

    if ( rodsStat->st_mode & S_IFDIR ) {
        objType = COLL_OBJ_T;
    }
    else {
        objType = DATA_OBJ_T;
        ( *dataObjInfo )->dataSize = rodsStat->st_size;
    }
    free( rodsStat );

    return objType;
}
Example #19
0
int
getUtil (rcComm_t **myConn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
rodsPathInp_t *rodsPathInp)
{
    int i;
    int status; 
    int savedStatus = 0;
    rodsPath_t *targPath;
    dataObjInp_t dataObjOprInp;
    rodsRestart_t rodsRestart;
    rcComm_t *conn = *myConn;

    if (rodsPathInp == NULL) {
	return (USER__NULL_INPUT_ERR);
    }

    if (myRodsArgs->ticket == True) {
       if (myRodsArgs->ticketString == NULL) {
	  rodsLog (LOG_ERROR,
		   "initCondForPut: NULL ticketString error");
	  return (USER__NULL_INPUT_ERR);
       } else {
	  setSessionTicket(conn, myRodsArgs->ticketString);
       }
    }

    initCondForGet (conn, myRodsEnv, myRodsArgs, &dataObjOprInp, &rodsRestart);

    if (rodsPathInp->resolved == False) {
        status = resolveRodsTarget (conn, myRodsEnv, rodsPathInp, 1);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "getUtil: resolveRodsTarget");
            return (status);
	}
	rodsPathInp->resolved = True;
    }

    /* initialize the progress struct */
    if (gGuiProgressCB != NULL) {
        bzero (&conn->operProgress, sizeof (conn->operProgress));
	for (i = 0; i < rodsPathInp->numSrc; i++) {
	    targPath = &rodsPathInp->targPath[i];
            if (targPath->objType == LOCAL_FILE_T) {
                conn->operProgress.totalNumFiles++;
		if (rodsPathInp->srcPath[i].size > 0) {
                    conn->operProgress.totalFileSize += 
		      rodsPathInp->srcPath[i].size;
		}
	    } else {
		getCollSizeForProgStat (conn, rodsPathInp->srcPath[i].outPath,
		  &conn->operProgress);
	    }
	}
    }

    if (conn->fileRestart.flags == FILE_RESTART_ON) {
        fileRestartInfo_t *info;
        status = readLfRestartFile (conn->fileRestart.infoFile, &info);
        if (status >= 0) {
            status = lfRestartGetWithInfo (conn, info);
            if (status >= 0) {
                /* save info so we know what got restarted and what not to
                 * delete in setStateForResume */
                rstrcpy (conn->fileRestart.info.objPath, info->objPath,
                  MAX_NAME_LEN);
                rstrcpy (conn->fileRestart.info.fileName, info->fileName,
                  MAX_NAME_LEN);
                conn->fileRestart.info.status = FILE_RESTARTED;
                printf ("%s was restarted successfully\n",
                  conn->fileRestart.info.objPath);
                unlink (conn->fileRestart.infoFile);
            }
            if (info != NULL) free (info);
        }
    }

    for (i = 0; i < rodsPathInp->numSrc; i++) {
        targPath = &rodsPathInp->targPath[i];

	if (rodsPathInp->srcPath[i].rodsObjStat != NULL &&
	  rodsPathInp->srcPath[i].rodsObjStat->specColl != NULL) {
	    dataObjOprInp.specColl = 
	      rodsPathInp->srcPath[i].rodsObjStat->specColl;
	} else {
	    dataObjOprInp.specColl = NULL;
	}
	if (targPath->objType == LOCAL_FILE_T) {
	    rmKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW);
	    status = getDataObjUtil (conn, rodsPathInp->srcPath[i].outPath, 
	     targPath->outPath, rodsPathInp->srcPath[i].size,
	      rodsPathInp->srcPath[i].objMode, myRodsEnv, 
	      myRodsArgs, &dataObjOprInp);
	} else if (targPath->objType ==  LOCAL_DIR_T) {
            setStateForRestart (conn, &rodsRestart, targPath, myRodsArgs);
            /* The path given by collEnt.collName from rclReadCollection 
             * has already been translated */
	    addKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW, "");
	    status = getCollUtil (myConn, rodsPathInp->srcPath[i].outPath,
              targPath->outPath, myRodsEnv, myRodsArgs, &dataObjOprInp,
	      &rodsRestart);
#if 0
            if (rodsRestart.fd > 0 && status < 0) {
                close (rodsRestart.fd);
                return (status);
            }
#endif
	} else {
	    /* should not be here */
	    rodsLog (LOG_ERROR,
	     "getUtil: invalid get dest objType %d for %s", 
	      targPath->objType, targPath->outPath);
	    return (USER_INPUT_PATH_ERR);
	}
	/* XXXX may need to return a global status */
	if (status < 0) {
            rodsLogError (LOG_ERROR, status,
             "getUtil: get error for %s", 
	      targPath->outPath);
	    savedStatus = status;
	    break;
	} 
    }

    if (rodsRestart.fd > 0) {
        close (rodsRestart.fd);
    }
    if (savedStatus < 0) {
        status = savedStatus;
    } else if (status == CAT_NO_ROWS_FOUND) {
        status = 0;
    }

    if (status < 0 && myRodsArgs->retries == True) {
        int reconnFlag;
        /* this is recursive. Only do it the first time */
        myRodsArgs->retries = False;
        if (myRodsArgs->reconnect == True) {
            reconnFlag = RECONN_TIMEOUT;
        } else {
            reconnFlag = NO_RECONN;
        }
        while (myRodsArgs->retriesValue > 0) {
            rErrMsg_t errMsg;
            bzero (&errMsg, sizeof (errMsg));
            status = rcReconnect (myConn, myRodsEnv->rodsHost, myRodsEnv,
              reconnFlag);
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                 "getUtil: rcReconnect error for %s", targPath->outPath);
                return status;
            }
            status = getUtil (myConn,  myRodsEnv, myRodsArgs, rodsPathInp);
            if (status >= 0) {
                printf ("Retry get successful\n");
                break;
            } else {
                rodsLogError (LOG_ERROR, status,
                 "getUtil: retry getUtil error");
            }
            myRodsArgs->retriesValue--;
        }
    }
    return status;
}
Example #20
0
int
queueSpecCollCache( rsComm_t *rsComm, genQueryOut_t *genQueryOut, char *objPath ) { // JMC - backport 4680
    int status;
    int i;
    sqlResult_t *dataId;
    sqlResult_t *ownerName;
    sqlResult_t *ownerZone;
    sqlResult_t *createTime;
    sqlResult_t *modifyTime;
    sqlResult_t *collType;
    sqlResult_t *collection;
    sqlResult_t *collInfo1;
    sqlResult_t *collInfo2;
    char *tmpDataId, *tmpOwnerName, *tmpOwnerZone, *tmpCreateTime,
         *tmpModifyTime, *tmpCollType, *tmpCollection, *tmpCollInfo1,
         *tmpCollInfo2;
    specColl_t *specColl;

    if ( ( dataId = getSqlResultByInx( genQueryOut, COL_COLL_ID ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache: getSqlResultByInx for COL_COLL_ID failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( ownerName = getSqlResultByInx( genQueryOut,
                            COL_COLL_OWNER_NAME ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_OWNER_NAME failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( ownerZone = getSqlResultByInx( genQueryOut,
                            COL_COLL_OWNER_ZONE ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_OWNER_ZONE failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( createTime = getSqlResultByInx( genQueryOut,
                             COL_COLL_CREATE_TIME ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_CREATE_TIME failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( modifyTime = getSqlResultByInx( genQueryOut,
                             COL_COLL_MODIFY_TIME ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_MODIFY_TIME failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( collType = getSqlResultByInx( genQueryOut,
                           COL_COLL_TYPE ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_TYPE failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( collection = getSqlResultByInx( genQueryOut,
                             COL_COLL_NAME ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_NAME failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( collInfo1 = getSqlResultByInx( genQueryOut,
                            COL_COLL_INFO1 ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_INFO1 failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    else if ( ( collInfo2 = getSqlResultByInx( genQueryOut,
                            COL_COLL_INFO2 ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "queueSpecCollCache:getSqlResultByInx for COL_COLL_INFO2 failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }

    for ( i = 0; i <= genQueryOut->rowCnt; i++ ) {
        int len;
        char *tmpPtr;

        tmpCollection = &collection->value[collection->len * i];

        len = strlen( tmpCollection );
        tmpPtr = objPath + len;

        if ( *tmpPtr == '\0' || *tmpPtr == '/' ) {
            specCollCache_t * tmpSpecCollCache = ( specCollCache_t* )malloc( sizeof( specCollCache_t ) );
            memset( tmpSpecCollCache, 0, sizeof( specCollCache_t ) );

            tmpDataId = &dataId->value[dataId->len * i];
            tmpOwnerName = &ownerName->value[ownerName->len * i];
            tmpOwnerZone = &ownerZone->value[ownerZone->len * i];
            tmpCreateTime = &createTime->value[createTime->len * i];
            tmpModifyTime = &modifyTime->value[modifyTime->len * i];
            tmpCollType = &collType->value[collType->len * i];
            tmpCollInfo1 = &collInfo1->value[collInfo1->len * i];
            tmpCollInfo2 = &collInfo2->value[collInfo2->len * i];

            specColl = &tmpSpecCollCache->specColl;
            status = resolveSpecCollType( tmpCollType, tmpCollection, tmpCollInfo1, tmpCollInfo2, specColl );
            if ( status < 0 ) {
                free( tmpSpecCollCache );
                return status;
            }

            // =-=-=-=-=-=-=-
            // JMC - backport 4680
            if ( specColl->collClass == STRUCT_FILE_COLL &&
                    specColl->type      == TAR_STRUCT_FILE_T ) {
                /* tar struct file. need to get phyPath */
                status = getPhyPath( rsComm, specColl->objPath, specColl->resource, specColl->phyPath, specColl->rescHier );
                if ( status < 0 ) {
                    rodsLog( LOG_ERROR, "queueSpecCollCache - getPhyPath failed for [%s] on resource [%s] with cache dir [%s] and collection [%s]",
                             specColl->objPath, specColl->resource, specColl->cacheDir, specColl->collection );
                    free( tmpSpecCollCache );
                    return status;
                }
            }
            // =-=-=-=-=-=-=-
            rstrcpy( tmpSpecCollCache->collId, tmpDataId, NAME_LEN );
            rstrcpy( tmpSpecCollCache->ownerName, tmpOwnerName, NAME_LEN );
            rstrcpy( tmpSpecCollCache->ownerZone, tmpOwnerZone, NAME_LEN );
            rstrcpy( tmpSpecCollCache->createTime, tmpCreateTime, TIME_LEN );
            rstrcpy( tmpSpecCollCache->modifyTime, tmpModifyTime, TIME_LEN );
            tmpSpecCollCache->next = SpecCollCacheHead;
            SpecCollCacheHead = tmpSpecCollCache;

            return 0;
        }
    }

    return CAT_NO_ROWS_FOUND;
}
Example #21
0
int
_rsChkNVPathPerm( rsComm_t *rsComm, fileOpenInp_t *chkNVPathPermInp ) {
    struct stat myFileStat;
    int sysUid;
    char  tmpPath[MAX_NAME_LEN];
    int len;
    char *tmpPtr;

    if ( chkNVPathPermInp->objPath[0] == '\0' ) {
        std::stringstream msg;
        msg << __FUNCTION__;
        msg << " - Empty logical path.";
        irods::log( LOG_ERROR, msg.str() );
        return -1;
    }

    /* Need to match path's owner uid with sysUid */
    sysUid = rsComm->clientUser.sysUid;
    if ( sysUid < 0 ) {
        /* have tried before */
        return SYS_NO_PATH_PERMISSION;
    }
    else if ( sysUid == 0 ) {
        sysUid = rsComm->clientUser.sysUid =
                     getUnixUid( rsComm->clientUser.userName );

        if ( sysUid < 0 ) {
            rsComm->clientUser.sysUid = sysUid;
            return SYS_NO_PATH_PERMISSION;
        }
    }


    rstrcpy( tmpPath, chkNVPathPermInp->fileName, MAX_NAME_LEN );

    len = strlen( tmpPath );
    irods::error stat_err;
    while ( 1 ) {

        irods::file_object_ptr file_obj(
            new irods::file_object(
                rsComm,
                chkNVPathPermInp->objPath,
                tmpPath,
                chkNVPathPermInp->resc_hier_,
                0, 0, 0 ) );
        stat_err = fileStat( rsComm, file_obj, &myFileStat );
        if ( stat_err.code() >= 0 ) {
            break;
        }
        else if ( errno == EEXIST || getErrno( stat_err.code() ) == EEXIST ) {

            /* go back */
            tmpPtr =  tmpPath + len;

            while ( len > 0 ) {
                len --;
                if ( *tmpPtr == '/' ) {
                    *tmpPtr = '\0';
                    break;
                }
                tmpPtr--;
            }

            if ( len > 0 ) {
                /* give it more tries */
                continue;
            }
            else {
                break;
            }
        }
        else {
            break;
        }
    }

    if ( stat_err.code() < 0 ) {
        return SYS_NO_PATH_PERMISSION;
    }

    if ( sysUid != ( int ) myFileStat.st_uid &&
            ( myFileStat.st_mode & S_IWOTH ) == 0 ) {
        return SYS_NO_PATH_PERMISSION;
    }
    else {
        return 0;
    }
}
Example #22
0
int
rsGetHostForGet (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
char **outHost)
{
    int status;
    rescInfo_t *myRescInfo;
    char *myResc;
    rodsServerHost_t *rodsServerHost;
    rodsHostAddr_t addr;
    specCollCache_t *specCollCache = NULL;
    char *myHost;
    int remoteFlag;

    *outHost = NULL;

#if 0
    if (isLocalZone (dataObjInp->objPath) == 0) {
	/* it is a remote zone. better connect to this host */
	*outHost = strdup (THIS_ADDRESS);
	return 0;
    }
#endif

    resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache, NULL);
    if (isLocalZone (dataObjInp->objPath) == 0) {
#if 0
        /* it is a remote zone. better connect to this host */
        *outHost = strdup (THIS_ADDRESS);
        return 0;
#else
        resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
          &dataObjInp->condInput);
        remoteFlag = getAndConnRcatHost (rsComm, SLAVE_RCAT, 
	  dataObjInp->objPath, &rodsServerHost);
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else if (remoteFlag == LOCAL_HOST) {
	    *outHost = strdup (THIS_ADDRESS);
            return 0;
	} else {
            status = rcGetHostForGet (rodsServerHost->conn, dataObjInp, 
	      outHost);
	    if (status >= 0 && *outHost != NULL && 
	      strcmp (*outHost, THIS_ADDRESS) == 0) {
		free (*outHost);
		*outHost = strdup (rodsServerHost->hostName->name);
	    }
            return (status);
	}
#endif
    }
    status = getSpecCollCache (rsComm, dataObjInp->objPath, 0, &specCollCache);
    if (status >= 0) {
	if (specCollCache->specColl.collClass == MOUNTED_COLL) {
            status = resolveResc (specCollCache->specColl.resource, 
	      &myRescInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "rsGetHostForGet: resolveResc error for %s, status = %d",
                 specCollCache->specColl.resource, status);
		return status;
            }
	    /* mounted coll will fall through with myRescInfo */
        } else {
            *outHost = strdup (THIS_ADDRESS);
            return 0;
	}
    } else if ((myResc = getValByKey (&dataObjInp->condInput, RESC_NAME_KW)) 
      != NULL && resolveResc (myResc, &myRescInfo) >= 0) {
	/* user specified a resource. myRescInfo set and fall through */
    } else {
	/* normal type */
        status = getBestRescForGet (rsComm, dataObjInp, &myRescInfo);
	if (myRescInfo == NULL) {
	    *outHost = strdup (THIS_ADDRESS);
            return status;
	}
    }

    /* get down here when we got a valid myRescInfo */

    if (getRescClass (myRescInfo) == COMPOUND_CL) {
        *outHost = strdup (THIS_ADDRESS);
        return 0;
    }

    bzero (&addr, sizeof (addr));
    rstrcpy (addr.hostAddr, myRescInfo->rescLoc, NAME_LEN);
    status = resolveHost (&addr, &rodsServerHost);
    if (status < 0) return status;
    if (rodsServerHost->localFlag == LOCAL_HOST) {
        *outHost = strdup (THIS_ADDRESS);
        return 0;
    }

    myHost = getSvrAddr (rodsServerHost);
    if (myHost != NULL) {
	*outHost = strdup (myHost);
        return 0;
    } else {
        *outHost = NULL;
	return SYS_INVALID_SERVER_HOST;
    }
}
Example #23
0
int writeICatUserLogging( char *userName, int logging, rsComm_t *rsComm ) {
    char value[MAX_NAME_LEN];
    rstrcpy( value, ( char * )( logging ? "true" : "false" ), MAX_NAME_LEN );
    return writeICatUserInfo( userName, RE_LOGGING_ATTR, value, rsComm );
}
Example #24
0
int
bunUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
         rodsPathInp_t *rodsPathInp ) {
    rodsPath_t *collPath, *structFilePath;
    structFileExtAndRegInp_t structFileExtAndRegInp;

    if ( rodsPathInp == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    int savedStatus = initCondForBunOpr( myRodsEnv, myRodsArgs, &structFileExtAndRegInp );
    if ( savedStatus < 0 ) {
        return savedStatus;
    }

    for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
        collPath = &rodsPathInp->destPath[i];	/* iRODS Collection */
        structFilePath = &rodsPathInp->srcPath[i];	/* iRODS StructFile */

        getRodsObjType( conn, collPath );

        rstrcpy( structFileExtAndRegInp.collection, collPath->outPath,
                 MAX_NAME_LEN );
        rstrcpy( structFileExtAndRegInp.objPath, structFilePath->outPath,
                 MAX_NAME_LEN );

        int status = 0;
        if ( myRodsArgs->extract == True ) {		/* -x */
            if ( myRodsArgs->condition == True ) {
                rodsLog( LOG_ERROR, "bunUtil: cannot use -x and -c at the same time" );
                return -1;
            }
            status = rcStructFileExtAndReg( conn, &structFileExtAndRegInp );
        }
        else if ( myRodsArgs->condition == True ) {  /* -c - create */
            status = rcStructFileBundle( conn, &structFileExtAndRegInp );
        }
        else if ( myRodsArgs->add == True ) {  /* add to tar */ // JMC - backport 4643
            status = rcStructFileBundle( conn, &structFileExtAndRegInp );
        }
        else {
            rodsLog( LOG_ERROR,
                     "bunUtil: -x or -c must be specified" );
            return -1;
        }

        /* XXXX may need to return a global status */
        if ( status < 0 &&
                status != CAT_NO_ROWS_FOUND ) {
            if ( status == SYS_CACHE_STRUCT_FILE_RESC_ERR &&
                    myRodsArgs->condition == True ) {
                rodsLogError( LOG_ERROR, status,
                              "bunUtil: A resc must be entered for non-existing structFile" );
            }
            else {
                rodsLogError( LOG_ERROR, status,
                              "bunUtil: opr error for %s, status = %d",
                              collPath->outPath, status );
                savedStatus = status;
            }
        }
    }
    return savedStatus;
}
Example #25
0
int 
parseRodsPath (rodsPath_t *rodsPath, rodsEnv *myRodsEnv)
{
    int len;
    char *tmpPtr1, *tmpPtr2;
    char tmpStr[MAX_NAME_LEN];
    
    if (rodsPath == NULL) {
        fprintf (stderr, "parseRodsPath: NULL rodsPath input\n");
        return (USER__NULL_INPUT_ERR);
    }

    rodsPath->objType = UNKNOWN_OBJ_T;
    rodsPath->objState = UNKNOWN_ST;

    if (rodsPath->inPath == NULL) {
        fprintf (stderr, "parseRodsPath: NULL rodsPath->inPath input\n");
        return (USER__NULL_INPUT_ERR);
    }

    if (myRodsEnv == NULL && rodsPath->inPath[0] != '/') {
	fprintf (stderr, "parseRodsPath: NULL myRodsEnv input\n");
        return (USER__NULL_INPUT_ERR);
    }
 
    len = strlen (rodsPath->inPath);

    if (len == 0) {
	/* just copy rodsCwd */
        rstrcpy (rodsPath->outPath, myRodsEnv->rodsCwd, MAX_NAME_LEN);
        rodsPath->objType = COLL_OBJ_T;
        return (0);
    } else if (strcmp (rodsPath->inPath, ".") == 0 || 
      strcmp (rodsPath->inPath, "./") == 0) {
	/* '.' or './' */
	rstrcpy (rodsPath->outPath, myRodsEnv->rodsCwd, MAX_NAME_LEN);
        rodsPath->objType = COLL_OBJ_T;
	return (0);
    } else if (strcmp (rodsPath->inPath, "~") == 0 ||
      strcmp (rodsPath->inPath, "~/") == 0 ||
      strcmp (rodsPath->inPath, "^") == 0 ||
      strcmp (rodsPath->inPath, "^/") == 0) { 
	/* ~ or ~/ */
        rstrcpy (rodsPath->outPath, myRodsEnv->rodsHome, MAX_NAME_LEN);
        rodsPath->objType = COLL_OBJ_T;
        return (0);
    } else if (rodsPath->inPath[0] == '~' || rodsPath->inPath[0] == '^') {
	if (rodsPath->inPath[1] == '/') {
	    snprintf (rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
	      myRodsEnv->rodsHome, rodsPath->inPath + 2);
	} else {
	    /* treat it like a relative path */
	    snprintf (rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
              myRodsEnv->rodsCwd, rodsPath->inPath + 2);
	}
    } else if (rodsPath->inPath[0] == '/') {
	/* full path */
        rstrcpy (rodsPath->outPath, rodsPath->inPath, MAX_NAME_LEN);
    } else {
	/* a relative path */
        snprintf (rodsPath->outPath, MAX_NAME_LEN, "%s/%s",
          myRodsEnv->rodsCwd, rodsPath->inPath);
    }

    /* take out any "//" */

    while ((tmpPtr1 = strstr (rodsPath->outPath, "//")) != NULL) {
#if 0
        rstrcpy (tmpPtr1 + 1, tmpPtr1 + 2, MAX_NAME_LEN);
#else
        rstrcpy (tmpStr, tmpPtr1 + 2, MAX_NAME_LEN);
        rstrcpy (tmpPtr1 + 1, tmpStr, MAX_NAME_LEN);
#endif
    }

    /* take out any "/./" */

    while ((tmpPtr1 = strstr (rodsPath->outPath, "/./")) != NULL) {
#if 0
        rstrcpy (tmpPtr1 + 1, tmpPtr1 + 3, MAX_NAME_LEN);
#else
        rstrcpy (tmpStr, tmpPtr1 + 3, MAX_NAME_LEN);
        rstrcpy (tmpPtr1 + 1, tmpStr, MAX_NAME_LEN);
#endif

    }

    /* take out any /../ */
 
    while ((tmpPtr1 = strstr (rodsPath->outPath, "/../")) != NULL) {  
	/* go back */
	tmpPtr2 = tmpPtr1 - 1;
	while (*tmpPtr2 != '/') {
	    tmpPtr2 --;
	    if (tmpPtr2 < rodsPath->outPath) {
		rodsLog (LOG_ERROR,
		 "parseRodsPath: parsing error for %s",
		  rodsPath->outPath);
		return (USER_INPUT_PATH_ERR);
	    }
	}
#if 0
	rstrcpy (tmpPtr2 + 1, tmpPtr1 + 4, MAX_NAME_LEN);
#else
        rstrcpy (tmpStr, tmpPtr1 + 4, MAX_NAME_LEN);
        rstrcpy (tmpPtr2 + 1, tmpStr, MAX_NAME_LEN);
#endif

    }

    /* handle "/.", "/.." and "/" at the end */

    len = strlen (rodsPath->outPath);

    tmpPtr1 = rodsPath->outPath + len;

    if ((tmpPtr2 = strstr (tmpPtr1 - 3, "/..")) != NULL) {
        /* go back */
        tmpPtr2 -= 1;
        while (*tmpPtr2 != '/') {
            tmpPtr2 --;
            if (tmpPtr2 < rodsPath->outPath) {
                rodsLog (LOG_ERROR,
                 "parseRodsPath: parsing error for %s",
                  rodsPath->outPath);
                return (USER_INPUT_PATH_ERR);
            }
        }
	*tmpPtr2 = '\0';
	if (tmpPtr2 == rodsPath->outPath) { /* nothing, special case */
	   *tmpPtr2++ = '/'; /* root */
	   *tmpPtr2 = '\0';
	}
        rodsPath->objType = COLL_OBJ_T;
        if (strlen(rodsPath->outPath) >= MAX_PATH_ALLOWED-1){
	    return (USER_PATH_EXCEEDS_MAX);
        }
	return (0);
    }

    /* take out "/." */

    if ((tmpPtr2 = strstr (tmpPtr1 - 2, "/.")) != NULL) {
        *tmpPtr2 = '\0';
        rodsPath->objType = COLL_OBJ_T;
        if (strlen(rodsPath->outPath) >= MAX_PATH_ALLOWED-1){
	    return (USER_PATH_EXCEEDS_MAX);
        }
        return (0);
    }

    if (*(tmpPtr1 - 1) == '/' && len > 1) {
        *(tmpPtr1 - 1) = '\0';
        rodsPath->objType = COLL_OBJ_T;
        if (strlen(rodsPath->outPath) >= MAX_PATH_ALLOWED-1){
	    return (USER_PATH_EXCEEDS_MAX);
        }
        return (0);
    }
    if (strlen(rodsPath->outPath) >= MAX_PATH_ALLOWED-1){
       return (USER_PATH_EXCEEDS_MAX);
    }
    return (0);
}
Example #26
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;

}
Example #27
0
int
getLastPathElement (char *inInPath, char *lastElement)
{
    char mydir[MAX_NAME_LEN];
	char inPath[MAX_NAME_LEN];
    int len;
    char *tmpPtr1, *tmpPtr2;

    if (inInPath == NULL) {
        *lastElement = '\0';
	return (0);
    }
	strcpy(inPath, inInPath);
#ifdef windows_platform
	iRODSNtPathForwardSlash(inPath);
#endif

    
    splitPathByKey (inPath, mydir, lastElement, '/'); 

    len = strlen (lastElement);

    if (len == 0) {
        len = strlen (inPath);
        if (len == 0) {
            *lastElement = '\0';
            return (0);
        } else {
            rstrcpy (lastElement, inPath, MAX_NAME_LEN);
            len = strlen (lastElement);
        }
    }

    tmpPtr1 = lastElement + len;
    if (len >= 2) {
	tmpPtr2 = tmpPtr1 - 2;
        if (strcmp (tmpPtr2, "/.") == 0 || strcmp (tmpPtr2, "..") == 0) {
	    *tmpPtr2 = '\0';
	    return 0;
	}
    } 

    if (len >= 1) {
	tmpPtr2 = tmpPtr1 - 1;
        if (*tmpPtr2 == '.' || *tmpPtr2 == '~' ||
          *tmpPtr2 == '^' || *tmpPtr2 == '/') {
            *tmpPtr2 = '\0';
	    return 0;
	}
    }

#if 0
    if (len == 1 && (*lastElement == '.' || *lastElement == '~' ||
      *lastElement == '^' || *lastElement == '/')) {
        *lastElement = '\0';
    } else if (len == 2 && *lastElement == '.' && *(lastElement + 1) == '.') {
	/* ".." */
       *lastElement = '\0';
    }
#endif

    return (0); 
}
Example #28
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
Example #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;
}
Example #30
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;
    }
}