00001
00002
00003
00004
00005
00006 #include "phyPathReg.h"
00007 #include "rodsLog.h"
00008 #include "icatDefines.h"
00009 #include "objMetaOpr.h"
00010 #include "dataObjOpr.h"
00011 #include "collection.h"
00012 #include "specColl.h"
00013 #include "resource.h"
00014 #include "physPath.h"
00015 #include "rsGlobalExtern.h"
00016 #include "rcGlobalExtern.h"
00017 #include "reGlobalsExtern.h"
00018 #include "miscServerFunct.h"
00019 #include "apiHeaderAll.h"
00020
00021
00022
00023
00024 int
00025 phyPathRegNoChkPerm (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00026 {
00027 int status;
00028
00029 addKeyVal (&phyPathRegInp->condInput, NO_CHK_FILE_PERM_KW, "");
00030
00031 status = irsPhyPathReg (rsComm, phyPathRegInp);
00032 return (status);
00033 }
00034
00035 int
00036 rsPhyPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00037 {
00038 int status;
00039
00040 if (getValByKey (&phyPathRegInp->condInput, NO_CHK_FILE_PERM_KW) != NULL &&
00041 rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00042 return SYS_NO_API_PRIV;
00043 }
00044
00045 status = irsPhyPathReg (rsComm, phyPathRegInp);
00046 return (status);
00047 }
00048
00049 int
00050 irsPhyPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00051 {
00052 int status;
00053 rescGrpInfo_t *rescGrpInfo = NULL;
00054 rodsServerHost_t *rodsServerHost = NULL;
00055 int remoteFlag;
00056 int rescCnt;
00057 rodsHostAddr_t addr;
00058 char *tmpStr = NULL;
00059 char *rescGroupName = NULL;
00060 rescInfo_t *tmpRescInfo = NULL;
00061
00062 if ((tmpStr = getValByKey (&phyPathRegInp->condInput,
00063 COLLECTION_TYPE_KW)) != NULL && strcmp (tmpStr, UNMOUNT_STR) == 0) {
00064 status = unmountFileDir (rsComm, phyPathRegInp);
00065 return (status);
00066 } else if (tmpStr != NULL && (strcmp (tmpStr, HAAW_STRUCT_FILE_STR) == 0 ||
00067 strcmp (tmpStr, TAR_STRUCT_FILE_STR) == 0)) {
00068 status = structFileReg (rsComm, phyPathRegInp);
00069 return (status);
00070 } else if (tmpStr != NULL && strcmp (tmpStr, LINK_POINT_STR) == 0) {
00071 status = linkCollReg (rsComm, phyPathRegInp);
00072 return (status);
00073 }
00074
00075 status = getRescInfo (rsComm, NULL, &phyPathRegInp->condInput,
00076 &rescGrpInfo);
00077
00078 if (status < 0) {
00079 rodsLog (LOG_ERROR,
00080 "rsPhyPathReg: getRescInfo error for %s, status = %d",
00081 phyPathRegInp->objPath, status);
00082 return (status);
00083 }
00084
00085 rescCnt = getRescCnt (rescGrpInfo);
00086
00087 if (rescCnt != 1) {
00088 rodsLog (LOG_ERROR,
00089 "rsPhyPathReg: The input resource is not unique for %s",
00090 phyPathRegInp->objPath);
00091 return (SYS_INVALID_RESC_TYPE);
00092 }
00093
00094 if ((rescGroupName = getValByKey (&phyPathRegInp->condInput,
00095 RESC_GROUP_NAME_KW)) != NULL) {
00096 status = getRescInGrp (rsComm, rescGrpInfo->rescInfo->rescName,
00097 rescGroupName, &tmpRescInfo);
00098 if (status < 0) {
00099 rodsLog (LOG_ERROR,
00100 "rsPhyPathReg: resc %s not in rescGrp %s for %s",
00101 rescGrpInfo->rescInfo->rescName, rescGroupName,
00102 phyPathRegInp->objPath);
00103 return SYS_UNMATCHED_RESC_IN_RESC_GRP;
00104 }
00105 }
00106
00107 memset (&addr, 0, sizeof (addr));
00108
00109 rstrcpy (addr.hostAddr, rescGrpInfo->rescInfo->rescLoc, LONG_NAME_LEN);
00110 remoteFlag = resolveHost (&addr, &rodsServerHost);
00111
00112 if (remoteFlag == LOCAL_HOST) {
00113 status = _rsPhyPathReg (rsComm, phyPathRegInp, rescGrpInfo,
00114 rodsServerHost);
00115 } else if (remoteFlag == REMOTE_HOST) {
00116 status = remotePhyPathReg (rsComm, phyPathRegInp, rodsServerHost);
00117 } else {
00118 if (remoteFlag < 0) {
00119 return (remoteFlag);
00120 } else {
00121 rodsLog (LOG_ERROR,
00122 "rsPhyPathReg: resolveHost returned unrecognized value %d",
00123 remoteFlag);
00124 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00125 }
00126 }
00127
00128 return (status);
00129 }
00130
00131 int
00132 remotePhyPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp,
00133 rodsServerHost_t *rodsServerHost)
00134 {
00135 int status;
00136
00137 if (rodsServerHost == NULL) {
00138 rodsLog (LOG_ERROR,
00139 "remotePhyPathReg: Invalid rodsServerHost");
00140 return SYS_INVALID_SERVER_HOST;
00141 }
00142
00143 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00144 return status;
00145 }
00146
00147 status = rcPhyPathReg (rodsServerHost->conn, phyPathRegInp);
00148
00149 if (status < 0) {
00150 rodsLog (LOG_ERROR,
00151 "remotePhyPathReg: rcPhyPathReg failed for %s",
00152 phyPathRegInp->objPath);
00153 }
00154
00155 return (status);
00156 }
00157
00158 int
00159 _rsPhyPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp,
00160 rescGrpInfo_t *rescGrpInfo, rodsServerHost_t *rodsServerHost)
00161 {
00162 int status;
00163 fileOpenInp_t chkNVPathPermInp;
00164 int rescTypeInx;
00165 char *tmpFilePath;
00166 char filePath[MAX_NAME_LEN];
00167 dataObjInfo_t dataObjInfo;
00168 char *tmpStr = NULL;
00169 int chkType = 0;
00170
00171 if ((tmpFilePath = getValByKey (&phyPathRegInp->condInput, FILE_PATH_KW))
00172 == NULL) {
00173 rodsLog (LOG_ERROR,
00174 "_rsPhyPathReg: No filePath input for %s",
00175 phyPathRegInp->objPath);
00176 return (SYS_INVALID_FILE_PATH);
00177 } else {
00178
00179 rstrcpy (filePath, tmpFilePath, MAX_NAME_LEN);
00180 }
00181
00182
00183
00184 memset (&dataObjInfo, 0, sizeof (dataObjInfo));
00185 rstrcpy (dataObjInfo.objPath, phyPathRegInp->objPath, MAX_NAME_LEN);
00186 rstrcpy (dataObjInfo.filePath, filePath, MAX_NAME_LEN);
00187 dataObjInfo.rescInfo = rescGrpInfo->rescInfo;
00188 rstrcpy (dataObjInfo.rescName, rescGrpInfo->rescInfo->rescName,
00189 LONG_NAME_LEN);
00190
00191
00192 if( getValByKey (&phyPathRegInp->condInput, NO_CHK_FILE_PERM_KW) == NULL &&
00193 (chkType = getchkPathPerm (rsComm, phyPathRegInp, &dataObjInfo)) != NO_CHK_PATH_PERM) {
00194
00195 memset (&chkNVPathPermInp, 0, sizeof (chkNVPathPermInp));
00196
00197 rescTypeInx = rescGrpInfo->rescInfo->rescTypeInx;
00198 rstrcpy (chkNVPathPermInp.fileName, filePath, MAX_NAME_LEN);
00199 chkNVPathPermInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
00200 rstrcpy (chkNVPathPermInp.addr.hostAddr,
00201 rescGrpInfo->rescInfo->rescLoc, NAME_LEN);
00202
00203 status = chkFilePathPerm (rsComm, &chkNVPathPermInp, rodsServerHost,chkType);
00204
00205 if (status < 0) {
00206 rodsLog (LOG_ERROR,
00207 "_rsPhyPathReg: chkFilePathPerm error for %s",
00208 phyPathRegInp->objPath);
00209 return (SYS_NO_PATH_PERMISSION);
00210 }
00211 } else {
00212 status = 0;
00213 }
00214
00215 if (getValByKey (&phyPathRegInp->condInput, COLLECTION_KW) != NULL) {
00216 status = dirPathReg (rsComm, phyPathRegInp, filePath,
00217 rescGrpInfo->rescInfo);
00218 } else if ((tmpStr = getValByKey (&phyPathRegInp->condInput,
00219 COLLECTION_TYPE_KW)) != NULL && strcmp (tmpStr, MOUNT_POINT_STR) == 0) {
00220 status = mountFileDir (rsComm, phyPathRegInp, filePath,
00221 rescGrpInfo->rescInfo);
00222 } else {
00223 if (getValByKey (&phyPathRegInp->condInput, REG_REPL_KW) != NULL) {
00224 status = filePathRegRepl (rsComm, phyPathRegInp, filePath,
00225 rescGrpInfo->rescInfo);
00226 } else {
00227 status = filePathReg (rsComm, phyPathRegInp, filePath,
00228 rescGrpInfo->rescInfo);
00229 }
00230 }
00231
00232 return (status);
00233 }
00234
00235 int
00236 filePathRegRepl (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
00237 rescInfo_t *rescInfo)
00238 {
00239 dataObjInfo_t destDataObjInfo, *dataObjInfoHead = NULL;
00240 regReplica_t regReplicaInp;
00241 char *rescGroupName = NULL;
00242 int status;
00243
00244 status = getDataObjInfo (rsComm, phyPathRegInp, &dataObjInfoHead,
00245 ACCESS_READ_OBJECT, 0);
00246
00247 if (status < 0) {
00248 rodsLog (LOG_ERROR,
00249 "filePathRegRepl: getDataObjInfo for %s", phyPathRegInp->objPath);
00250 return (status);
00251 }
00252 status = sortObjInfoForOpen (rsComm, &dataObjInfoHead, NULL, 0);
00253 if (status < 0 || NULL == dataObjInfoHead ) return status;
00254
00255 destDataObjInfo = *dataObjInfoHead;
00256 rstrcpy (destDataObjInfo.filePath, filePath, MAX_NAME_LEN);
00257 destDataObjInfo.rescInfo = rescInfo;
00258 rstrcpy (destDataObjInfo.rescName, rescInfo->rescName, NAME_LEN);
00259 if ((rescGroupName = getValByKey (&phyPathRegInp->condInput,
00260 RESC_GROUP_NAME_KW)) != NULL) {
00261 rstrcpy (destDataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
00262 }
00263 memset (®ReplicaInp, 0, sizeof (regReplicaInp));
00264 regReplicaInp.srcDataObjInfo = dataObjInfoHead;
00265 regReplicaInp.destDataObjInfo = &destDataObjInfo;
00266 if (getValByKey (&phyPathRegInp->condInput, SU_CLIENT_USER_KW) != NULL) {
00267 addKeyVal (®ReplicaInp.condInput, SU_CLIENT_USER_KW, "");
00268 addKeyVal (®ReplicaInp.condInput, IRODS_ADMIN_KW, "");
00269 } else if (getValByKey (&phyPathRegInp->condInput,
00270 IRODS_ADMIN_KW) != NULL) {
00271 addKeyVal (®ReplicaInp.condInput, IRODS_ADMIN_KW, "");
00272 }
00273 status = rsRegReplica (rsComm, ®ReplicaInp);
00274 clearKeyVal (®ReplicaInp.condInput);
00275 freeAllDataObjInfo (dataObjInfoHead);
00276
00277 return status;
00278 }
00279
00280 int
00281 filePathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
00282 rescInfo_t *rescInfo)
00283 {
00284 dataObjInfo_t dataObjInfo;
00285 int status;
00286 char *rescGroupName = NULL;
00287 char *chksum;
00288
00289 initDataObjInfoWithInp (&dataObjInfo, phyPathRegInp);
00290 if ((rescGroupName = getValByKey (&phyPathRegInp->condInput,
00291 RESC_GROUP_NAME_KW)) != NULL) {
00292 rstrcpy (dataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
00293 }
00294 dataObjInfo.replStatus = NEWLY_CREATED_COPY;
00295 dataObjInfo.rescInfo = rescInfo;
00296 rstrcpy (dataObjInfo.rescName, rescInfo->rescName, NAME_LEN);
00297
00298 if (dataObjInfo.dataSize <= 0 &&
00299 (dataObjInfo.dataSize = getSizeInVault (rsComm, &dataObjInfo)) < 0 &&
00300 dataObjInfo.dataSize != UNKNOWN_FILE_SZ) {
00301 status = (int) dataObjInfo.dataSize;
00302 rodsLog (LOG_ERROR,
00303 "filePathReg: getSizeInVault for %s failed, status = %d",
00304 dataObjInfo.objPath, status);
00305 return (status);
00306 }
00307
00308 if ((chksum = getValByKey (&phyPathRegInp->condInput,
00309 REG_CHKSUM_KW)) != NULL) {
00310 rstrcpy (dataObjInfo.chksum, chksum, NAME_LEN);
00311 }
00312 else if ((chksum = getValByKey (&phyPathRegInp->condInput,
00313 VERIFY_CHKSUM_KW)) != NULL) {
00314 status = _dataObjChksum (rsComm, &dataObjInfo, &chksum);
00315 if (status < 0) {
00316 rodsLog (LOG_ERROR,
00317 "rodsPathReg: _dataObjChksum for %s failed, status = %d",
00318 dataObjInfo.objPath, status);
00319 return (status);
00320 }
00321 rstrcpy (dataObjInfo.chksum, chksum, NAME_LEN);
00322 }
00323
00324 status = svrRegDataObj (rsComm, &dataObjInfo);
00325 if (status < 0) {
00326 rodsLog (LOG_ERROR,
00327 "filePathReg: rsRegDataObj for %s failed, status = %d",
00328 dataObjInfo.objPath, status);
00329 } else {
00330 ruleExecInfo_t rei;
00331 initReiWithDataObjInp (&rei, rsComm, phyPathRegInp);
00332 rei.doi = &dataObjInfo;
00333 rei.status = status;
00334 rei.status = applyRule ("acPostProcForFilePathReg", NULL, &rei,
00335 NO_SAVE_REI);
00336 }
00337
00338 return (status);
00339 }
00340
00341 int
00342 dirPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
00343 rescInfo_t *rescInfo)
00344 {
00345 collInp_t collCreateInp;
00346 fileOpendirInp_t fileOpendirInp;
00347 fileClosedirInp_t fileClosedirInp;
00348 int rescTypeInx;
00349 int status;
00350 int dirFd;
00351 dataObjInp_t subPhyPathRegInp;
00352 fileReaddirInp_t fileReaddirInp;
00353 rodsDirent_t *rodsDirent = NULL;
00354 rodsObjStat_t *rodsObjStatOut = NULL;
00355 int forceFlag;
00356
00357 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00358 if (status < 0 || NULL == rodsObjStatOut ) {
00359 memset (&collCreateInp, 0, sizeof (collCreateInp));
00360 rstrcpy (collCreateInp.collName, phyPathRegInp->objPath,
00361 MAX_NAME_LEN);
00362
00363
00364 addKeyVal (&collCreateInp.condInput, TRANSLATED_PATH_KW, "");
00365
00366
00367 status = rsCollCreate (rsComm, &collCreateInp);
00368 clearKeyVal (&collCreateInp.condInput);
00369 if (status < 0 ) return status;
00370 } else if (rodsObjStatOut->specColl != NULL) {
00371 freeRodsObjStat (rodsObjStatOut);
00372 rodsLog (LOG_ERROR,
00373 "mountFileDir: %s already mounted", phyPathRegInp->objPath);
00374 return (SYS_MOUNT_MOUNTED_COLL_ERR);
00375 }
00376 freeRodsObjStat (rodsObjStatOut);
00377
00378 memset (&fileOpendirInp, 0, sizeof (fileOpendirInp));
00379
00380 rescTypeInx = rescInfo->rescTypeInx;
00381 rstrcpy (fileOpendirInp.dirName, filePath, MAX_NAME_LEN);
00382 fileOpendirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
00383 rstrcpy (fileOpendirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00384
00385 dirFd = rsFileOpendir (rsComm, &fileOpendirInp);
00386 if (dirFd < 0) {
00387 rodsLog (LOG_ERROR,
00388 "dirPathReg: rsFileOpendir for %s error, status = %d",
00389 filePath, dirFd);
00390 return (dirFd);
00391 }
00392
00393 fileReaddirInp.fileInx = dirFd;
00394
00395 if (getValByKey (&phyPathRegInp->condInput, FORCE_FLAG_KW) != NULL) {
00396 forceFlag = 1;
00397 } else {
00398 forceFlag = 0;
00399 }
00400
00401 while ((status = rsFileReaddir (rsComm, &fileReaddirInp, &rodsDirent))
00402 >= 0) {
00403 fileStatInp_t fileStatInp;
00404 rodsStat_t *myStat = NULL;
00405
00406 if (strcmp (rodsDirent->d_name, ".") == 0 ||
00407 strcmp (rodsDirent->d_name, "..") == 0) {
00408 free (rodsDirent);
00409 continue;
00410 }
00411
00412 memset (&fileStatInp, 0, sizeof (fileStatInp));
00413
00414 snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s/%s",
00415 filePath, rodsDirent->d_name);
00416
00417 fileStatInp.fileType = fileOpendirInp.fileType;
00418 fileStatInp.addr = fileOpendirInp.addr;
00419 status = rsFileStat (rsComm, &fileStatInp, &myStat);
00420
00421 if (status != 0) {
00422 rodsLog (LOG_ERROR,
00423 "dirPathReg: rsFileStat failed for %s, status = %d",
00424 fileStatInp.fileName, status);
00425 free (rodsDirent);
00426 return (status);
00427 }
00428
00429 subPhyPathRegInp = *phyPathRegInp;
00430 snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s",
00431 phyPathRegInp->objPath, rodsDirent->d_name);
00432
00433 if ((myStat->st_mode & S_IFREG) != 0) {
00434 if (forceFlag > 0) {
00435
00436 if (isData (rsComm, subPhyPathRegInp.objPath, NULL) >= 0) {
00437 free (myStat);
00438 free (rodsDirent);
00439 continue;
00440 }
00441 }
00442 subPhyPathRegInp.dataSize = myStat->st_size;
00443 if (getValByKey (&phyPathRegInp->condInput, REG_REPL_KW) != NULL) {
00444 status = filePathRegRepl (rsComm, &subPhyPathRegInp,
00445 fileStatInp.fileName, rescInfo);
00446 } else {
00447 addKeyVal (&subPhyPathRegInp.condInput, FILE_PATH_KW,
00448 fileStatInp.fileName);
00449 status = filePathReg (rsComm, &subPhyPathRegInp,
00450 fileStatInp.fileName, rescInfo);
00451 }
00452 } else if ((myStat->st_mode & S_IFDIR) != 0) {
00453 status = dirPathReg (rsComm, &subPhyPathRegInp,
00454 fileStatInp.fileName, rescInfo);
00455 }
00456 free (myStat);
00457 free (rodsDirent);
00458 }
00459 if (status == -1) {
00460 status = 0;
00461 }
00462
00463 fileClosedirInp.fileInx = dirFd;
00464 rsFileClosedir (rsComm, &fileClosedirInp);
00465
00466 return (status);
00467 }
00468
00469 int
00470 mountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
00471 rescInfo_t *rescInfo)
00472 {
00473 collInp_t collCreateInp;
00474 int rescTypeInx;
00475 int status;
00476 fileStatInp_t fileStatInp;
00477 rodsStat_t *myStat = NULL;
00478 rodsObjStat_t *rodsObjStatOut = NULL;
00479
00480 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH)
00481 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00482
00483
00484 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00485 if (status < 0 || NULL == rodsObjStatOut ) return status;
00486
00487 if (rodsObjStatOut->specColl != NULL) {
00488 freeRodsObjStat (rodsObjStatOut);
00489 rodsLog (LOG_ERROR,
00490 "mountFileDir: %s already mounted", phyPathRegInp->objPath);
00491 return (SYS_MOUNT_MOUNTED_COLL_ERR);
00492 }
00493 freeRodsObjStat (rodsObjStatOut);
00494
00495 if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) {
00496 rodsLog (LOG_ERROR,
00497 "mountFileDir: collection %s not empty", phyPathRegInp->objPath);
00498 return (SYS_COLLECTION_NOT_EMPTY);
00499 }
00500
00501 memset (&fileStatInp, 0, sizeof (fileStatInp));
00502
00503 rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN);
00504
00505 rescTypeInx = rescInfo->rescTypeInx;
00506 fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
00507 rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00508 status = rsFileStat (rsComm, &fileStatInp, &myStat);
00509
00510 if (status < 0) {
00511 fileMkdirInp_t fileMkdirInp;
00512
00513 rodsLog (LOG_NOTICE,
00514 "mountFileDir: rsFileStat failed for %s, status = %d, create it",
00515 fileStatInp.fileName, status);
00516 memset (&fileMkdirInp, 0, sizeof (fileMkdirInp));
00517 rstrcpy (fileMkdirInp.dirName, filePath, MAX_NAME_LEN);
00518 fileMkdirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
00519 fileMkdirInp.mode = getDefDirMode ();
00520 rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00521 status = rsFileMkdir (rsComm, &fileMkdirInp);
00522 if (status < 0) {
00523 return (status);
00524 }
00525 } else if ((myStat->st_mode & S_IFDIR) == 0) {
00526 rodsLog (LOG_ERROR,
00527 "mountFileDir: phyPath %s is not a directory",
00528 fileStatInp.fileName);
00529 free (myStat);
00530 return (USER_FILE_DOES_NOT_EXIST);
00531 }
00532
00533 free (myStat);
00534
00535
00536 memset (&collCreateInp, 0, sizeof (collCreateInp));
00537 rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
00538 addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, MOUNT_POINT_STR);
00539
00540 addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, filePath);
00541 addKeyVal (&collCreateInp.condInput, COLLECTION_INFO2_KW,
00542 rescInfo->rescName);
00543
00544
00545 status = rsModColl (rsComm, &collCreateInp);
00546
00547 if (status < 0) {
00548 status = rsRegColl (rsComm, &collCreateInp);
00549 }
00550
00551 if (status >= 0) {
00552 char outLogPath[MAX_NAME_LEN];
00553 int status1;
00554
00555 if (getLogPathFromPhyPath (filePath, rescInfo, outLogPath) >= 0 &&
00556 strcmp (outLogPath, phyPathRegInp->objPath) != 0) {
00557
00558 if (isColl (rsComm, outLogPath, NULL) >= 0) {
00559 modAccessControlInp_t modAccessControl;
00560
00561
00562
00563 bzero (&modAccessControl, sizeof (modAccessControl));
00564 modAccessControl.accessLevel = "read";
00565 modAccessControl.userName = rsComm->clientUser.userName;
00566 modAccessControl.zone = rsComm->clientUser.rodsZone;
00567 modAccessControl.path = phyPathRegInp->objPath;
00568 status1 = rsModAccessControl(rsComm, &modAccessControl);
00569 if (status1 < 0) {
00570 rodsLog (LOG_NOTICE,
00571 "mountFileDir: rsModAccessControl err for %s, stat = %d",
00572 phyPathRegInp->objPath, status1);
00573 }
00574 }
00575 }
00576 }
00577 return (status);
00578 }
00579
00580 int
00581 unmountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00582 {
00583 int status;
00584 collInp_t modCollInp;
00585 rodsObjStat_t *rodsObjStatOut = NULL;
00586
00587 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00588 if (status < 0 || NULL == rodsObjStatOut ) {
00589 return status;
00590 } else if (rodsObjStatOut->specColl == NULL) {
00591 freeRodsObjStat (rodsObjStatOut);
00592 rodsLog (LOG_ERROR,
00593 "unmountFileDir: %s not mounted", phyPathRegInp->objPath);
00594 return (SYS_COLL_NOT_MOUNTED_ERR);
00595 }
00596
00597 if (getStructFileType (rodsObjStatOut->specColl) >= 0) {
00598
00599 status = _rsSyncMountedColl (rsComm, rodsObjStatOut->specColl,
00600 PURGE_STRUCT_FILE_CACHE);
00601 #if 0
00602 if (status < 0) {
00603 freeRodsObjStat (rodsObjStatOut);
00604 return (status);
00605 }
00606 #endif
00607 }
00608
00609 freeRodsObjStat (rodsObjStatOut);
00610
00611 memset (&modCollInp, 0, sizeof (modCollInp));
00612 rstrcpy (modCollInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
00613 addKeyVal (&modCollInp.condInput, COLLECTION_TYPE_KW,
00614 "NULL_SPECIAL_VALUE");
00615 addKeyVal (&modCollInp.condInput, COLLECTION_INFO1_KW, "NULL_SPECIAL_VALUE");
00616 addKeyVal (&modCollInp.condInput, COLLECTION_INFO2_KW, "NULL_SPECIAL_VALUE");
00617
00618 status = rsModColl (rsComm, &modCollInp);
00619
00620 return (status);
00621 }
00622
00623 int
00624 structFileReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00625 {
00626 collInp_t collCreateInp;
00627 int status;
00628 dataObjInfo_t *dataObjInfo = NULL;
00629 char *structFilePath = NULL;
00630 dataObjInp_t dataObjInp;
00631 char *collType;
00632 int len;
00633 rodsObjStat_t *rodsObjStatOut = NULL;
00634 specCollCache_t *specCollCache = NULL;
00635 rescInfo_t *rescInfo = NULL;
00636
00637
00638 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH)
00639 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00640
00641 if ((structFilePath = getValByKey (&phyPathRegInp->condInput, FILE_PATH_KW))
00642 == NULL) {
00643 rodsLog (LOG_ERROR,
00644 "structFileReg: No structFilePath input for %s",
00645 phyPathRegInp->objPath);
00646 return (SYS_INVALID_FILE_PATH);
00647 }
00648
00649 collType = getValByKey (&phyPathRegInp->condInput, COLLECTION_TYPE_KW);
00650 if (collType == NULL) {
00651 rodsLog (LOG_ERROR,
00652 "structFileReg: Bad COLLECTION_TYPE_KW for structFilePath %s",
00653 dataObjInp.objPath);
00654 return (SYS_INTERNAL_NULL_INPUT_ERR);
00655 }
00656
00657 len = strlen (phyPathRegInp->objPath);
00658 if (strncmp (structFilePath, phyPathRegInp->objPath, len) == 0 &&
00659 (structFilePath[len] == '\0' || structFilePath[len] == '/')) {
00660 rodsLog (LOG_ERROR,
00661 "structFileReg: structFilePath %s inside collection %s",
00662 structFilePath, phyPathRegInp->objPath);
00663 return (SYS_STRUCT_FILE_INMOUNTED_COLL);
00664 }
00665
00666
00667
00668 if (getSpecCollCache (rsComm, structFilePath, 0, &specCollCache) >= 0) {
00669 rodsLog (LOG_ERROR,
00670 "structFileReg: structFilePath %s is in a mounted path",
00671 structFilePath);
00672 return (SYS_STRUCT_FILE_INMOUNTED_COLL);
00673 }
00674
00675 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00676 if (status < 0 || NULL == rodsObjStatOut ) return status;
00677
00678 if (rodsObjStatOut->specColl != NULL) {
00679 freeRodsObjStat (rodsObjStatOut);
00680 rodsLog (LOG_ERROR,
00681 "structFileReg: %s already mounted", phyPathRegInp->objPath);
00682 return (SYS_MOUNT_MOUNTED_COLL_ERR);
00683 }
00684
00685 freeRodsObjStat (rodsObjStatOut);
00686
00687 if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) {
00688 rodsLog (LOG_ERROR,
00689 "structFileReg: collection %s not empty", phyPathRegInp->objPath);
00690 return (SYS_COLLECTION_NOT_EMPTY);
00691 }
00692
00693 memset (&dataObjInp, 0, sizeof (dataObjInp));
00694 rstrcpy (dataObjInp.objPath, structFilePath, sizeof (dataObjInp));
00695
00696 dataObjInp.openFlags = O_WRONLY;
00697 status = getDataObjInfoIncSpecColl (rsComm, &dataObjInp, &dataObjInfo);
00698 if (status < 0 || NULL == dataObjInfo) {
00699 int myStatus;
00700
00701 dataObjInp.condInput = phyPathRegInp->condInput;
00702
00703 rmKeyVal (&dataObjInp.condInput, FILE_PATH_KW);
00704 myStatus = rsDataObjCreate (rsComm, &dataObjInp);
00705 if (myStatus < 0 ) {
00706 rodsLog (LOG_ERROR,
00707 "structFileReg: Problem with open/create structFilePath %s, status = %d",
00708 dataObjInp.objPath, status);
00709 return (status);
00710 } else {
00711 openedDataObjInp_t dataObjCloseInp;
00712 bzero (&dataObjCloseInp, sizeof (dataObjCloseInp));
00713 rescInfo = L1desc[myStatus].dataObjInfo->rescInfo;
00714 dataObjCloseInp.l1descInx = myStatus;
00715 rsDataObjClose (rsComm, &dataObjCloseInp);
00716 }
00717 } else {
00718 rescInfo = dataObjInfo->rescInfo;
00719 }
00720
00721 if (!structFileSupport (rsComm, phyPathRegInp->objPath,
00722 collType, rescInfo)) {
00723 rodsLog (LOG_ERROR,
00724 "structFileReg: structFileDriver type %s does not exist for %s",
00725 collType, dataObjInp.objPath);
00726 return (SYS_NOT_SUPPORTED);
00727 }
00728
00729
00730
00731 memset (&collCreateInp, 0, sizeof (collCreateInp));
00732 rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
00733 addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, collType);
00734
00735
00736 addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW,
00737 dataObjInp.objPath);
00738
00739
00740 status = rsModColl (rsComm, &collCreateInp);
00741
00742 if (status < 0) {
00743 status = rsRegColl (rsComm, &collCreateInp);
00744 }
00745
00746 return (status);
00747 }
00748
00749 int
00750 structFileSupport (rsComm_t *rsComm, char *collection, char *collType,
00751 rescInfo_t *rescInfo)
00752 {
00753 rodsStat_t *myStat = NULL;
00754 int status;
00755 subFile_t subFile;
00756 specColl_t specColl;
00757
00758 if (rsComm == NULL || collection == NULL || collType == NULL ||
00759 rescInfo == NULL) return 0;
00760
00761 memset (&subFile, 0, sizeof (subFile));
00762 memset (&specColl, 0, sizeof (specColl));
00763
00764 subFile.specColl = &specColl;
00765 rstrcpy (specColl.collection, collection, MAX_NAME_LEN);
00766 specColl.collClass = STRUCT_FILE_COLL;
00767 if (strcmp (collType, HAAW_STRUCT_FILE_STR) == 0) {
00768 specColl.type = HAAW_STRUCT_FILE_T;
00769 } else if (strcmp (collType, TAR_STRUCT_FILE_STR) == 0) {
00770 specColl.type = TAR_STRUCT_FILE_T;
00771 } else {
00772 return (0);
00773 }
00774 snprintf (specColl.objPath, MAX_NAME_LEN, "%s/myFakeFile",
00775 collection);
00776 rstrcpy (specColl.resource, rescInfo->rescName, NAME_LEN);
00777 rstrcpy (specColl.phyPath, "/fakeDir1/fakeDir2/myFakeStructFile",
00778 MAX_NAME_LEN);
00779 rstrcpy (subFile.subFilePath, "/fakeDir1/fakeDir2/myFakeFile",
00780 MAX_NAME_LEN);
00781 rstrcpy (subFile.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);
00782
00783 status = rsSubStructFileStat (rsComm, &subFile, &myStat);
00784
00785 if (status == SYS_NOT_SUPPORTED)
00786 return (0);
00787 else
00788 return (1);
00789 }
00790
00791 int
00792 linkCollReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
00793 {
00794 collInp_t collCreateInp;
00795 int status;
00796 char *linkPath = NULL;
00797 char *collType;
00798 int len;
00799 rodsObjStat_t *rodsObjStatOut = NULL;
00800 specCollCache_t *specCollCache = NULL;
00801
00802 if ((linkPath = getValByKey (&phyPathRegInp->condInput, FILE_PATH_KW))
00803 == NULL) {
00804 rodsLog (LOG_ERROR,
00805 "linkCollReg: No linkPath input for %s",
00806 phyPathRegInp->objPath);
00807 return (SYS_INVALID_FILE_PATH);
00808 }
00809
00810 collType = getValByKey (&phyPathRegInp->condInput, COLLECTION_TYPE_KW);
00811 if (collType == NULL || strcmp (collType, LINK_POINT_STR) != 0) {
00812 rodsLog (LOG_ERROR,
00813 "linkCollReg: Bad COLLECTION_TYPE_KW for linkPath %s",
00814 phyPathRegInp->objPath);
00815 return (SYS_INTERNAL_NULL_INPUT_ERR);
00816 }
00817
00818 if (phyPathRegInp->objPath[0] != '/' || linkPath[0] != '/') {
00819 rodsLog (LOG_ERROR,
00820 "linkCollReg: linkPath %s or collection %s not absolute path",
00821 linkPath, phyPathRegInp->objPath);
00822 return (SYS_COLL_LINK_PATH_ERR);
00823 }
00824
00825 len = strlen (phyPathRegInp->objPath);
00826 if (strncmp (linkPath, phyPathRegInp->objPath, len) == 0 &&
00827 linkPath[len] == '/') {
00828 rodsLog (LOG_ERROR,
00829 "linkCollReg: linkPath %s inside collection %s",
00830 linkPath, phyPathRegInp->objPath);
00831 return (SYS_COLL_LINK_PATH_ERR);
00832 }
00833
00834 len = strlen (linkPath);
00835 if (strncmp (phyPathRegInp->objPath, linkPath, len) == 0 &&
00836 phyPathRegInp->objPath[len] == '/') {
00837 rodsLog (LOG_ERROR,
00838 "linkCollReg: collection %s inside linkPath %s",
00839 linkPath, phyPathRegInp->objPath);
00840 return (SYS_COLL_LINK_PATH_ERR);
00841 }
00842
00843 if (getSpecCollCache (rsComm, linkPath, 0, &specCollCache) >= 0 &&
00844 specCollCache->specColl.collClass != LINKED_COLL) {
00845 rodsLog (LOG_ERROR,
00846 "linkCollReg: linkPath %s is in a spec coll path",
00847 linkPath);
00848 return (SYS_COLL_LINK_PATH_ERR);
00849 }
00850
00851 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00852 if (status < 0) {
00853
00854 collInp_t collCreateInp;
00855 memset (&collCreateInp, 0, sizeof (collCreateInp));
00856 rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
00857 status = rsRegColl (rsComm, &collCreateInp);
00858 if (status < 0) {
00859 rodsLog (LOG_ERROR,
00860 "linkCollReg: rsRegColl error for %s, status = %d",
00861 collCreateInp.collName, status);
00862 return status;
00863 }
00864 status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
00865 if (status < 0 ) return status;
00866
00867 }
00868
00869 if ( rodsObjStatOut &&
00870 rodsObjStatOut->specColl != NULL &&
00871 rodsObjStatOut->specColl->collClass != LINKED_COLL) {
00872 freeRodsObjStat (rodsObjStatOut);
00873 rodsLog (LOG_ERROR,
00874 "linkCollReg: link collection %s in a spec coll path",
00875 phyPathRegInp->objPath);
00876 return (SYS_COLL_LINK_PATH_ERR);
00877 }
00878
00879 freeRodsObjStat (rodsObjStatOut);
00880
00881 if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) {
00882 rodsLog (LOG_ERROR,
00883 "linkCollReg: collection %s not empty", phyPathRegInp->objPath);
00884 return (SYS_COLLECTION_NOT_EMPTY);
00885 }
00886
00887
00888
00889 memset (&collCreateInp, 0, sizeof (collCreateInp));
00890 rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
00891 addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, collType);
00892
00893
00894 addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW,
00895 linkPath);
00896
00897
00898 status = rsModColl (rsComm, &collCreateInp);
00899
00900 if (status < 0) {
00901 status = rsRegColl (rsComm, &collCreateInp);
00902 }
00903
00904 return (status);
00905 }
00906