00001
00002
00003
00004
00005
00006 #include "phyBundleColl.h"
00007 #include "objMetaOpr.h"
00008 #include "resource.h"
00009 #include "collection.h"
00010 #include "specColl.h"
00011 #include "physPath.h"
00012 #include "dataObjOpr.h"
00013 #include "miscServerFunct.h"
00014 #include "openCollection.h"
00015 #include "readCollection.h"
00016 #include "closeCollection.h"
00017 #include "dataObjRepl.h"
00018 #include "dataObjUnlink.h"
00019 #include "dataObjCreate.h"
00020 #include "syncMountedColl.h"
00021 #include "regReplica.h"
00022 #include "unbunAndRegPhyBunfile.h"
00023 #include "fileChksum.h"
00024
00025 static rodsLong_t OneGig = (1024*1024*1024);
00026
00027 int
00028 rsPhyBundleColl (rsComm_t *rsComm, structFileExtAndRegInp_t *phyBundleCollInp)
00029 {
00030 char *destRescName;
00031 int status;
00032 rodsServerHost_t *rodsServerHost;
00033 int remoteFlag;
00034 rodsHostAddr_t rescAddr;
00035 rescGrpInfo_t *rescGrpInfo = NULL;
00036
00037 specCollCache_t *specCollCache = NULL;
00038
00039 resolveLinkedPath (rsComm, phyBundleCollInp->objPath, &specCollCache,
00040 &phyBundleCollInp->condInput);
00041
00042 resolveLinkedPath (rsComm, phyBundleCollInp->collection,
00043 &specCollCache, NULL);
00044
00045 if ((destRescName = getValByKey (&phyBundleCollInp->condInput,
00046 DEST_RESC_NAME_KW)) == NULL) {
00047 return USER_NO_RESC_INPUT_ERR;
00048 }
00049
00050 if (isLocalZone (phyBundleCollInp->collection) == 0) {
00051
00052 return SYS_INVALID_ZONE_NAME;
00053 }
00054 status = _getRescInfo (rsComm, destRescName, &rescGrpInfo);
00055 if (status < 0 || NULL == rescGrpInfo ) {
00056 rodsLog (LOG_ERROR,
00057 "rsPhyBundleColl: _getRescInfo of %s error for %s. stat = %d",
00058 destRescName, phyBundleCollInp->collection, status);
00059 return status;
00060 }
00061
00062 bzero (&rescAddr, sizeof (rescAddr));
00063 rstrcpy (rescAddr.hostAddr, rescGrpInfo->rescInfo->rescLoc, NAME_LEN);
00064 remoteFlag = resolveHost (&rescAddr, &rodsServerHost);
00065
00066 if (remoteFlag == LOCAL_HOST) {
00067 status = _rsPhyBundleColl (rsComm, phyBundleCollInp, rescGrpInfo);
00068 } else if (remoteFlag == REMOTE_HOST) {
00069 status = remotePhyBundleColl (rsComm, phyBundleCollInp, rodsServerHost);
00070 } else if (remoteFlag < 0) {
00071 status = remoteFlag;
00072 }
00073
00074 return status;
00075 }
00076
00077 int
00078 _rsPhyBundleColl (rsComm_t *rsComm, structFileExtAndRegInp_t *phyBundleCollInp,
00079 rescGrpInfo_t *rescGrpInfo)
00080 {
00081 rescInfo_t *myRescInfo;
00082 char *myRescName;
00083 collInp_t collInp;
00084 collEnt_t *collEnt;
00085 char phyBunDir[MAX_NAME_LEN];
00086 curSubFileCond_t curSubFileCond;
00087 int handleInx;
00088 int status, l1descInx;
00089 dataObjInp_t dataObjInp;
00090 bunReplCacheHeader_t bunReplCacheHeader;
00091 int savedStatus = 0;
00092 int chksumFlag, maxSubFileCnt;
00093 char *dataType = NULL;
00094
00095 myRescInfo = rescGrpInfo->rescInfo;
00096 myRescName = myRescInfo->rescName;
00097 bzero (&collInp, sizeof (collInp));
00098 rstrcpy (collInp.collName, phyBundleCollInp->collection, MAX_NAME_LEN);
00099 collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG |
00100 NO_TRIM_REPL_FG;
00101 handleInx = rsOpenCollection (rsComm, &collInp);
00102 if (handleInx < 0) {
00103 rodsLog (LOG_ERROR,
00104 "_rsPhyBundleColl: rsOpenCollection of %s error. status = %d",
00105 collInp.collName, handleInx);
00106 return (handleInx);
00107 }
00108
00109 if (CollHandle[handleInx].rodsObjStat->specColl != NULL) {
00110 rodsLog (LOG_ERROR,
00111 "_rsPhyBundleColl: unable to bundle special collection %s",
00112 collInp.collName);
00113 rsCloseCollection (rsComm, &handleInx);
00114 return (0);
00115 }
00116
00117
00118 dataType = getValByKey (&phyBundleCollInp->condInput, DATA_TYPE_KW);
00119 l1descInx = createPhyBundleDataObj (rsComm, phyBundleCollInp->collection,
00120 rescGrpInfo, &dataObjInp, dataType );
00121
00122 if (l1descInx < 0) return l1descInx;
00123
00124
00125 if (getValByKey (&phyBundleCollInp->condInput, VERIFY_CHKSUM_KW) != NULL) {
00126 L1desc[l1descInx].chksumFlag = VERIFY_CHKSUM;
00127 chksumFlag = 1;
00128 } else {
00129 chksumFlag = 0;
00130 }
00131
00132
00133 if (getValByKey (&phyBundleCollInp->condInput, MAX_SUB_FILE_KW) != NULL) {
00134 maxSubFileCnt = atoi(getValByKey (&phyBundleCollInp->condInput, MAX_SUB_FILE_KW));
00135 } else {
00136 maxSubFileCnt = MAX_SUB_FILE_CNT;
00137 }
00138
00139 createPhyBundleDir (rsComm, L1desc[l1descInx].dataObjInfo->filePath,
00140 phyBunDir);
00141
00142 bzero (&bunReplCacheHeader, sizeof (bunReplCacheHeader));
00143 bzero (&curSubFileCond, sizeof (curSubFileCond));
00144 while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
00145 if (collEnt->objType == DATA_OBJ_T) {
00146 if (curSubFileCond.collName[0] == '\0') {
00147
00148 rstrcpy (curSubFileCond.collName, collEnt->collName,
00149 MAX_NAME_LEN);
00150 rstrcpy (curSubFileCond.dataName, collEnt->dataName,
00151 MAX_NAME_LEN);
00152 curSubFileCond.dataId = strtoll (collEnt->dataId, 0, 0);
00153 } else if (strcmp (curSubFileCond.collName, collEnt->collName) != 0
00154 || strcmp (curSubFileCond.dataName, collEnt->dataName) != 0) {
00155
00156 if (bunReplCacheHeader.numSubFiles >= maxSubFileCnt ||
00157 bunReplCacheHeader.totSubFileSize + collEnt->dataSize >
00158 MAX_BUNDLE_SIZE * OneGig) {
00159
00160 status = bundlleAndRegSubFiles (rsComm, l1descInx,
00161 phyBunDir, phyBundleCollInp->collection,
00162 &bunReplCacheHeader, chksumFlag);
00163 if (status < 0) {
00164 rodsLog (LOG_ERROR,
00165 "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stst=%d",
00166 phyBundleCollInp->collection, status);
00167 savedStatus = status;
00168 } else {
00169
00170 l1descInx = createPhyBundleDataObj (rsComm,
00171 phyBundleCollInp->collection, rescGrpInfo,
00172 &dataObjInp, dataType);
00173
00174 if (l1descInx < 0) {
00175 rodsLog (LOG_ERROR,
00176 "_rsPhyBundleColl:createPhyBundleDataObj err for %s,stat=%d",
00177 phyBundleCollInp->collection, l1descInx);
00178 return (l1descInx);
00179 }
00180
00181 createPhyBundleDir (rsComm,
00182 L1desc[l1descInx].dataObjInfo->filePath, phyBunDir);
00183
00184
00185
00186
00187
00188 if (curSubFileCond.subPhyPath[0] != '\0')
00189 setSubPhyPath (phyBunDir, curSubFileCond.dataId,
00190 curSubFileCond.subPhyPath);
00191
00192 }
00193 }
00194 status = replAndAddSubFileToDir (rsComm, &curSubFileCond,
00195 myRescName, phyBunDir, &bunReplCacheHeader);
00196 if (status < 0) {
00197 savedStatus = status;
00198 rodsLog (LOG_ERROR,
00199 "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,sta=%d",
00200 curSubFileCond.subPhyPath, status);
00201 }
00202 curSubFileCond.bundled = 0;
00203 curSubFileCond.subPhyPath[0] =
00204 curSubFileCond.cachePhyPath[0] = '\0';
00205 rstrcpy (curSubFileCond.collName, collEnt->collName,
00206 MAX_NAME_LEN);
00207 rstrcpy (curSubFileCond.dataName, collEnt->dataName,
00208 MAX_NAME_LEN);
00209 curSubFileCond.dataId = strtoll (collEnt->dataId, 0, 0);
00210 }
00211
00212 if (curSubFileCond.bundled > 0) {
00213
00214 } else if (isDataObjBundled (rsComm, collEnt)) {
00215
00216 curSubFileCond.bundled = 1;
00217 curSubFileCond.subPhyPath[0] = '\0';
00218 curSubFileCond.cachePhyPath[0] = '\0';
00219
00220
00221 } else if( ( collEnt->replStatus > 0 || curSubFileCond.subPhyPath[0] == '\0') &&
00222 strcmp (collEnt->resource, myRescName) == 0) {
00223
00224 setSubPhyPath (phyBunDir, curSubFileCond.dataId, curSubFileCond.subPhyPath);
00225 rstrcpy (curSubFileCond.cachePhyPath, collEnt->phyPath, MAX_NAME_LEN);
00226 curSubFileCond.cacheReplNum = collEnt->replNum;
00227 curSubFileCond.subFileSize = collEnt->dataSize;
00228 }
00229 }
00230 free (collEnt);
00231 }
00232
00233
00234 status = replAndAddSubFileToDir (rsComm, &curSubFileCond,
00235 myRescName, phyBunDir, &bunReplCacheHeader);
00236 if (status < 0) {
00237 savedStatus = status;
00238 rodsLog (LOG_ERROR,
00239 "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,stat=%d",
00240 curSubFileCond.subPhyPath, status);
00241 }
00242
00243 status = bundlleAndRegSubFiles (rsComm, l1descInx, phyBunDir,
00244 phyBundleCollInp->collection, &bunReplCacheHeader, chksumFlag);
00245 if (status < 0) {
00246 rodsLog (LOG_ERROR,
00247 "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stat=%d",
00248 phyBundleCollInp->collection, status);
00249 }
00250 if (status >= 0 && savedStatus < 0) {
00251 return savedStatus;
00252 } else {
00253 return status;
00254 }
00255 }
00256
00257 int
00258 replAndAddSubFileToDir (rsComm_t *rsComm, curSubFileCond_t *curSubFileCond,
00259 char *myRescName, char *phyBunDir, bunReplCacheHeader_t *bunReplCacheHeader)
00260 {
00261 int status;
00262 dataObjInfo_t dataObjInfo;
00263
00264 if (curSubFileCond->bundled == 1) {
00265 return 0;
00266 }
00267
00268 bzero (&dataObjInfo, sizeof (dataObjInfo));
00269
00270 if (curSubFileCond->subPhyPath[0] == '\0') {
00271
00272 status = replDataObjForBundle (rsComm, curSubFileCond->collName,
00273 curSubFileCond->dataName, myRescName, 1, &dataObjInfo);
00274 if (status >= 0) {
00275 setSubPhyPath (phyBunDir, curSubFileCond->dataId,
00276 curSubFileCond->subPhyPath);
00277 rstrcpy (curSubFileCond->cachePhyPath, dataObjInfo.filePath,
00278 MAX_NAME_LEN);
00279 curSubFileCond->cacheReplNum = dataObjInfo.replNum;
00280 curSubFileCond->subFileSize = dataObjInfo.dataSize;
00281 }
00282 }
00283 status = addSubFileToDir (curSubFileCond, bunReplCacheHeader);
00284 if (status < 0) {
00285 rodsLog (LOG_ERROR,
00286 "_rsPhyBundleColl:addSubFileToDir error for %s,stst=%d",
00287 curSubFileCond->subPhyPath, status);
00288 }
00289 return status;
00290 }
00291
00292 int
00293 bundlleAndRegSubFiles (rsComm_t *rsComm, int l1descInx, char *phyBunDir,
00294 char *collection, bunReplCacheHeader_t *bunReplCacheHeader, int chksumFlag)
00295 {
00296 int status;
00297 openedDataObjInp_t dataObjCloseInp;
00298 bunReplCache_t *tmpBunReplCache, *nextBunReplCache;
00299 regReplica_t regReplicaInp;
00300 dataObjInp_t dataObjUnlinkInp;
00301 keyValPair_t regParam;
00302 modDataObjMeta_t modDataObjMetaInp;
00303
00304 int savedStatus = 0;
00305
00306 bzero (&dataObjCloseInp, sizeof (dataObjCloseInp));
00307 dataObjCloseInp.l1descInx = l1descInx;
00308 if (bunReplCacheHeader->numSubFiles == 0) {
00309 bzero (&dataObjUnlinkInp, sizeof (dataObjUnlinkInp));
00310 rstrcpy (dataObjUnlinkInp.objPath,
00311 L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN);
00312 dataObjUnlinkS (rsComm, &dataObjUnlinkInp,
00313 L1desc[l1descInx].dataObjInfo);
00314 L1desc[l1descInx].bytesWritten = 0;
00315 rsDataObjClose (rsComm, &dataObjCloseInp);
00316 bzero (bunReplCacheHeader, sizeof (bunReplCacheHeader_t));
00317 return 0;
00318 }
00319
00320 status = phyBundle (rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
00321 collection, CREATE_TAR_OPR);
00322 if (status < 0) {
00323 rodsLog (LOG_ERROR,
00324 "bundlleAndRegSubFiles: rsStructFileSync of %s error. stat = %d",
00325 L1desc[l1descInx].dataObjInfo->objPath, status);
00326 rmLinkedFilesInUnixDir (phyBunDir);
00327 rmdir (phyBunDir);
00328 rsDataObjClose (rsComm, &dataObjCloseInp);
00329 tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead;
00330 while (tmpBunReplCache != NULL) {
00331 nextBunReplCache = tmpBunReplCache->next;
00332 free (tmpBunReplCache);
00333 tmpBunReplCache = nextBunReplCache;
00334 }
00335 bzero (bunReplCacheHeader, sizeof (bunReplCacheHeader_t));
00336 return status;
00337 } else {
00338
00339 L1desc[l1descInx].bytesWritten = 1;
00340 }
00341
00342
00343 tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead;
00344
00345 if (tmpBunReplCache == NULL) {
00346 rmdir (phyBunDir);
00347 bzero (&dataObjUnlinkInp, sizeof (dataObjUnlinkInp));
00348 rstrcpy (dataObjUnlinkInp.objPath,
00349 L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN);
00350 dataObjUnlinkS (rsComm, &dataObjUnlinkInp,
00351 L1desc[l1descInx].dataObjInfo);
00352 L1desc[l1descInx].bytesWritten = 0;
00353 rsDataObjClose (rsComm, &dataObjCloseInp);
00354 bzero (bunReplCacheHeader, sizeof (bunReplCacheHeader_t));
00355 return 0;
00356 }
00357
00358 bzero (®ReplicaInp, sizeof (regReplicaInp));
00359 regReplicaInp.srcDataObjInfo = (dataObjInfo_t*)malloc (sizeof (dataObjInfo_t));
00360 regReplicaInp.destDataObjInfo = (dataObjInfo_t*)malloc (sizeof (dataObjInfo_t));
00361 bzero (regReplicaInp.srcDataObjInfo, sizeof (dataObjInfo_t));
00362 bzero (regReplicaInp.destDataObjInfo, sizeof (dataObjInfo_t));
00363 addKeyVal (®ReplicaInp.condInput, IRODS_ADMIN_KW, "");
00364 rstrcpy (regReplicaInp.destDataObjInfo->rescName, BUNDLE_RESC, NAME_LEN);
00365 rstrcpy (regReplicaInp.destDataObjInfo->filePath,
00366 L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN);
00367
00368
00369 if (chksumFlag != 0) {
00370 bzero (&modDataObjMetaInp, sizeof (modDataObjMetaInp));
00371 bzero (®Param, sizeof (regParam));
00372 modDataObjMetaInp.dataObjInfo = regReplicaInp.destDataObjInfo;
00373 modDataObjMetaInp.regParam = ®Param;
00374 }
00375
00376
00377
00378
00379 rsDataObjClose (rsComm, &dataObjCloseInp);
00380 while (tmpBunReplCache != NULL) {
00381 char subPhyPath[MAX_NAME_LEN];
00382
00383 nextBunReplCache = tmpBunReplCache->next;
00384
00385 snprintf (subPhyPath, MAX_NAME_LEN, "%s/%lld", phyBunDir,
00386 tmpBunReplCache->dataId);
00387
00388
00389 if (chksumFlag != 0) {
00390 status = fileChksum (UNIX_FILE_TYPE, rsComm, subPhyPath, tmpBunReplCache->chksumStr);
00391 if (status < 0) {
00392 savedStatus = status;
00393 rodsLogError (LOG_ERROR, status,"bundlleAndRegSubFiles: fileChksum error for %s",tmpBunReplCache->objPath);
00394 }
00395 }
00396
00397 unlink (subPhyPath);
00398
00399 rstrcpy (regReplicaInp.srcDataObjInfo->objPath,
00400 tmpBunReplCache->objPath, MAX_NAME_LEN);
00401 regReplicaInp.srcDataObjInfo->dataId =
00402 regReplicaInp.destDataObjInfo->dataId =
00403 tmpBunReplCache->dataId;
00404 regReplicaInp.srcDataObjInfo->replNum = tmpBunReplCache->srcReplNum;
00405 status = rsRegReplica (rsComm, ®ReplicaInp);
00406 if (status < 0) {
00407 savedStatus = status;
00408 rodsLog (LOG_ERROR,
00409 "bundlleAndRegSubFiles: rsRegReplica error for %s. stat = %d",
00410 tmpBunReplCache->objPath, status);
00411 }
00412
00413
00414 if (chksumFlag != 0) {
00415 addKeyVal (®Param, CHKSUM_KW, tmpBunReplCache->chksumStr);
00416 status = rsModDataObjMeta (rsComm, &modDataObjMetaInp);
00417 clearKeyVal (®Param);
00418 if (status < 0) {
00419 savedStatus = status;
00420 rodsLogError (LOG_ERROR, status, "bundlleAndRegSubFiles: rsModDataObjMeta error for %s.", tmpBunReplCache->objPath);
00421 }
00422 }
00423
00424 free (tmpBunReplCache);
00425 tmpBunReplCache = nextBunReplCache;
00426 }
00427 clearKeyVal (®ReplicaInp.condInput);
00428 free (regReplicaInp.srcDataObjInfo);
00429 free (regReplicaInp.destDataObjInfo);
00430 bzero (bunReplCacheHeader, sizeof (bunReplCacheHeader_t));
00431 rmdir (phyBunDir);
00432
00433 if (status >= 0 && savedStatus < 0) {
00434 return savedStatus;
00435 } else {
00436 return status;
00437 }
00438 }
00439
00440
00441
00442
00443 int
00444 phyBundle (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo, char *phyBunDir,
00445 char *collection, int oprType )
00446 {
00447 structFileOprInp_t structFileOprInp;
00448 int status;
00449 char *dataType;
00450 int myOprType = oprType;
00451
00452 dataType = dataObjInfo->dataType;
00453 if ((oprType & ADD_TO_TAR_OPR) != 0) {
00454
00455 if( dataType != NULL &&
00456 ( strstr( dataType, GZIP_TAR_DT_STR ) != NULL ||
00457 strstr (dataType, BZIP2_TAR_DT_STR) != NULL)) {
00458
00459
00460 status = unbunPhyBunFile (rsComm, dataObjInfo->objPath,
00461 dataObjInfo->rescInfo, dataObjInfo->filePath, phyBunDir,
00462 dataType, PRESERVE_DIR_CONT);
00463 if (status < 0) return status;
00464
00465 myOprType = myOprType ^ ADD_TO_TAR_OPR;
00466 }
00467 }
00468
00469
00470 bzero (&structFileOprInp, sizeof (structFileOprInp));
00471
00472 structFileOprInp.specColl = (specColl_t*)malloc (sizeof (specColl_t));
00473 memset (structFileOprInp.specColl, 0, sizeof (specColl_t));
00474 structFileOprInp.specColl->type = TAR_STRUCT_FILE_T;
00475
00476
00477 rstrcpy (structFileOprInp.specColl->collection,
00478 collection, MAX_NAME_LEN);
00479 rstrcpy (structFileOprInp.specColl->objPath,
00480 dataObjInfo->objPath, MAX_NAME_LEN);
00481 structFileOprInp.specColl->collClass = STRUCT_FILE_COLL;
00482 rstrcpy (structFileOprInp.specColl->resource, dataObjInfo->rescName,
00483 NAME_LEN);
00484 rstrcpy (structFileOprInp.specColl->phyPath,
00485 dataObjInfo->filePath, MAX_NAME_LEN);
00486 rstrcpy (structFileOprInp.addr.hostAddr, dataObjInfo->rescInfo->rescLoc,
00487 NAME_LEN);
00488 rstrcpy (structFileOprInp.specColl->cacheDir, phyBunDir, MAX_NAME_LEN);
00489 structFileOprInp.specColl->cacheDirty = 1;
00490
00491 structFileOprInp.oprType = NO_REG_COLL_INFO | myOprType;
00492 if( dataType != NULL &&
00493 ( strstr( dataType, GZIP_TAR_DT_STR) != NULL ||
00494 strstr( dataType, BZIP2_TAR_DT_STR) != NULL ||
00495 strstr( dataType, ZIP_DT_STR) != NULL ) ) {
00496 addKeyVal (&structFileOprInp.condInput, DATA_TYPE_KW, dataType);
00497 }
00498
00499 status = rsStructFileSync (rsComm, &structFileOprInp);
00500
00501 free (structFileOprInp.specColl);
00502
00503 if ((oprType & ADD_TO_TAR_OPR) != 0 && (myOprType & ADD_TO_TAR_OPR) == 0) {
00504 rmUnlinkedFilesInUnixDir (phyBunDir);
00505 }
00506
00507 if (status < 0) {
00508 rodsLog (LOG_ERROR,
00509 "phyBundle: rsStructFileSync of %s error. stat = %d",
00510 dataObjInfo->objPath, status);
00511 }
00512
00513 return status;
00514 }
00515
00516 int
00517 addSubFileToDir (curSubFileCond_t *curSubFileCond,
00518 bunReplCacheHeader_t *bunReplCacheHeader)
00519 {
00520 int status;
00521 bunReplCache_t *bunReplCache;
00522
00523
00524 status = link (curSubFileCond->cachePhyPath, curSubFileCond->subPhyPath);
00525 if (status < 0) {
00526 rodsLog (LOG_ERROR,
00527 "addSubFileToDir: link error %s to %s. errno = %d",
00528 curSubFileCond->cachePhyPath, curSubFileCond->subPhyPath, errno);
00529 return (UNIX_FILE_LINK_ERR - errno);
00530 }
00531 bunReplCache = (bunReplCache_t*)malloc (sizeof (bunReplCache_t));
00532 bzero (bunReplCache, sizeof (bunReplCache_t));
00533 bunReplCache->dataId = curSubFileCond->dataId;
00534 snprintf (bunReplCache->objPath, MAX_NAME_LEN, "%s/%s",
00535 curSubFileCond->collName, curSubFileCond->dataName);
00536 bunReplCache->srcReplNum = curSubFileCond->cacheReplNum;
00537 bunReplCache->next = bunReplCacheHeader->bunReplCacheHead;
00538 bunReplCacheHeader->bunReplCacheHead = bunReplCache;
00539 bunReplCacheHeader->numSubFiles++;
00540 bunReplCacheHeader->totSubFileSize += curSubFileCond->subFileSize;
00541
00542 return 0;
00543 }
00544
00545 int
00546 setSubPhyPath (char *phyBunDir, rodsLong_t dataId, char *subPhyPath)
00547 {
00548 snprintf (subPhyPath, MAX_NAME_LEN, "%s/%lld", phyBunDir, dataId);
00549 return 0;
00550 }
00551
00552 int
00553 isDataObjBundled (rsComm_t *rsComm, collEnt_t *collEnt)
00554 {
00555 if (strcmp (collEnt->resource, BUNDLE_RESC) == 0) {
00556 if (collEnt->replStatus > 0) {
00557 return 1;
00558 } else {
00559
00560 return 0;
00561 }
00562 } else {
00563 return 0;
00564 }
00565 }
00566
00567 int
00568 replDataObjForBundle (rsComm_t *rsComm, char *collName, char *dataName,
00569 char *rescName, int adminFlag, dataObjInfo_t *outCacheObjInfo)
00570 {
00571 transferStat_t transStat;
00572 dataObjInp_t dataObjInp;
00573 int status;
00574
00575 if (outCacheObjInfo != NULL)
00576 memset (outCacheObjInfo, 0, sizeof (dataObjInfo_t));
00577 memset (&dataObjInp, 0, sizeof (dataObjInp_t));
00578 memset (&transStat, 0, sizeof (transStat));
00579
00580 snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s", collName, dataName);
00581 addKeyVal (&dataObjInp.condInput, BACKUP_RESC_NAME_KW, rescName);
00582 if (adminFlag > 0)
00583 addKeyVal (&dataObjInp.condInput, IRODS_ADMIN_KW, "");
00584
00585 status = _rsDataObjRepl (rsComm, &dataObjInp, &transStat,
00586 outCacheObjInfo);
00587 clearKeyVal (&dataObjInp.condInput);
00588 return status;
00589 }
00590
00591 int
00592 createPhyBundleDir (rsComm_t *rsComm, char *bunFilePath,
00593 char *outPhyBundleDir)
00594 {
00595
00596 snprintf (outPhyBundleDir, MAX_NAME_LEN, "%s.dir", bunFilePath);
00597 mkdirR ("/", outPhyBundleDir, getDefDirMode ());
00598 return (0);
00599 }
00600
00601 int
00602 createPhyBundleDataObj (rsComm_t *rsComm, char *collection,
00603 rescGrpInfo_t *rescGrpInfo, dataObjInp_t *dataObjInp, char* dataType )
00604 {
00605 int myRanNum;
00606 int l1descInx;
00607 int status;
00608 int rescTypeInx = rescGrpInfo->rescInfo->rescTypeInx;
00609
00610
00611 if (RescTypeDef[rescTypeInx].driverType != UNIX_FILE_TYPE) {
00612 rodsLog (LOG_ERROR,
00613 "createPhyBundleFile: resource %s is not UNIX_FILE_TYPE",
00614 rescGrpInfo->rescInfo->rescName);
00615 return SYS_INVALID_RESC_TYPE;
00616 } else if (getRescClass (rescGrpInfo->rescInfo) != CACHE_CL) {
00617 return SYS_NO_CACHE_RESC_IN_GRP;
00618 }
00619
00620
00621 do {
00622 int loopCnt = 0;
00623 bzero (dataObjInp, sizeof (dataObjInp_t));
00624 while (1) {
00625 myRanNum = random ();
00626 status = rsMkBundlePath (rsComm, collection, dataObjInp->objPath,
00627 myRanNum);
00628 if (status < 0) {
00629 rodsLog (LOG_ERROR,
00630 "createPhyBundleFile: getPhyBundlePath err for %s.stat = %d",
00631 collection, status);
00632 return status;
00633 }
00634
00635 if (isData (rsComm, dataObjInp->objPath, NULL) >= 0) {
00636 if (loopCnt >= 100) {
00637 break;
00638 } else {
00639 loopCnt++;
00640 continue;
00641 }
00642 } else {
00643 break;
00644 }
00645 }
00646
00647 if (dataType != NULL && strstr (dataType, BUNDLE_STR) != NULL) {
00648 addKeyVal (&dataObjInp->condInput, DATA_TYPE_KW, dataType);
00649 } else {
00650
00651 addKeyVal (&dataObjInp->condInput, DATA_TYPE_KW, TAR_BUNDLE_DT_STR);
00652 }
00653
00654 if (dataType != NULL && strstr (dataType, ZIP_DT_STR) != NULL) {
00655
00656 int len = strlen (dataObjInp->objPath);
00657 if (strcmp (&dataObjInp->objPath[len - 4], ".zip") != 0) {
00658 strcat (dataObjInp->objPath, ".zip");
00659 }
00660 }
00661
00662 l1descInx = _rsDataObjCreateWithRescInfo (rsComm, dataObjInp,
00663 rescGrpInfo->rescInfo, rescGrpInfo->rescGroupName);
00664
00665 clearKeyVal (&dataObjInp->condInput);
00666 } while (l1descInx == OVERWRITE_WITHOUT_FORCE_FLAG);
00667
00668 if (l1descInx >= 0) {
00669 l3Close (rsComm, l1descInx);
00670 L1desc[l1descInx].l3descInx = 0;
00671 if (dataType != NULL && strstr (dataType, ZIP_DT_STR) != NULL)
00672 l3Unlink (rsComm, L1desc[l1descInx].dataObjInfo);
00673 }
00674
00675 return l1descInx;
00676 }
00677
00678
00679
00680
00681
00682
00683 int
00684 rsMkBundlePath (rsComm_t *rsComm, char *collection, char *bundlePath,
00685 int myRanNum)
00686 {
00687 int status;
00688 char *tmpStr;
00689 char startBundlePath[MAX_NAME_LEN];
00690 char destBundleColl[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
00691 char *bundlePathPtr;
00692
00693 bundlePathPtr = bundlePath;
00694 *bundlePathPtr = '/';
00695 bundlePathPtr++;
00696 tmpStr = collection + 1;
00697
00698 while (*tmpStr != '\0') {
00699 *bundlePathPtr = *tmpStr;
00700 bundlePathPtr ++;
00701 if (*tmpStr == '/') {
00702 tmpStr ++;
00703 break;
00704 }
00705 tmpStr ++;
00706 }
00707
00708 if (*tmpStr == '\0') {
00709 rodsLog (LOG_ERROR,
00710 "rsMkBundlePath: input path %s too short", collection);
00711 return (USER_INPUT_PATH_ERR);
00712 }
00713
00714
00715 if (strncmp (tmpStr, "trash/", 6) == 0 ||
00716 strncmp (tmpStr, "bundle/", 7) == 0) {
00717 rodsLog (LOG_ERROR,
00718 "rsMkBundlePath: cannot bundle trash or bundle path %s", collection);
00719 return (USER_INPUT_PATH_ERR);
00720 }
00721
00722
00723
00724 *bundlePathPtr = '\0';
00725 rstrcpy (startBundlePath, bundlePath, MAX_NAME_LEN);
00726
00727 snprintf (bundlePathPtr, MAX_NAME_LEN, "bundle/%s.%d", tmpStr, myRanNum);
00728
00729 if ((status = splitPathByKey (bundlePath, destBundleColl, myFile, '/'))
00730 < 0) {
00731 rodsLog (LOG_ERROR,
00732 "rsMkBundlePath: splitPathByKey error for %s ", bundlePath);
00733 return (USER_INPUT_PATH_ERR);
00734 }
00735
00736 status = rsMkCollR (rsComm, startBundlePath, destBundleColl);
00737
00738 if (status < 0) {
00739 rodsLog (LOG_ERROR,
00740 "rsMkBundlePath: rsMkCollR error for startPath %s, destPath %s ",
00741 startBundlePath, destBundleColl);
00742 }
00743
00744 return (status);
00745 }
00746
00747 int
00748 remotePhyBundleColl (rsComm_t *rsComm,
00749 structFileExtAndRegInp_t *phyBundleCollInp, rodsServerHost_t *rodsServerHost)
00750 {
00751 int status;
00752
00753 if (rodsServerHost == NULL) {
00754 rodsLog (LOG_NOTICE,
00755 "remotePhyBundleColl: Invalid rodsServerHost");
00756 return SYS_INVALID_SERVER_HOST;
00757 }
00758
00759 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00760 return status;
00761 }
00762
00763 status = rcPhyBundleColl (rodsServerHost->conn, phyBundleCollInp);
00764 return status;
00765 }
00766