00001
00002
00003
00004
00005
00006 #include "collRepl.h"
00007 #include "dataObjOpr.h"
00008 #include "rodsLog.h"
00009 #include "objMetaOpr.h"
00010 #include "reGlobalsExtern.h"
00011 #include "reDefines.h"
00012 #include "openCollection.h"
00013 #include "readCollection.h"
00014 #include "closeCollection.h"
00015 #include "dataObjRepl.h"
00016 #include "rsApiHandler.h"
00017 #include "getRemoteZoneResc.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 int
00029 rsCollRepl (rsComm_t *rsComm, collInp_t *collReplInp,
00030 collOprStat_t **collOprStat)
00031 {
00032 int status;
00033 dataObjInp_t dataObjInp;
00034 collEnt_t *collEnt;
00035 int handleInx;
00036 transferStat_t myTransStat;
00037 int totalFileCnt;
00038 int fileCntPerStatOut;
00039 int savedStatus = 0;
00040 int remoteFlag;
00041 rodsServerHost_t *rodsServerHost;
00042
00043
00044 bzero (&dataObjInp, sizeof (dataObjInp));
00045 rstrcpy (dataObjInp.objPath, collReplInp->collName, MAX_NAME_LEN);
00046 remoteFlag = getAndConnRemoteZone (rsComm, &dataObjInp, &rodsServerHost,
00047 REMOTE_CREATE);
00048
00049 if (remoteFlag < 0) {
00050 return (remoteFlag);
00051 } else if (remoteFlag == REMOTE_HOST) {
00052 int retval;
00053 retval = _rcCollRepl (rodsServerHost->conn, collReplInp, collOprStat);
00054 if (retval < 0) return retval;
00055 status = svrSendZoneCollOprStat (rsComm, rodsServerHost->conn,
00056 *collOprStat, retval);
00057 return status;
00058 }
00059
00060 fileCntPerStatOut = FILE_CNT_PER_STAT_OUT;
00061 if (collOprStat != NULL) *collOprStat = NULL;
00062 collReplInp->flags = RECUR_QUERY_FG;
00063 handleInx = rsOpenCollection (rsComm, collReplInp);
00064 if (handleInx < 0) {
00065 rodsLog (LOG_ERROR,
00066 "rsCollRepl: rsOpenCollection of %s error. status = %d",
00067 collReplInp->collName, handleInx);
00068 return (handleInx);
00069 }
00070
00071 if (collOprStat != NULL) {
00072 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00073 memset (*collOprStat, 0, sizeof (collOprStat_t));
00074 }
00075
00076 if (CollHandle[handleInx].rodsObjStat->specColl != NULL) {
00077 rodsLog (LOG_ERROR,
00078 "rsCollRepl: unable to replicate mounted collection %s",
00079 collReplInp->collName);
00080 rsCloseCollection (rsComm, &handleInx);
00081 return (0);
00082 }
00083
00084 while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
00085 if (collEnt->objType == DATA_OBJ_T) {
00086 if (totalFileCnt == 0) totalFileCnt =
00087 CollHandle[handleInx].dataObjSqlResult.totalRowCount;
00088
00089 bzero (&dataObjInp, sizeof (dataObjInp));
00090 snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
00091 collEnt->collName, collEnt->dataName);
00092 dataObjInp.condInput = collReplInp->condInput;
00093
00094 memset (&myTransStat, 0, sizeof (myTransStat));
00095 status = _rsDataObjRepl (rsComm, &dataObjInp,
00096 &myTransStat, NULL);
00097
00098 if (status == SYS_COPY_ALREADY_IN_RESC) {
00099 savedStatus = status;
00100 status = 0;
00101 }
00102
00103 if (status < 0) {
00104 rodsLogError (LOG_ERROR, status,
00105 "rsCollRepl: rsDataObjRepl failed for %s. status = %d",
00106 dataObjInp.objPath, status);
00107 savedStatus = status;
00108 break;
00109 } else {
00110 if (collOprStat != NULL) {
00111 (*collOprStat)->bytesWritten += myTransStat.bytesWritten;
00112 (*collOprStat)->filesCnt ++;
00113 }
00114 }
00115 if (collOprStat != NULL &&
00116 (*collOprStat)->filesCnt >= fileCntPerStatOut) {
00117 rstrcpy ((*collOprStat)->lastObjPath, dataObjInp.objPath,
00118 MAX_NAME_LEN);
00119 (*collOprStat)->totalFileCnt = totalFileCnt;
00120 status = svrSendCollOprStat (rsComm, *collOprStat);
00121 if (status < 0) {
00122 rodsLogError (LOG_ERROR, status,
00123 "rsCollRepl: svrSendCollOprStat failed for %s. status = %d",
00124 dataObjInp.objPath, status);
00125 *collOprStat = NULL;
00126 savedStatus = status;
00127 break;
00128 }
00129 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00130 memset (*collOprStat, 0, sizeof (collOprStat_t));
00131 }
00132 }
00133 free (collEnt);
00134 }
00135 rsCloseCollection (rsComm, &handleInx);
00136
00137 return (savedStatus);
00138 }
00139
00140 #ifdef COMPAT_201
00141 int
00142 rsCollRepl201 (rsComm_t *rsComm, dataObjInp_t *collReplInp,
00143 collOprStat_t **collOprStat)
00144 {
00145 collInp_t collInp;
00146 int status;
00147
00148 bzero (&collInp, sizeof (collInp));
00149
00150 rstrcpy (collInp.collName, collReplInp->objPath, MAX_NAME_LEN);
00151 collInp.flags = collReplInp->openFlags;
00152 collInp.oprType = collReplInp->oprType;
00153 collInp.condInput = collReplInp->condInput;
00154
00155 status = rsCollRepl (rsComm, &collInp, collOprStat);
00156
00157 return status;
00158 }
00159 #endif
00160