00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "fileOpen.h"
00011 #include "fileOpr.h"
00012 #include "miscServerFunct.h"
00013 #include "rsGlobalExtern.h"
00014
00015
00016
00017 #include "eirods_log.h"
00018 #include "eirods_file_object.h"
00019 #include "eirods_stacktrace.h"
00020 #include "eirods_resource_backport.h"
00021
00022 int
00023 rsFileOpen (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp)
00024 {
00025 rodsServerHost_t *rodsServerHost;
00026 int remoteFlag;
00027 int fileInx;
00028
00029
00030 eirods::error ret = eirods::get_host_for_hier_string( fileOpenInp->resc_hier_, remoteFlag, rodsServerHost );
00031 if( !ret.ok() ) {
00032 eirods::log( PASSMSG( "failed in call to eirods::get_host_for_hier_string", ret ) );
00033 return -1;
00034 }
00035
00036
00037 if (remoteFlag < 0) {
00038 return (remoteFlag);
00039 } else {
00040 fileInx = rsFileOpenByHost (rsComm, fileOpenInp, rodsServerHost);
00041 return (fileInx);
00042 }
00043 }
00044
00045 int
00046 rsFileOpenByHost (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp,
00047 rodsServerHost_t *rodsServerHost)
00048 {
00049 int fileInx;
00050 int fd;
00051 int remoteFlag;
00052
00053 if (rodsServerHost == NULL) {
00054 rodsLog (LOG_NOTICE,
00055 "rsFileOpenByHost: Input NULL rodsServerHost");
00056 return (SYS_INTERNAL_NULL_INPUT_ERR);
00057 }
00058
00059 remoteFlag = rodsServerHost->localFlag;
00060
00061 if (remoteFlag == LOCAL_HOST) {
00062 fd = _rsFileOpen (rsComm, fileOpenInp);
00063 } else if (remoteFlag == REMOTE_HOST) {
00064 fd = remoteFileOpen (rsComm, fileOpenInp, rodsServerHost);
00065 } else {
00066 if (remoteFlag < 0) {
00067 return (remoteFlag);
00068 } else {
00069 rodsLog (LOG_NOTICE,
00070 "rsFileOpenByHost: resolveHost returned unrecognized value %d",
00071 remoteFlag);
00072 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00073 }
00074 }
00075
00076 if (fd < 0) {
00077 return (fd);
00078 }
00079 fileInx = allocAndFillFileDesc (rodsServerHost, fileOpenInp->objPath, fileOpenInp->fileName, fileOpenInp->resc_hier_,
00080 fileOpenInp->fileType, fd, fileOpenInp->mode);
00081
00082 return (fileInx);
00083 }
00084
00085 int
00086 remoteFileOpen (rsComm_t *rsComm, fileOpenInp_t *fileOpenInp,
00087 rodsServerHost_t *rodsServerHost)
00088 {
00089 int fileInx;
00090 int status;
00091
00092 if (rodsServerHost == NULL) {
00093 rodsLog (LOG_NOTICE,
00094 "remoteFileOpen: Invalid rodsServerHost");
00095 return SYS_INVALID_SERVER_HOST;
00096 }
00097
00098 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00099 return status;
00100 }
00101
00102 fileInx = rcFileOpen (rodsServerHost->conn, fileOpenInp);
00103
00104 if (fileInx < 0) {
00105 rodsLog (LOG_NOTICE,
00106 "remoteFileOpen: rcFileOpen failed for %s",
00107 fileOpenInp->fileName);
00108 }
00109
00110 return fileInx;
00111 }
00112
00113
00114
00115 int _rsFileOpen(
00116 rsComm_t* _comm,
00117 fileOpenInp_t* _open_inp ) {
00118
00119
00120 if( !_comm || !_open_inp ) {
00121 rodsLog( LOG_ERROR, "_rsFileOpen - null comm or open_inp pointer(s)." );
00122 return -1;
00123 }
00124
00125
00126
00127
00128 if( ( _open_inp->flags & O_WRONLY ) && ( _open_inp->flags & O_RDWR ) ) {
00129
00130 _open_inp->flags &= ~(O_WRONLY);
00131 }
00132
00133 if(_open_inp->objPath[0] == '\0') {
00134 std::stringstream msg;
00135 msg << __FUNCTION__;
00136 msg << " - Empty logical path.";
00137 eirods::log(LOG_ERROR, msg.str());
00138 return -1;
00139 }
00140
00141
00142
00143 eirods::file_object_ptr file_obj(
00144 new eirods::file_object(
00145 _comm,
00146 _open_inp->objPath,
00147 _open_inp->fileName,
00148 _open_inp->resc_hier_,
00149 0,
00150 _open_inp->mode,
00151 _open_inp->flags ) );
00152 file_obj->in_pdmo(_open_inp->in_pdmo);
00153
00154 eirods::error ret_err = fileOpen( _comm, file_obj );
00155
00156
00157
00158
00159
00160 if( ret_err.code() == EIRODS_DIRECT_ARCHIVE_ACCESS ) {
00161 return EIRODS_DIRECT_ARCHIVE_ACCESS;
00162
00163 } else if ( !ret_err.ok() ) {
00164 std::stringstream msg;
00165 msg << "_rsFileOpen: fileOpen for [";
00166 msg << _open_inp->fileName;
00167 msg << "]";
00168 eirods::error out_err = PASSMSG( msg.str(), ret_err );
00169 eirods::log( out_err );
00170 }
00171
00172 return file_obj->file_descriptor();
00173
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184