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)  

rsDataObjCopy.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See dataObjCopy.h for a description of this API call.*/
5 
6 #include "dataObjCopy.h"
7 #include "rodsLog.h"
8 #include "objMetaOpr.hpp"
9 #include "collection.hpp"
10 #include "specColl.hpp"
11 #include "dataObjOpen.h"
12 #include "dataObjClose.h"
13 #include "dataObjCreate.h"
14 #include "dataObjRepl.h"
15 #include "regDataObj.h"
16 #include "rsGlobalExtern.hpp"
17 #include "rcGlobalExtern.h"
18 #include "getRemoteZoneResc.h"
19 #include "rsDataObjCopy.hpp"
20 #include "rsDataObjOpen.hpp"
21 #include "rsDataObjCreate.hpp"
22 #include "rsDataObjRepl.hpp"
23 #include "rsRegDataObj.hpp"
24 #include "rsDataObjClose.hpp"
25 
26 #define IRODS_FILESYSTEM_ENABLE_SERVER_SIDE_API
27 #include "filesystem.hpp"
28 
29 
30 // =-=-=-=-=-=-=-
32 
33 namespace {
34 
35 int close_objects(
36  rsComm_t* comm,
37  const int dest_l1_inx,
38  const int opr_status,
39  transferStat_t **transStat)
40 {
41  openedDataObjInp_t close_inp{.l1descInx = dest_l1_inx};
42  if (opr_status >= 0) {
43  int src_l1_inx = L1desc[dest_l1_inx].srcL1descInx;
44  dataObjInp_t* dest_data_obj_inp = L1desc[dest_l1_inx].dataObjInp;
45  dataObjInfo_t* src_data_obj_info = L1desc[src_l1_inx].dataObjInfo;
46  if (dest_data_obj_inp && src_data_obj_info) {
47  *transStat = ( transferStat_t* )malloc( sizeof( transferStat_t ) );
48  memset( *transStat, 0, sizeof( transferStat_t ) );
49  ( *transStat )->bytesWritten = src_data_obj_info->dataSize;
50  ( *transStat )->numThreads = dest_data_obj_inp->numThreads;
51  close_inp.bytesWritten = src_data_obj_info->dataSize;
52  }
53  }
54  const auto close_status = rsDataObjClose(comm, &close_inp);
55  if (close_status < 0) {
56  rodsLog(LOG_ERROR, "[%s] - Failed closing data object:[%d]",
57  __FUNCTION__, close_status);
58  }
59  return close_status;
60 } // close_objects
61 
62 int _rsDataObjCopy(
63  rsComm_t *rsComm,
64  int destL1descInx,
65  int existFlag)
66 {
67  dataObjInp_t *srcDataObjInp, *destDataObjInp;
68  dataObjInfo_t *srcDataObjInfo, *destDataObjInfo;
69  int srcL1descInx;
70  int status = 0;
71 
72  destDataObjInp = L1desc[destL1descInx].dataObjInp;
73  destDataObjInfo = L1desc[destL1descInx].dataObjInfo;
74  srcL1descInx = L1desc[destL1descInx].srcL1descInx;
75 
76  srcDataObjInp = L1desc[srcL1descInx].dataObjInp;
77  srcDataObjInfo = L1desc[srcL1descInx].dataObjInfo;
78 
79  if ( destDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
80  rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInp is NULL" );
81  return -1;
82  }
83  if ( destDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
84  rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInfo is NULL" );
85  return -1;
86  }
87  if ( srcDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
88  rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInp is NULL" );
89  return -1;
90  }
91  if ( srcDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
92  rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInfo is NULL" );
93  return -1;
94  }
95 
96  if ( L1desc[srcL1descInx].l3descInx <= 2 ) {
97 
98  /* no physical file was opened */
99  status = l3DataCopySingleBuf( rsComm, destL1descInx );
100 
101  /* has not been registered yet because of NO_OPEN_FLAG_KW */
102  if ( status >= 0 &&
103  existFlag == 0 &&
104  destDataObjInfo->specColl == NULL &&
105  L1desc[destL1descInx].remoteZoneHost == NULL ) {
106  /* If the dest is in remote zone, register in _rsDataObjClose there */
107  status = svrRegDataObj(rsComm, destDataObjInfo);
109  /* collection does not exist. make one */
110  char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN];
111  status = splitPathByKey(destDataObjInfo->objPath, parColl, MAX_NAME_LEN, child, MAX_NAME_LEN, '/');
112  if (status < 0) {
113  const auto err{ERROR(status,
114  (boost::format("splitPathByKey failed for [%s]") %
115  destDataObjInfo->objPath).str().c_str())};
116  irods::log(err);
117  }
118  status = rsMkCollR(rsComm, "/", parColl);
119  if (status < 0) {
120  const auto err{ERROR(status,
121  (boost::format("rsMkCollR for [%s] failed") %
122  parColl).str().c_str())};
123  irods::log(err);
124  }
125  status = svrRegDataObj(rsComm, destDataObjInfo);
126  }
127  if (status < 0) {
129  (boost::format("[%s] - svrRegDataObj for [%s] failed, status = [%d]") %
130  __FUNCTION__ % destDataObjInfo->objPath % status).str().c_str());
131  return status;
132  }
133  }
134  }
135  else {
136  destDataObjInp->numThreads = getNumThreads( rsComm, srcDataObjInfo->dataSize, destDataObjInp->numThreads, NULL,
137  destDataObjInfo->rescHier, srcDataObjInfo->rescHier, 0 );
138  srcDataObjInp->numThreads = destDataObjInp->numThreads;
139  status = dataObjCopy( rsComm, destL1descInx );
140  }
141 
142  return status;
143 }
144 
145 } // anonymous namespace
146 
147 int
148 rsDataObjCopy( rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp,
149  transferStat_t **transStat ) {
150  dataObjInp_t *srcDataObjInp, *destDataObjInp;
151  int srcL1descInx, destL1descInx;
152  int status;
153  int existFlag;
154  uint createMode;
155  int remoteFlag;
157  specCollCache_t *specCollCache = NULL;
158 
159  {
160  namespace fs = irods::experimental::filesystem;
161 
162  srcDataObjInp = &dataObjCopyInp->srcDataObjInp;
163  try {
164  if (! fs::server::is_data_object( *rsComm, srcDataObjInp->objPath )) {
165  return USER_INPUT_PATH_ERR;
166  }
167 
168  destDataObjInp = &dataObjCopyInp->destDataObjInp;
169  if (fs::path{destDataObjInp->objPath}.is_relative()) {
170  return USER_INPUT_PATH_ERR;
171  }
172  }
173  catch (const fs::filesystem_error & err) {
174  return err.code().value();
175  }
176  }
177 
178  resolveLinkedPath( rsComm, srcDataObjInp->objPath, &specCollCache, &srcDataObjInp->condInput );
179  resolveLinkedPath( rsComm, destDataObjInp->objPath, &specCollCache, &destDataObjInp->condInput );
180 
181  remoteFlag = getAndConnRemoteZoneForCopy( rsComm, dataObjCopyInp, &rodsServerHost );
182  if ( remoteFlag < 0 ) {
183  return remoteFlag;
184  }
185  else if ( remoteFlag == REMOTE_HOST ) {
186  status = _rcDataObjCopy( rodsServerHost->conn, dataObjCopyInp,
187  transStat );
188  return status;
189  }
190 
191  if ( strcmp( srcDataObjInp->objPath, destDataObjInp->objPath ) == 0 ) {
193  "rsDataObjCopy: same src and dest objPath %s not allowed",
194  srcDataObjInp->objPath );
195  return USER_INPUT_PATH_ERR;
196  }
197 
198  addKeyVal( &srcDataObjInp->condInput, PHYOPEN_BY_SIZE_KW, "" );
199 
200  srcL1descInx = rsDataObjOpen( rsComm, srcDataObjInp );
201 
202  if ( srcL1descInx < 0 ) {
203  std::stringstream msg;
204  char* sys_error = NULL;
205  const char* rods_error = rodsErrorName( srcL1descInx, &sys_error );
206  msg << __FUNCTION__;
207  msg << " - Failed to open source object: \"";
208  msg << srcDataObjInp->objPath;
209  msg << "\" - ";
210  msg << rods_error << " " << sys_error;
211  irods::log( LOG_ERROR, msg.str() );
212  free( sys_error );
213  return srcL1descInx;
214  }
215 
216  /* have to set L1desc[srcL1descInx].dataSize because open set this to -1 */
217  destDataObjInp->dataSize = L1desc[srcL1descInx].dataSize =
218  L1desc[srcL1descInx].dataObjInfo->dataSize;
219 
220  createMode = atoi( L1desc[srcL1descInx].dataObjInfo->dataMode );
221 
222  if ( createMode >= 0100 ) {
223  destDataObjInp->createMode = createMode;
224  }
225 
226  L1desc[srcL1descInx].oprType = COPY_SRC;
227 
228  if ( L1desc[srcL1descInx].l3descInx <= 2 ) {
229  /* dataSingleBuf */
230  addKeyVal( &destDataObjInp->condInput, NO_OPEN_FLAG_KW, "" );
231  }
232 
233  destDataObjInp->oprType = COPY_DEST;
234  destL1descInx = rsDataObjCreate( rsComm, destDataObjInp );
235  if ( destL1descInx == CAT_UNKNOWN_COLLECTION ) {
236  /* collection does not exist. make one */
237  char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN];
238  splitPathByKey( destDataObjInp->objPath, parColl, MAX_NAME_LEN, child, MAX_NAME_LEN, '/' );
239  rsMkCollR( rsComm, "/", parColl );
240  destL1descInx = rsDataObjCreate( rsComm, destDataObjInp );
241  }
242 
243  if ( destL1descInx < 0 ) {
244  // Close source resource before returning - leaks L1 descriptors
245  openedDataObjInp_t close_inp{.l1descInx = srcL1descInx};
246  if(const auto close_status = rsDataObjClose(rsComm, &close_inp);
247  close_status < 0) {
248  rodsLog(LOG_ERROR, "[%s] - Failed closing source replica for [%s]:[%d]",
249  __FUNCTION__, srcDataObjInp->objPath, close_status);
250  }
251 
252  clearKeyVal( &destDataObjInp->condInput );
253  std::stringstream msg;
254  char* sys_error = NULL;
255  const char* rods_error = rodsErrorName( destL1descInx, &sys_error );
256  msg << __FUNCTION__;
257  msg << " - Failed to create destination object: \"";
258  msg << destDataObjInp->objPath;
259  msg << "\" - ";
260  msg << rods_error << " " << sys_error;
261  irods::log( LOG_ERROR, msg.str() );
262  free( sys_error );
263  return destL1descInx;
264  }
265 
266  if ( L1desc[destL1descInx].replStatus == NEWLY_CREATED_COPY ) {
267  existFlag = 0;
268  }
269  else {
270  existFlag = 1;
271  }
272 
273  L1desc[destL1descInx].oprType = COPY_DEST;
274 
275  L1desc[destL1descInx].srcL1descInx = srcL1descInx;
276 
277  rstrcpy( L1desc[destL1descInx].dataObjInfo->dataType,
278 
279  L1desc[srcL1descInx].dataObjInfo->dataType, NAME_LEN );
280  /* set dataSize for verification in _rsDataObjClose */
281 
282  L1desc[destL1descInx].dataSize =
283  L1desc[srcL1descInx].dataObjInfo->dataSize;
284 
285  status = _rsDataObjCopy(rsComm, destL1descInx, existFlag);
286 
287  const int close_status = close_objects(rsComm, destL1descInx, status, transStat);
288 
289  clearKeyVal( &destDataObjInp->condInput );
290  if (status) {
291  return status;
292  }
293  return close_status;
294 }
295 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
OpenedDataObjInp
Definition: dataObjInpOut.h:104
L1desc
l1desc_t L1desc[1026]
Definition: irods_server_globals.cpp:29
NULL
#define NULL
Definition: rodsDef.h:70
regDataObj.h
rsComm_t
Definition: rcConnect.h:145
DataObjCopyInp::srcDataObjInp
dataObjInp_t srcDataObjInp
Definition: dataObjCopy.h:26
transferStat_t
Definition: objInfo.h:291
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
l1desc::remoteZoneHost
rodsServerHost_t * remoteZoneHost
Definition: objDesc.hpp:59
getRemoteZoneResc.h
DataObjCopyInp
Definition: dataObjCopy.h:25
NEWLY_CREATED_COPY
#define NEWLY_CREATED_COPY
Definition: objInfo.h:115
specColl.hpp
rsDataObjOpen.hpp
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
rsDataObjCreate.hpp
irods::experimental::filesystem::client::is_data_object
auto is_data_object(object_status _s) noexcept -> bool
Definition: filesystem.cpp:635
PHYOPEN_BY_SIZE_KW
#define PHYOPEN_BY_SIZE_KW
Definition: rodsKeyWdDef.h:46
l1desc::dataSize
rodsLong_t dataSize
Definition: objDesc.hpp:46
DataObjInp::dataSize
rodsLong_t dataSize
Definition: dataObjInpOut.h:70
rsDataObjOpen
int rsDataObjOpen(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjOpen.cpp:45
OpenedDataObjInp::l1descInx
int l1descInx
Definition: dataObjInpOut.h:105
rsDataObjCreate
int rsDataObjCreate(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjCreate.cpp:77
DataObjInfo::dataType
char dataType[64]
Definition: objInfo.h:133
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
svrRegDataObj
int svrRegDataObj(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
Definition: rsRegDataObj.cpp:120
l1desc::dataObjInfo
dataObjInfo_t * dataObjInfo
Definition: objDesc.hpp:42
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
filesystem.hpp
l1desc::oprType
int oprType
Definition: objDesc.hpp:37
rcGlobalExtern.h
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
dataObjCreate.h
irods_resource_redirect.hpp
rodsErrorName
const char * rodsErrorName(int errorValue, char **subName)
Definition: rodsLog.cpp:373
DataObjInfo::specColl
specColl_t * specColl
Definition: objInfo.h:158
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
rsGlobalExtern.hpp
CAT_UNKNOWN_COLLECTION
@ CAT_UNKNOWN_COLLECTION
Definition: rodsErrorTable.h:429
getNumThreads
int getNumThreads(rsComm_t *rsComm, rodsLong_t dataSize, int inpNumThr, keyValPair_t *condInput, char *destRescName, char *srcRescName, int oprType)
Definition: objDesc.cpp:279
_rcDataObjCopy
int _rcDataObjCopy(rcComm_t *conn, dataObjCopyInp_t *dataObjCopyInp, transferStat_t **transferStat)
Definition: rcDataObjCopy.cpp:107
irods::experimental::filesystem
Definition: collection_entry.hpp:12
COPY_SRC
#define COPY_SRC
Definition: dataObjInpOut.h:176
rsDataObjCopy.hpp
rsDataObjClose
int rsDataObjClose(rsComm_t *rsComm, openedDataObjInp_t *dataObjCloseInp)
Definition: rsDataObjClose.cpp:56
DataObjInp
Definition: dataObjInpOut.h:65
rsDataObjClose.hpp
NO_OPEN_FLAG_KW
#define NO_OPEN_FLAG_KW
Definition: rodsKeyWdDef.h:45
l1desc::dataObjInp
dataObjInp_t * dataObjInp
Definition: objDesc.hpp:41
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
l1desc::srcL1descInx
int srcL1descInx
Definition: objDesc.hpp:50
collection.hpp
splitPathByKey
int splitPathByKey(const char *srcPath, char *dir, size_t maxDirLen, char *file, size_t maxFileLen, char key)
Definition: stringOpr.cpp:222
rodsLog.h
dataObjCopy
int dataObjCopy(rsComm_t *rsComm, int l1descInx)
Definition: rsDataObjRepl.cpp:1041
irods::log
void log(const error &)
Definition: irods_log.cpp:13
l3DataCopySingleBuf
int l3DataCopySingleBuf(rsComm_t *rsComm, int l1descInx)
Definition: rsDataObjRepl.cpp:1185
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
dataObjClose.h
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
DataObjInp::createMode
int createMode
Definition: dataObjInpOut.h:67
dataObjRepl.h
DataObjCopyInp::destDataObjInp
dataObjInp_t destDataObjInp
Definition: dataObjCopy.h:27
getAndConnRemoteZoneForCopy
int getAndConnRemoteZoneForCopy(rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:814
COPY_DEST
#define COPY_DEST
Definition: dataObjInpOut.h:175
rodsServerHost
Definition: rodsConnect.h:62
DataObjInp::oprType
int oprType
Definition: dataObjInpOut.h:72
rsMkCollR
int rsMkCollR(rsComm_t *rsComm, const char *startColl, const char *destColl)
Definition: collection.cpp:428
dataObjOpen.h
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
rsRegDataObj.hpp
dataObjCopy.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
rsDataObjCopy
int rsDataObjCopy(rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, transferStat_t **transStat)
Definition: rsDataObjCopy.cpp:148
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
DataObjInfo
Definition: objInfo.h:129
USER_INPUT_PATH_ERR
@ USER_INPUT_PATH_ERR
Definition: rodsErrorTable.h:248
DataObjInfo::dataSize
rodsLong_t dataSize
Definition: objInfo.h:134
DataObjInp::numThreads
int numThreads
Definition: dataObjInpOut.h:71
rsDataObjRepl.hpp
SpecCollCache
Definition: objInfo.h:102
objMetaOpr.hpp