00001
00002
00003
00004
00005
00006 #include "getHostForPut.h"
00007 #include "rodsLog.h"
00008 #include "rsGlobalExtern.h"
00009 #include "rcGlobalExtern.h"
00010 #include "getRemoteZoneResc.h"
00011 #include "dataObjCreate.h"
00012 #include "objMetaOpr.h"
00013 #include "resource.h"
00014 #include "collection.h"
00015 #include "specColl.h"
00016 #include "miscServerFunct.h"
00017
00018 int
00019 rsGetHostForPut (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
00020 char **outHost)
00021 {
00022 int status;
00023 rescGrpInfo_t *myRescGrpInfo;
00024 rescInfo_t *myRescInfo;
00025 rodsServerHost_t *rodsServerHost;
00026 rodsHostAddr_t addr;
00027 specCollCache_t *specCollCache = NULL;
00028 char *myHost;
00029 int remoteFlag = 0;
00030
00031 *outHost = NULL;
00032 #if 0 // JMC -backport 4746
00033 if (isLocalZone (dataObjInp->objPath) == 0) {
00034
00035 *outHost = strdup (THIS_ADDRESS);
00036 return 0;
00037 }
00038 #endif
00039 if (getValByKey (&dataObjInp->condInput, ALL_KW) != NULL ||
00040 getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) {
00041
00042
00043 *outHost = strdup (THIS_ADDRESS);
00044 return 0;
00045 }
00046
00047 resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache, NULL);
00048 if (isLocalZone (dataObjInp->objPath) == 0) {
00049 #if 0 // JMC -backport 4746
00050
00051 *outHost = strdup (THIS_ADDRESS);
00052 return 0;
00053 #else // JMC -backport 4746
00054 resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
00055 &dataObjInp->condInput);
00056 remoteFlag = getAndConnRcatHost (rsComm, SLAVE_RCAT,
00057 dataObjInp->objPath, &rodsServerHost);
00058 if (remoteFlag < 0) {
00059 return (remoteFlag);
00060 } else if (remoteFlag == LOCAL_HOST) {
00061 *outHost = strdup (THIS_ADDRESS);
00062 return 0;
00063 } else {
00064 status = rcGetHostForPut (rodsServerHost->conn, dataObjInp,
00065 outHost);
00066 if (status >= 0 && *outHost != NULL &&
00067 strcmp (*outHost, THIS_ADDRESS) == 0) {
00068 free (*outHost);
00069 *outHost = strdup (rodsServerHost->hostName->name);
00070 }
00071 return (status);
00072 }
00073 #endif // JMC -backport 4746
00074 }
00075
00076 status = getSpecCollCache (rsComm, dataObjInp->objPath, 0, &specCollCache);
00077 if (status >= 0 && NULL != specCollCache) {
00078 if (specCollCache->specColl.collClass == MOUNTED_COLL) {
00079 status = resolveResc (specCollCache->specColl.resource,
00080 &myRescInfo);
00081 if (status < 0) {
00082 rodsLog (LOG_ERROR,
00083 "rsGetHostForPut: resolveResc error for %s, status = %d",
00084 specCollCache->specColl.resource, status);
00085 return status;
00086 }
00087
00088 } else {
00089 *outHost = strdup (THIS_ADDRESS);
00090 return 0;
00091 }
00092 } else {
00093
00094 status = getRescGrpForCreate (rsComm, dataObjInp, &myRescGrpInfo);
00095 if (status < 0) return status;
00096
00097 myRescInfo = myRescGrpInfo->rescInfo;
00098 freeAllRescGrpInfo (myRescGrpInfo);
00099
00100 if ((status == 1 && getRescCnt (myRescGrpInfo) > 1) ||
00101 getRescClass (myRescInfo) == COMPOUND_CL) {
00102 *outHost = strdup (THIS_ADDRESS);
00103 return 0;
00104 }
00105 }
00106
00107 bzero (&addr, sizeof (addr));
00108 rstrcpy (addr.hostAddr, myRescInfo->rescLoc, NAME_LEN);
00109 status = resolveHost (&addr, &rodsServerHost);
00110 if (status < 0) return status;
00111 if (rodsServerHost->localFlag == LOCAL_HOST) {
00112 *outHost = strdup (THIS_ADDRESS);
00113 return 0;
00114 }
00115
00116 myHost = getSvrAddr (rodsServerHost);
00117 if (myHost != NULL) {
00118 *outHost = strdup (myHost);
00119 return 0;
00120 } else {
00121 *outHost = NULL;
00122 return SYS_INVALID_SERVER_HOST;
00123 }
00124 }
00125