Пример #1
0
int
replAndAddSubFileToDir( rsComm_t *rsComm, curSubFileCond_t *curSubFileCond,
                        const char *myRescName, char *phyBunDir, bunReplCacheHeader_t *bunReplCacheHeader ) {
    int status;
    dataObjInfo_t dataObjInfo;

    if ( curSubFileCond->bundled == 1 ) {
        return 0;
    }

    bzero( &dataObjInfo, sizeof( dataObjInfo ) );
    /* next dataObj. See if we need to replicate */
    if ( curSubFileCond->subPhyPath[0] == '\0' ) {
        /* don't have a good cache copy yet. make one */
        status = replDataObjForBundle( rsComm, curSubFileCond->collName,
                                       curSubFileCond->dataName, myRescName,
                                       0, 0, 1, &dataObjInfo );
        if ( status >= 0 ) {
            setSubPhyPath( phyBunDir, curSubFileCond->dataId,
                           curSubFileCond->subPhyPath );
            rstrcpy( curSubFileCond->cachePhyPath, dataObjInfo.filePath,
                     MAX_NAME_LEN );
            curSubFileCond->cacheReplNum = dataObjInfo.replNum;
            curSubFileCond->subFileSize = dataObjInfo.dataSize;
        }
    }
    status = addSubFileToDir( curSubFileCond, bunReplCacheHeader );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "_rsPhyBundleColl:addSubFileToDir error for %s,stst=%d",
                 curSubFileCond->subPhyPath, status );
    }
    return status;
}
Пример #2
0
int
chkCollForBundleOpr( rsComm_t *rsComm,
                     chkObjPermAndStat_t *chkObjPermAndStatInp ) {
#ifdef RODS_CAT
    int status;
    collInp_t openCollInp;
    collEnt_t *collEnt = NULL;
    collEnt_t *curCollEnt = NULL;
    int handleInx;
    int curCopyGood = False;
    char *resource;
    char *resc_hier;
    rodsLong_t myId;
    char myPath[MAX_NAME_LEN];

    if ( ( resource = getValByKey( &chkObjPermAndStatInp->condInput,
                                   RESC_NAME_KW ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "chkCollForBundleOpr: RESC_NAME_KW not specified for %s",
                 chkObjPermAndStatInp->objPath );
        return SYS_INVALID_RESC_INPUT;
    }

    if ( ( resc_hier = getValByKey( &chkObjPermAndStatInp->condInput,
                                    RESC_HIER_STR_KW ) ) == NULL ) {
        rodsLog( LOG_ERROR,
                 "chkCollForBundleOpr: RESC_HIER_STR_KW not specified for %s",
                 chkObjPermAndStatInp->objPath );
        return SYS_INVALID_RESC_INPUT;
    }

    memset( &openCollInp, 0, sizeof( openCollInp ) );
    rstrcpy( openCollInp.collName, chkObjPermAndStatInp->objPath, MAX_NAME_LEN );
    openCollInp.flags =
        RECUR_QUERY_FG | LONG_METADATA_FG | NO_TRIM_REPL_FG;
    handleInx = rsOpenCollection( rsComm, &openCollInp );
    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "chkCollForBundleOpr: rsOpenCollection of %s error. status = %d",
                 openCollInp.collName, handleInx );
        return handleInx;
    }
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( collEnt->specColl.collClass != NO_SPEC_COLL ) {
            if ( strcmp( resource, collEnt->specColl.resource ) != 0 ) {
                rodsLog( LOG_ERROR,
                         "chkCollForBundleOpr: specColl resc %s does not match %s",
                         collEnt->specColl.resource, resource );
                rsCloseCollection( rsComm, &handleInx );
                return SYS_COPY_NOT_EXIST_IN_RESC;
            }
            /* check permission */
            myId = chlCheckAndGetObjectID( rsComm, "-c",
                                           collEnt->specColl.collection, ACCESS_READ_OBJECT );
            if ( myId < 0 ) {
                status = myId;
                rodsLog( LOG_ERROR,
                         "chkCollForBundleOpr: no accPerm to specColl %s. status = %d",
                         collEnt->specColl.collection, status );
                rsCloseCollection( rsComm, &handleInx );
                return status;
            }
            free( collEnt );
            collEnt = NULL;
            continue;
        }

        if ( collEnt->objType == DATA_OBJ_T ) {
            if ( curCollEnt == NULL ) {
                curCollEnt = collEnt;
                saveCollEntForChkColl( collEnt );
                if ( collEnt->replStatus > 0 &&
                        strcmp( resource,  collEnt->resource ) == 0 &&
                        strcmp( resc_hier, collEnt->resc_hier ) == 0 ) {
                    curCopyGood = True;
                }
            }
            else {
                if ( strcmp( curCollEnt->dataName, collEnt->dataName ) == 0 &&
                        strcmp( curCollEnt->collName, collEnt->collName ) == 0 ) {
                    if ( collEnt->replStatus                     >  0 &&
                            strcmp( resource,  collEnt->resource ) == 0 &&
                            strcmp( resc_hier, collEnt->resc_hier ) == 0 ) {
                        /* a good copy */
                        freeCollEntForChkColl( curCollEnt );
                        curCopyGood = True;
                        curCollEnt = collEnt;
                        saveCollEntForChkColl( collEnt );
                    }
                }
                else {
                    /* encounter a new data obj */
                    snprintf( myPath, MAX_NAME_LEN, "%s/%s",
                              curCollEnt->collName, curCollEnt->dataName );

                    if ( curCopyGood == False ) {
                        status = replDataObjForBundle( rsComm,
                                                       curCollEnt->collName, curCollEnt->dataName,
                                                       resource, curCollEnt->resc_hier, resc_hier, 0, NULL );

                        if ( status < 0 ) {
                            rodsLog( LOG_ERROR,
                                     "chkCollForBundleOpr: %s no good copy in %s [%d]",
                                     myPath, resource, status );
                            rsCloseCollection( rsComm, &handleInx );
                            freeCollEntForChkColl( curCollEnt );
                            return SYS_COPY_NOT_EXIST_IN_RESC;
                        }
                    }
                    else {

                    }
                    freeCollEntForChkColl( curCollEnt );
                    curCopyGood = False;
                    curCollEnt = NULL;

                    /* we have a good copy. Check the permission */
                    myId = chlCheckAndGetObjectID( rsComm, "-d", myPath,
                                                   ACCESS_READ_OBJECT );
                    if ( myId < 0 && myId != CAT_UNKNOWN_FILE ) {
                        /* could return CAT_UNKNOWN_FILE if mounted files */
                        status = myId;
                        rodsLog( LOG_ERROR,
                                 "chkCollForBundleOpr: no accPerm to %s. status = %d",
                                 myPath, status );
                        rsCloseCollection( rsComm, &handleInx );
                        return status;
                    }
                    else {
                        /* copy is OK */
                        curCollEnt = collEnt;
                        saveCollEntForChkColl( collEnt );
                        collEnt = NULL;
                        if ( curCollEnt->replStatus > 0 &&
                                strcmp( resource, curCollEnt->resource ) == 0 &&
                                strcmp( resc_hier, curCollEnt->resc_hier ) == 0 ) {
                            /* a good copy */
                            curCopyGood = True;
                        }
                    }
                }
            }
        }
        else {
            free( collEnt );
        }
    }

    /* handle what's left */
    if ( curCollEnt != NULL ) {
        if ( curCopyGood == False ) {
            status = replDataObjForBundle( rsComm, curCollEnt->collName,
                                           curCollEnt->dataName, resource, curCollEnt->resc_hier, resc_hier, 0, NULL );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "chkCollForBundleOpr:%s does not have a good copy in %s",
                         chkObjPermAndStatInp->objPath, resource );
                status = SYS_COPY_NOT_EXIST_IN_RESC;
            }
        }
        else {
            freeCollEntForChkColl( curCollEnt );
        }
    }
    else {
        status = 0;
    }

    rsCloseCollection( rsComm, &handleInx );

    return 0;
#else
    return SYS_NO_RCAT_SERVER_ERR;
#endif
}