Exemple #1
0
int irods_reli_getfile ( const char *host, const char *path, const char *local_path )
{
	dataObjInp_t request;
	int result;

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

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

	request.numThreads = 0; // server chooses threads
	request.openFlags = O_RDONLY;

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

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

	clearKeyVal(&request.condInput);

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

	return 0;
}
Exemple #2
0
/**
 * \fn rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray )
 *
 * \brief Execute my rule.
 *
 * \user client
 *
 * \ingroup rules
 *
 * \since 1.0
 *
 *
 * \remark none
 *
 * \note none
*
 * \param[in] conn - A rcComm_t connection handle to the server.
 * \param[in] execMyRuleInp
 * \param[out] outParamArray
 *
 * \return integer
 * \retval 0 on success.
 * \sideeffect none
 * \pre none
 * \post none
 * \sa none
**/
int
rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp,
              msParamArray_t **outParamArray ) {

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

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

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

        /* read the reply from the earlier call */

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

    return status;
}
int RodsConnection::getFile(const std::string &localPath, const std::string &objPath, bool verifyChecksum,
                            bool allowOverwrite, unsigned int numThreads)
{
    int status = 0;
    dataObjInp_t getParam;

    // sanity check, input argument string must be nonempty and begin with /
    if (objPath.empty() || objPath.find_first_of('/') != 0)
        return (-1);

    this->mutexLock();

    // zero rods api param struct
    memset(&getParam, 0, sizeof (dataObjInp_t));

    // set parameters for get operation
    getParam.oprType = GET_OPR;
    getParam.numThreads = numThreads;

    if (verifyChecksum)
        addKeyVal(&getParam.condInput, VERIFY_CHKSUM_KW, "");

    if (allowOverwrite)
        addKeyVal(&getParam.condInput, FORCE_FLAG_KW, "");

    // copy obj path string
    rstrcpy(getParam.objPath, objPath.c_str(), MAX_NAME_LEN);

    // execute data object get
    status = rcDataObjGet(this->rodsCommPtr, &getParam, (char*)localPath.c_str());

    this->mutexUnlock();

    // return rods api status
    return (status);
}
Exemple #4
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);
}
int
rcDataObjRsync (rcComm_t *conn, dataObjInp_t *dataObjInp) 
{
    int status;
    msParamArray_t *outParamArray = NULL;
    char *locFilePath;

    status = _rcDataObjRsync (conn, dataObjInp, &outParamArray);

    if (status == SYS_SVR_TO_CLI_PUT_ACTION) {
        if ((locFilePath = getValByKey (&dataObjInp->condInput,
          RSYNC_DEST_PATH_KW)) == NULL) {
	    return USER_INPUT_PATH_ERR;
	} else {
	    status = rcDataObjPut (conn, dataObjInp, locFilePath);
	    if (status >= 0) {
		return SYS_RSYNC_TARGET_MODIFIED;
	    } else {
	        return status;
	    }
	}
    } else if (status == SYS_SVR_TO_CLI_GET_ACTION) {
        if ((locFilePath = getValByKey (&dataObjInp->condInput,
          RSYNC_DEST_PATH_KW)) == NULL) {
            return USER_INPUT_PATH_ERR;
        } else {
            status = rcDataObjGet (conn, dataObjInp, locFilePath);
            if (status >= 0) {
                return SYS_RSYNC_TARGET_MODIFIED;
            } else {
                return status;
            }
	}
    }

    /* below is for backward compatibility */
    while (status == SYS_SVR_TO_CLI_MSI_REQUEST) {
	/* it is a server request */
        msParam_t *myMsParam;
        dataObjInp_t *dataObjInp = NULL;
	int l1descInx; 

	myMsParam = getMsParamByLabel (outParamArray, CL_ZONE_OPR_INX);
	if (myMsParam == NULL) {
	    l1descInx = -1;
	} else {
	    l1descInx = *(int*) myMsParam->inOutStruct;
	}

	if ((myMsParam = getMsParamByLabel (outParamArray, CL_PUT_ACTION))
	  != NULL) { 

	    dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct;
	    if ((locFilePath = getValByKey (&dataObjInp->condInput, 
	      RSYNC_DEST_PATH_KW)) == NULL) {
		if (l1descInx >= 0) {
		    rcOprComplete (conn, l1descInx);
		} else {
		        rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST);
		}
	    } else {
	        status = rcDataObjPut (conn, dataObjInp, locFilePath);
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
		    rcOprComplete (conn, status);
		}
	    }
	} else if ((myMsParam = getMsParamByLabel (outParamArray, 
	  CL_GET_ACTION)) != NULL) {
            dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct;
            if ((locFilePath = getValByKey (&dataObjInp->condInput,
              RSYNC_DEST_PATH_KW)) == NULL) {
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
                    rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST);
		}
            } else {
                status = rcDataObjGet (conn, dataObjInp, locFilePath);
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
                    rcOprComplete (conn, status);
		}
            }
	} else {
            if (l1descInx >= 0) {
                rcOprComplete (conn, l1descInx);
            } else {
                rcOprComplete (conn, SYS_SVR_TO_CLI_MSI_NO_EXIST);
	    }
	}
	/* free outParamArray */
	if (dataObjInp != NULL) {
	    clearKeyVal (&dataObjInp->condInput); 
	}
	clearMsParamArray (outParamArray, 1);
	free (outParamArray);

	/* read the reply from the eariler call */

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

    return (status);
}
Exemple #6
0
int
rsyncDataToFileUtil (rcComm_t *conn, rodsPath_t *srcPath, 
rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, 
dataObjInp_t *dataObjOprInp)
{
    int status;
    struct timeval startTime, endTime;
    int getFlag = 0;
    int syncFlag = 0;
    char *chksum;
 
    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "rsyncDataToFileUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    /* check the age */
    if (myRodsArgs->age == True) {
	if (srcPath->rodsObjStat != NULL) {
	    if (ageExceeded (myRodsArgs->agevalue, 
	      atoi (srcPath->rodsObjStat->modifyTime), myRodsArgs->verbose,
              srcPath->outPath, srcPath->size)) return 0;
        }
    }
    if (myRodsArgs->verbose == True) {
        (void) gettimeofday(&startTime, (struct timezone *)0);
	bzero (&conn->transStat, sizeof (transStat_t));
    }

    if (targPath->objState == NOT_EXIST_ST) {
	getFlag = 1;
    } else if (myRodsArgs->sizeFlag == True) {
	/* sync by size */
	if (targPath->size != srcPath->size) {
	    getFlag = 1;
	}
    } else if (strlen (srcPath->chksum) > 0) {
	/* src has a checksum value */
        status = rcChksumLocFile (targPath->outPath, RSYNC_CHKSUM_KW,
          &dataObjOprInp->condInput, extractHashFunction3(myRodsArgs));
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "rsyncDataToFileUtil: rcChksumLocFile error for %s, status = %d",
              targPath->outPath, status);
            return (status);
        } else {
	    chksum = getValByKey (&dataObjOprInp->condInput, RSYNC_CHKSUM_KW);
	    if (strcmp (chksum, srcPath->chksum) != 0) {
		getFlag = 1;
	    }
	}
    } else { 
	/* exist but no chksum */
        status = rcChksumLocFile (targPath->outPath, RSYNC_CHKSUM_KW,
          &dataObjOprInp->condInput, extractHashFunction3(myRodsArgs));
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "rsyncDataToFileUtil: rcChksumLocFile error for %s, status = %d",
              targPath->outPath, status);
            return (status);
        } else {
	    syncFlag = 1;
	}
    }

    if (getFlag + syncFlag > 0) {
        if (myRodsArgs->verifyChecksum == True) {
            addKeyVal (&dataObjOprInp->condInput, VERIFY_CHKSUM_KW, "");
        }
        rstrcpy (dataObjOprInp->objPath, srcPath->outPath, MAX_NAME_LEN);
        dataObjOprInp->dataSize = srcPath->size;
        dataObjOprInp->openFlags = O_RDONLY;
    }

    if (getFlag == 1) {
	/* only do the sync if no -l option specified */
	if ( myRodsArgs->longOption != True ) { 
	    status = rcDataObjGet (conn, dataObjOprInp, targPath->outPath);	
	} else {
	    status = 0;
	    printf ("%s   %lld   N\n", srcPath->outPath, srcPath->size);
	}
        rmKeyVal (&dataObjOprInp->condInput, RSYNC_CHKSUM_KW);
	if (status >= 0 && myRodsArgs->longOption != True) 
	    myChmod (targPath->outPath, srcPath->objMode);
    } else if (syncFlag == 1) {
	addKeyVal (&dataObjOprInp->condInput, RSYNC_DEST_PATH_KW, 
	  targPath->outPath);
	addKeyVal (&dataObjOprInp->condInput, RSYNC_MODE_KW, LOCAL_TO_IRODS);
        status = rcDataObjRsync (conn, dataObjOprInp);
        rmKeyVal (&dataObjOprInp->condInput, RSYNC_DEST_PATH_KW);
        rmKeyVal (&dataObjOprInp->condInput, RSYNC_MODE_KW);
    } else {
	status = 0;
    }

    if (status >= 0 && myRodsArgs->verbose == True) {
	if (getFlag > 0 || 
	  (syncFlag > 0 && status == SYS_RSYNC_TARGET_MODIFIED)) {
            (void) gettimeofday(&endTime, (struct timezone *)0);
            printTiming (conn, srcPath->outPath, srcPath->size, 
	      targPath->outPath, &startTime, &endTime);
	} else {
	    printNoSync (srcPath->outPath, srcPath->size, "a match");
	}
    }

    return (status);
}
Exemple #7
0
int
irodsOpen (const char *path, struct fuse_file_info *fi)
{
    dataObjInp_t dataObjInp;
    int status;
    int fd;
    iFuseConn_t *iFuseConn = NULL;
    iFuseDesc_t *desc = NULL;
    pathCache_t *tmpPathCache = NULL;
    struct stat stbuf;
    char cachePath[MAX_NAME_LEN];
    char objPath[MAX_NAME_LEN];
    int flags = fi->flags;

    rodsLog (LOG_DEBUG, "irodsOpen: %s, flags = %d", path, fi->flags);

    matchAndLockPathCache((char *) path, &tmpPathCache);
    if(tmpPathCache!= NULL) {
        if(tmpPathCache->fileCache != NULL) {
            LOCK_STRUCT(*(tmpPathCache->fileCache));
            if (tmpPathCache->fileCache->state != NO_FILE_CACHE) {
                rodsLog (LOG_DEBUG, "irodsOpen: a match for %s", path);
                desc = newIFuseDesc(tmpPathCache->fileCache->objPath, (char *) path, tmpPathCache->fileCache, &status);
                if (status < 0) {
                    UNLOCK_STRUCT(*(tmpPathCache->fileCache));
                    UNLOCK_STRUCT(*tmpPathCache);
                    rodsLogError (LOG_ERROR, status, "irodsOpen: create descriptor of %s error", dataObjInp.objPath);
                    return status;
                }
                fi->fh = desc->index;
                if(tmpPathCache->fileCache->iFd == 0) {
                    tmpPathCache->fileCache->iFd = open(tmpPathCache->fileCache->fileCachePath, O_RDWR);
                }
                UNLOCK_STRUCT(*(tmpPathCache->fileCache));
                UNLOCK_STRUCT(*tmpPathCache);
                return (0);
            }
            UNLOCK_STRUCT(*(tmpPathCache->fileCache));
        }
        UNLOCK_STRUCT(*tmpPathCache);
    }

    memset (&dataObjInp, 0, sizeof (dataObjInp));
    dataObjInp.openFlags = flags;

    status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv, objPath);
    rstrcpy(dataObjInp.objPath, objPath, MAX_NAME_LEN);
    if (status < 0) {
        rodsLogError (LOG_ERROR, status, "irodsOpen: parseRodsPathStr of %s error", path);
        /* use ENOTDIR for this type of error */
        return -ENOTDIR;
    }

    iFuseConn = getAndUseConnByPath((char *) path, &MyRodsEnv, &status);
    /* status = getAndUseIFuseConn(&iFuseConn, &MyRodsEnv); */
    if(status < 0) {
        rodsLogError (LOG_ERROR, status, "irodsOpen: cannot get connection for %s error", path);
        /* use ENOTDIR for this type of error */
        return -ENOTDIR;
    }

    /* do only O_RDONLY (0) */
    status = _irodsGetattr (iFuseConn, path, &stbuf);
    if ((flags & (O_WRONLY | O_RDWR)) != 0 || status < 0 || stbuf.st_size > MAX_READ_CACHE_SIZE) {
        fd = rcDataObjOpen (iFuseConn->conn, &dataObjInp);
        unuseIFuseConn (iFuseConn);

        if (fd < 0) {
            rodsLogError (LOG_ERROR, status, "irodsOpen: rcDataObjOpen of %s error, status = %d", path, fd);
            return -ENOENT;
        }

        fileCache_t *fileCache = addFileCache(fd, objPath, (char *) path, NULL, stbuf.st_mode, stbuf.st_size, NO_FILE_CACHE);
        matchAndLockPathCache((char *) path, &tmpPathCache);
        if(tmpPathCache == NULL) {
            pathExist((char *) path, fileCache, &stbuf, NULL);
        } else {
            _addFileCacheForPath(tmpPathCache, fileCache);
            UNLOCK_STRUCT(*tmpPathCache);
        }
        desc = newIFuseDesc (objPath, (char *) path, fileCache, &status);
        if (desc == NULL) {
            rodsLogError (LOG_ERROR, status, "irodsOpen: allocIFuseDesc of %s error", path);
            return -ENOENT;
        }
    } else {
        rodsLog (LOG_DEBUG, "irodsOpenWithReadCache: caching %s", path);
        if ((status = getFileCachePath (path, cachePath)) < 0) {
            unuseIFuseConn(iFuseConn);
            return status;
        }
        /* get the file to local cache */
        dataObjInp.dataSize = stbuf.st_size;

        status = rcDataObjGet (iFuseConn->conn, &dataObjInp, cachePath);
        unuseIFuseConn(iFuseConn);

        if (status < 0) {
            rodsLogError (LOG_ERROR, status, "irodsOpenWithReadCache: rcDataObjGet of %s error", dataObjInp.objPath);
            return status;
        }

        int fd = open(cachePath, O_RDWR);

        fileCache_t *fileCache = addFileCache(fd, objPath, (char *) path, cachePath, stbuf.st_mode, stbuf.st_size, HAVE_READ_CACHE);
        matchAndLockPathCache((char *) path, &tmpPathCache);
        if(tmpPathCache == NULL) {
            pathExist((char *) path, fileCache, &stbuf, NULL);
        } else {
            _addFileCacheForPath(tmpPathCache, fileCache);
            UNLOCK_STRUCT(*tmpPathCache);
        }
        desc = newIFuseDesc(objPath, (char *) path,fileCache, &status);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status, "irodsOpen: create descriptor of %s error", dataObjInp.objPath);
            return status;
        }
    }

    fi->fh = desc->index;

    return (0);
}