irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsDataObjPhymv.cpp
Go to the documentation of this file.
1 
4 #include "dataObjPhymv.h"
5 #include "dataObjRepl.h"
6 #include "dataObjOpr.hpp"
7 #include "rodsLog.h"
8 #include "objMetaOpr.hpp"
9 #include "specColl.hpp"
10 #include "icatDefines.h"
11 #include "dataObjCreate.h"
12 #include "getRemoteZoneResc.h"
13 #include "physPath.hpp"
14 #include "fileClose.h"
15 #include "rsDataObjPhymv.hpp"
16 #include "rsFileOpen.hpp"
17 #include "rsFileClose.hpp"
18 #include "rsDataObjRepl.hpp"
19 #include "rsDataObjPhymv.hpp"
20 
21 // =-=-=-=-=-=-=-
25 
26 
28  rsComm_t* _comm,
29  std::string _resc_hier,
30  dataObjInfo_t* _data_obj_info ) {
31 
32  while(_data_obj_info != NULL && _data_obj_info->rescHier != _resc_hier) {
33  _data_obj_info = _data_obj_info->next;
34  }
35  if( !_comm || !_data_obj_info ) {
36  return ERROR(
38  "null _data_obj_info or _comm" );
39  }
40 
41  std::string location;
43  _data_obj_info->rescHier,
44  location );
45  if ( !ret.ok() ) {
46  return PASS( ret );
47  }
48 
49  // test the source hier to determine if we have write access to the data
50  // stored. if not then we cannot unlink that replica and should throw an
51  // error.
52  fileOpenInp_t open_inp;
53  memset(
54  &open_inp, 0,
55  sizeof( open_inp ) );
56  open_inp.mode = getDefFileMode();
57  open_inp.flags = O_WRONLY;
58  rstrcpy(
59  open_inp.resc_name_,
60  _data_obj_info->rescName,
61  MAX_NAME_LEN );
62  rstrcpy(
63  open_inp.resc_hier_,
64  _data_obj_info->rescHier,
65  MAX_NAME_LEN );
66  rstrcpy(
67  open_inp.objPath,
68  _data_obj_info->objPath,
69  MAX_NAME_LEN );
70  rstrcpy(
71  open_inp.addr.hostAddr,
72  location.c_str(),
73  NAME_LEN );
74  rstrcpy(
75  open_inp.fileName,
76  _data_obj_info->filePath,
77  MAX_NAME_LEN );
78  rstrcpy(
79  open_inp.in_pdmo,
80  _data_obj_info->in_pdmo,
81  MAX_NAME_LEN );
82 
83  // kv passthru
84  copyKeyVal(
85  &_data_obj_info->condInput,
86  &open_inp.condInput );
87 
88  int l3_idx = rsFileOpen( _comm, &open_inp );
89  clearKeyVal( &open_inp.condInput );
90  if( l3_idx < 0 ) {
91  std::string msg = "unable to open ";
92  msg += _data_obj_info->objPath;
93  msg += " for unlink";
95  &_comm->rError,
97  msg.c_str() );
98  return ERROR(
100  msg );
101  }
102 
103 
104  fileCloseInp_t close_inp;
105  memset( &close_inp, 0, sizeof( close_inp ) );
106  close_inp.fileInx = l3_idx;
107  int status = rsFileClose( _comm, &close_inp );
108  if( status < 0 ) {
109  std::string msg = "failed to close ";
110  msg += _data_obj_info->objPath;
111  return ERROR(
112  status,
113  msg );
114  }
115 
116  return SUCCESS();
117 
118 } // test_source_replica_for_write_permissions
119 
120 
121 /* rsDataObjPhymv - The Api handler of the rcDataObjPhymv call - phymove
122  * a data object from one resource to another.
123  * Input -
124  * rsComm_t *rsComm
125  * dataObjInp_t *dataObjInp - The replication input
126  * transferStat_t **transStat - transfer stat output
127  */
128 
129 int
130 rsDataObjPhymv( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
131  transferStat_t **transStat ) {
132  int status = 0;
133  dataObjInfo_t *dataObjInfoHead = NULL;
134  dataObjInfo_t *oldDataObjInfoHead = NULL;
135  ruleExecInfo_t rei;
136  int multiCopyFlag = 0;
137  char *accessPerm = NULL;
138  int remoteFlag = 0;
140  specCollCache_t *specCollCache = NULL;
141 
142  resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache,
143  &dataObjInp->condInput );
144  remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp, &rodsServerHost,
145  REMOTE_OPEN );
146 
147  if ( remoteFlag < 0 ) {
148  return remoteFlag;
149  }
150  else if ( remoteFlag == REMOTE_HOST ) {
151  status = _rcDataObjPhymv( rodsServerHost->conn, dataObjInp,
152  transStat );
153  return status;
154  }
155 
156  char* dest_resc = getValByKey( &dataObjInp->condInput, DEST_RESC_NAME_KW );
157  if ( dest_resc ) {
158  std::string dest_hier;
160  rsComm,
161  dest_resc,
162  dest_hier );
163  if( !ret.ok() ) {
164  irods::log( PASS( ret ) );
165  return ret.code();
166  }
167  addKeyVal(
168  &dataObjInp->condInput,
170  dest_hier.c_str() );
171  }
172 
173  // =-=-=-=-=-=-=-
174  // determine hierarchy string
175  char* dest_hier_kw = getValByKey( &dataObjInp->condInput, DEST_RESC_HIER_STR_KW );
176  std::string dest_hier;
177  if ( NULL == dest_hier_kw || 0 == strlen(dest_hier_kw) ) {
180  rsComm,
181  dataObjInp,
182  dest_hier );
183  if ( !ret.ok() ) {
184  std::stringstream msg;
185  msg << __FUNCTION__;
186  msg << " :: failed in irods::resolve_resource_hierarchy for [";
187  msg << dataObjInp->objPath << "]";
188  irods::log( PASSMSG( msg.str(), ret ) );
189  return ret.code();
190  }
191 
192  // =-=-=-=-=-=-=-
193  // we resolved the redirect and have a host, set the dest_hier str for subsequent
194  // api calls, etc.
195  addKeyVal(
196  &dataObjInp->condInput,
198  dest_hier.c_str() );
199  } // if keyword
200  else {
201  dest_hier = dest_hier_kw;
202  }
203 
204  char* src_resc = getValByKey( &dataObjInp->condInput, RESC_NAME_KW );
205  if ( src_resc ) {
206  std::string src_hier;
208  rsComm,
209  src_resc,
210  src_hier );
211  if( !ret.ok() ) {
212  irods::log( PASS( ret ) );
213  return ret.code();
214  }
215  addKeyVal(
216  &dataObjInp->condInput,
218  src_hier.c_str() );
219  }
220 
221  // =-=-=-=-=-=-=-
222  // determine hierarchy string
223  char* resc_hier_kw = getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW );
224  std::string src_hier;
225  if ( NULL == resc_hier_kw || 0 == strlen(resc_hier_kw) ) {
228  rsComm,
229  dataObjInp,
230  src_hier );
231  if ( !ret.ok() ) {
232  std::stringstream msg;
233  msg << __FUNCTION__;
234  msg << " :: failed in irods::resolve_resource_hierarchy for [";
235  msg << dataObjInp->objPath << "]";
236  irods::log( PASSMSG( msg.str(), ret ) );
237  return ret.code();
238  }
239 
240  // =-=-=-=-=-=-=-
241  // we resolved the redirect and have a host, set the src_hier str for subsequent
242  // api calls, etc.
243  addKeyVal(
244  &dataObjInp->condInput,
246  src_hier.c_str() );
247  } // if keyword
248  else {
249  src_hier = resc_hier_kw;
250  }
251 
252  *transStat = ( transferStat_t* )malloc( sizeof( transferStat_t ) );
253  memset( *transStat, 0, sizeof( transferStat_t ) );
254 
255  if( getValByKey( &dataObjInp->condInput, ADMIN_KW ) != NULL ) {
258  }
259  accessPerm = NULL;
260  }
261  else {
262  accessPerm = ACCESS_DELETE_OBJECT;
263  }
264 
265  // get root of the destination hierarchy as the 'resc for create'
266  irods::hierarchy_parser h_parse;
267  h_parse.set_string( dest_hier );
268 
269  std::string dest_root;
270  h_parse.first_resc( dest_root );
271  if( status < 0 ) {
272  return status;
273  }
274 
275 
277  &rei,
278  rsComm,
279  dataObjInp );
280  status = applyRule(
281  "acSetMultiReplPerResc",
282  NULL,
283  &rei,
284  NO_SAVE_REI );
286  free(rei.condInputData);
287  if ( strcmp( rei.statusStr, MULTI_COPIES_PER_RESC ) == 0 ) {
288  multiCopyFlag = 1;
289  }
290  else {
291  multiCopyFlag = 0;
292  }
293 
294  // query rcat for dataObjInfo and sort it
296  rsComm,
297  dataObjInp,
298  &dataObjInfoHead,
299  accessPerm, 1 );
300 
301  if ( status < 0 ) {
302  rodsLog(
303  LOG_NOTICE,
304  "rsDataObjPhymv: getDataObjInfo for %s",
305  dataObjInp->objPath );
306  return status;
307  }
308 
310  rsComm,
311  src_hier,
312  dataObjInfoHead );
313  if( !ret.ok() ) {
314  irods::log( PASS( ret ) );
315  return ret.code();
316  }
317 
319  &dataObjInfoHead,
320  &oldDataObjInfoHead,
321  dest_root.c_str(),
322  &dataObjInp->condInput,
323  multiCopyFlag );
324  if ( status < 0 ) {
325  freeAllDataObjInfo( dataObjInfoHead );
326  freeAllDataObjInfo( oldDataObjInfoHead );
327  if ( status == CAT_NO_ROWS_FOUND ) {
328  return 0;
329  }
330  else {
331  return status;
332  }
333  }
335  rsComm,
336  dataObjInp,
337  dataObjInfoHead,
338  dest_root.c_str(),
339  *transStat,
340  multiCopyFlag );
341 
342  freeAllDataObjInfo( dataObjInfoHead );
343  freeAllDataObjInfo( oldDataObjInfoHead );
344 
345  return status;
346 }
347 
348 int
349 _rsDataObjPhymv( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
350  dataObjInfo_t *srcDataObjInfoHead, const char *_resc_name,
351  transferStat_t *transStat, int multiCopyFlag ) {
352  dataObjInfo_t *srcDataObjInfo;
353  int status = 0;
354  int savedStatus = 0;
355 
356 
357  srcDataObjInfo = srcDataObjInfoHead;
358 
359  while ( srcDataObjInfo ) {
360  /* use _rsDataObjReplS for the phymv */
361  dataObjInp->oprType = PHYMV_OPR; /* should be set already */
362  status = _rsDataObjReplS( rsComm, dataObjInp, srcDataObjInfo,
363  _resc_name, NULL, 0 );
364 
365  if ( multiCopyFlag == 0 ) {
366  if ( status >= 0 ) {
367  srcDataObjInfo = srcDataObjInfo->next;
368  }
369  else {
370  savedStatus = status;
371  }
372  /* use another resc */
373  break;
374  }
375  else {
376  if ( status < 0 ) {
377  savedStatus = status;
378  /* use another resc */
379  break;
380  }
381  }
382  srcDataObjInfo = srcDataObjInfo->next;
383  }
384  if ( status >= 0 ) {
385  transStat->numThreads = dataObjInp->numThreads;
386  }
387 
388 
389  if ( srcDataObjInfo != NULL ) {
390  /* not everything got moved */
391  if ( savedStatus == 0 ) {
393  }
394  }
395  else {
396  savedStatus = 0;
397  }
398 
399  return savedStatus;
400 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
transferStat_t
Definition: objInfo.h:291
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
rsDataObjPhymv
int rsDataObjPhymv(rsComm_t *rsComm, dataObjInp_t *dataObjInp, transferStat_t **transStat)
Definition: rsDataObjPhymv.cpp:130
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
getRemoteZoneResc.h
rsFileOpen.hpp
SYS_USER_NO_PERMISSION
@ SYS_USER_NO_PERMISSION
Definition: rodsErrorTable.h:186
specColl.hpp
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
fileOpenInp_t::resc_name_
char resc_name_[(1024+64)]
Definition: fileOpen.h:15
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
irods::resolve_resource_hierarchy
error resolve_resource_hierarchy(const std::string &, rsComm_t *, dataObjInp_t *, std::string &, dataObjInfo_t **_data_obj_info=0)
Definition: irods_resource_redirect.cpp:505
NO_SAVE_REI
#define NO_SAVE_REI
Definition: rodsDef.h:103
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
REMOTE_OPEN
#define REMOTE_OPEN
Definition: getRemoteZoneResc.h:5
irods::hierarchy_parser
Definition: irods_hierarchy_parser.hpp:14
_rcDataObjPhymv
int _rcDataObjPhymv(rcComm_t *conn, dataObjInp_t *dataObjInp, transferStat_t **transferStat)
Definition: rcDataObjPhymv.cpp:88
resolve_hierarchy_for_resc_from_cond_input
irods::error resolve_hierarchy_for_resc_from_cond_input(rsComm_t *, const std::string &, std::string &)
Definition: dataObjOpr.cpp:1880
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
test_source_replica_for_write_permissions
irods::error test_source_replica_for_write_permissions(rsComm_t *_comm, std::string _resc_hier, dataObjInfo_t *_data_obj_info)
Definition: rsDataObjPhymv.cpp:27
DataObjInfo::condInput
keyValPair_t condInput
Definition: objInfo.h:161
irods_resource_backport.hpp
fileOpenInp_t::resc_hier_
char resc_hier_[(1024+64)]
Definition: fileOpen.h:16
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
DataObjInfo::filePath
char filePath[(1024+64)]
Definition: objInfo.h:137
dataObjCreate.h
rsDataObjPhymv.hpp
irods_resource_redirect.hpp
fileOpenInp_t::fileName
char fileName[(1024+64)]
Definition: fileOpen.h:20
DataObjInfo::next
struct DataObjInfo * next
Definition: objInfo.h:163
_rsDataObjReplS
int _rsDataObjReplS(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t *srcDataObjInfo, const char *rescName, dataObjInfo_t *destDataObjInfo, int updateFlag)
Definition: rsDataObjRepl.cpp:652
rsFileOpen
int rsFileOpen(rsComm_t *rsComm, fileOpenInp_t *fileOpenInp)
Definition: rsFileOpen.cpp:21
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
rsFileClose.hpp
fileClose.h
getDefFileMode
int getDefFileMode()
Definition: physPath.cpp:1057
initReiWithDataObjInp
int initReiWithDataObjInp(ruleExecInfo_t *rei, rsComm_t *rsComm, dataObjInp_t *dataObjIn)
Definition: irods_re_structs.cpp:164
FileCloseInp
Definition: fileClose.h:6
PHYMV_OPR
#define PHYMV_OPR
Definition: dataObjInpOut.h:181
DEST_RESC_NAME_KW
#define DEST_RESC_NAME_KW
Definition: rodsKeyWdDef.h:20
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
RuleExecInfo::condInputData
keyValPair_t * condInputData
Definition: irods_re_structs.hpp:34
irods::OPEN_OPERATION
const std::string OPEN_OPERATION("OPEN")
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
fileOpenInp_t::flags
int flags
Definition: fileOpen.h:21
transferStat_t::numThreads
int numThreads
Definition: objInfo.h:292
RESC_HIER_STR_KW
#define RESC_HIER_STR_KW
Definition: rodsKeyWdDef.h:225
fileOpenInp_t::addr
rodsHostAddr_t addr
Definition: fileOpen.h:19
FileCloseInp::fileInx
int fileInx
Definition: fileClose.h:7
fileOpenInp_t::objPath
char objPath[(1024+64)]
Definition: fileOpen.h:17
DataObjInfo::in_pdmo
char in_pdmo[(1024+64)]
Definition: objInfo.h:162
freeAllDataObjInfo
int freeAllDataObjInfo(dataObjInfo_t *dataObjInfoHead)
Definition: rcMisc.cpp:561
irods::hierarchy_parser::first_resc
error first_resc(std::string &_ret_resc) const
Definition: irods_hierarchy_parser.cpp:96
CAT_INSUFFICIENT_PRIVILEGE_LEVEL
@ CAT_INSUFFICIENT_PRIVILEGE_LEVEL
Definition: rodsErrorTable.h:445
RuleExecInfo::statusStr
char statusStr[(1024+64)]
Definition: irods_re_structs.hpp:20
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
fileOpenInp_t::mode
int mode
Definition: fileOpen.h:22
_rsDataObjPhymv
int _rsDataObjPhymv(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t *srcDataObjInfoHead, const char *_resc_name, transferStat_t *transStat, int multiCopyFlag)
Definition: rsDataObjPhymv.cpp:349
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
irods::hierarchy_parser::set_string
error set_string(const std::string &_resc_hier)
Definition: irods_hierarchy_parser.cpp:36
LOCAL_PRIV_USER_AUTH
#define LOCAL_PRIV_USER_AUTH
Definition: rodsUser.h:36
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
physPath.hpp
irods::log
void log(const error &)
Definition: irods_log.cpp:13
DEST_RESC_HIER_STR_KW
#define DEST_RESC_HIER_STR_KW
Definition: rodsKeyWdDef.h:226
rsFileClose
int rsFileClose(rsComm_t *rsComm, fileCloseInp_t *fileCloseInp)
Definition: rsFileClose.cpp:18
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
icatDefines.h
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
getDataObjInfo
int getDataObjInfo(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t **dataObjInfoHead, char *accessPerm, int ignoreCondInput)
Definition: dataObjOpr.cpp:87
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
dataObjRepl.h
fileOpenInp_t::condInput
keyValPair_t condInput
Definition: fileOpen.h:24
irods_hierarchy_parser.hpp
fileOpenInp_t
Definition: fileOpen.h:14
MULTI_COPIES_PER_RESC
#define MULTI_COPIES_PER_RESC
Definition: dataObjOpr.hpp:32
rodsServerHost
Definition: rodsConnect.h:62
DataObjInfo::rescName
char rescName[64]
Definition: objInfo.h:131
DataObjInp::oprType
int oprType
Definition: dataObjInpOut.h:72
rodsHostAddr_t::hostAddr
char hostAddr[256]
Definition: rodsDef.h:297
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
RuleExecInfo
Definition: irods_re_structs.hpp:18
resolveInfoForPhymv
int resolveInfoForPhymv(dataObjInfo_t **dataObjInfoHead, dataObjInfo_t **oldDataObjInfoHead, const std::string &_resc_name, keyValPair_t *condInput, int multiCopyFlag)
Definition: dataObjOpr.cpp:1364
getAndConnRemoteZone
int getAndConnRemoteZone(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remotZoneOpr)
Definition: rodsConnect.cpp:784
applyRule
int applyRule(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
Definition: irods_re_structs.cpp:65
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
fileOpenInp_t::in_pdmo
char in_pdmo[(1024+64)]
Definition: fileOpen.h:25
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
irods::get_loc_for_hier_string
error get_loc_for_hier_string(const std::string &_hier, std::string &_loc)
Definition: irods_resource_backport.cpp:633
ACCESS_DELETE_OBJECT
#define ACCESS_DELETE_OBJECT
Definition: icatDefines.h:60
SYS_COPY_ALREADY_IN_RESC
@ SYS_COPY_ALREADY_IN_RESC
Definition: rodsErrorTable.h:113
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
irods::CREATE_OPERATION
const std::string CREATE_OPERATION("CREATE")
DataObjInp::numThreads
int numThreads
Definition: dataObjInpOut.h:71
rsDataObjRepl.hpp
SpecCollCache
Definition: objInfo.h:102
objMetaOpr.hpp
dataObjPhymv.h
copyKeyVal
int copyKeyVal(const keyValPair_t *srcCondInput, keyValPair_t *destCondInput)
Definition: rcMisc.cpp:751