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)  

phymvUtil.cpp
Go to the documentation of this file.
1 
3 #ifndef windows_platform
4 #include <sys/time.h>
5 #endif
6 #include "rodsPath.h"
7 #include "rodsErrorTable.h"
8 #include "rodsLog.h"
9 #include "miscUtil.h"
10 #include "phymvUtil.h"
11 #include "rcGlobalExtern.h"
12 
13 int
14 phymvUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
15  rodsPathInp_t *rodsPathInp ) {
16  if ( rodsPathInp == NULL ) {
17  return USER__NULL_INPUT_ERR;
18  }
19 
20  dataObjInp_t dataObjInp;
21  initCondForPhymv( myRodsEnv, myRodsArgs, &dataObjInp );
22 
23  int savedStatus = 0;
24  for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
25  if ( strcmp("/", rodsPathInp->srcPath[i].outPath) == 0) {
27  "phymvUtil: '/' does not specify a zone; "
28  "physical move only makes sense within a zone.");
29  savedStatus = USER_INPUT_PATH_ERR;
30  continue;
31  }
32  if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
33  getRodsObjType( conn, &rodsPathInp->srcPath[i] );
34  if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
36  "phymvUtil: srcPath %s does not exist",
37  rodsPathInp->srcPath[i].outPath );
38  savedStatus = USER_INPUT_PATH_ERR;
39  continue;
40  }
41  }
42 
43  int status = 0;
44  if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
45  rmKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW );
46  status = phymvDataObjUtil( conn, rodsPathInp->srcPath[i].outPath,
47  myRodsArgs, &dataObjInp );
48  }
49  else if ( rodsPathInp->srcPath[i].objType == COLL_OBJ_T ) {
50  addKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW, "" );
51  status = phymvCollUtil( conn, rodsPathInp->srcPath[i].outPath,
52  myRodsEnv, myRodsArgs, &dataObjInp );
53  }
54  else {
55  /* should not be here */
57  "phymvUtil: invalid phymv objType %d for %s",
58  rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
59  return USER_INPUT_PATH_ERR;
60  }
61  /* XXXX may need to return a global status */
62  if ( status < 0 &&
65  "phymvUtil: phymv error for %s, status = %d",
66  rodsPathInp->srcPath[i].outPath, status );
67  savedStatus = status;
68  }
69  }
70  return savedStatus;
71 }
72 
73 int
74 phymvDataObjUtil( rcComm_t *conn, char *srcPath,
75  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
76  int status;
77  struct timeval startTime, endTime;
78 
79  if ( srcPath == NULL ) {
81  "phymvDataObjUtil: NULL srcPath input" );
82  return USER__NULL_INPUT_ERR;
83  }
84 
85  if ( rodsArgs->verbose == True ) {
86  ( void ) gettimeofday( &startTime, ( struct timezone * )0 );
87  }
88 
89  rstrcpy( dataObjInp->objPath, srcPath, MAX_NAME_LEN );
90 
91  status = rcDataObjPhymv( conn, dataObjInp );
92 
93  if ( status >= 0 && rodsArgs->verbose == True ) {
94  ( void ) gettimeofday( &endTime, ( struct timezone * )0 );
95  printTiming( conn, dataObjInp->objPath, conn->transStat.bytesWritten,
96  NULL, &startTime, &endTime );
97  }
98 
99  return status;
100 }
101 
102 int
103 initCondForPhymv( rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs,
104  dataObjInp_t *dataObjInp ) {
105 
106  if ( dataObjInp == NULL ) {
108  "initCondForPhymv: NULL dataObjInp input" );
109  return USER__NULL_INPUT_ERR;
110  }
111 
112  memset( dataObjInp, 0, sizeof( dataObjInp_t ) );
113 
114  if ( rodsArgs == NULL ) {
115  return 0;
116  }
117 
118  if ( rodsArgs->admin == True ) {
119  addKeyVal( &dataObjInp->condInput, ADMIN_KW, "" );
120  }
121 
122  if ( rodsArgs->replNum == True ) {
123  addKeyVal( &dataObjInp->condInput, REPL_NUM_KW,
124  rodsArgs->replNumValue );
125  }
126 
127  if ( rodsArgs->srcResc == True ) {
128  addKeyVal( &dataObjInp->condInput, RESC_NAME_KW,
129  rodsArgs->srcRescString );
130  }
131 
132  if ( rodsArgs->resource == True ) {
133  if ( rodsArgs->resourceString == NULL ) {
135  "initCondForPhymv: NULL resourceString error" );
136  return USER__NULL_INPUT_ERR;
137  }
138  else {
139  addKeyVal( &dataObjInp->condInput, DEST_RESC_NAME_KW,
140  rodsArgs->resourceString );
141  }
142  }
143  else if ( myRodsEnv != NULL && strlen( myRodsEnv->rodsDefResource ) > 0 ) {
144  addKeyVal( &dataObjInp->condInput, DEST_RESC_NAME_KW,
145  myRodsEnv->rodsDefResource );
146  }
147 
148  return 0;
149 }
150 
151 int
152 phymvCollUtil( rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv,
153  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
154  int status;
155  int savedStatus = 0;
156  collHandle_t collHandle;
157  collEnt_t collEnt;
158  char srcChildPath[MAX_NAME_LEN];
159 
160  if ( srcColl == NULL ) {
162  "phymvCollUtil: NULL srcColl input" );
163  return USER__NULL_INPUT_ERR;
164  }
165 
166  if ( rodsArgs->recursive != True ) {
168  "phymvCollUtil: -r option must be used for getting %s collection",
169  srcColl );
170  return USER_INPUT_OPTION_ERR;
171  }
172 
173  if ( rodsArgs->verbose == True ) {
174  fprintf( stdout, "C- %s:\n", srcColl );
175  }
176 
177  status = rclOpenCollection( conn, srcColl, 0, &collHandle );
178  if ( status < 0 ) {
180  "phymvCollUtil: rclOpenCollection of %s error. status = %d",
181  srcColl, status );
182  return status;
183  }
184  if ( collHandle.rodsObjStat->specColl != NULL &&
185  collHandle.rodsObjStat->specColl->collClass != LINKED_COLL ) {
186  /* no trim for mounted coll */
187  rclCloseCollection( &collHandle );
188  return 0;
189  }
190  while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) {
191  if ( collEnt.objType == DATA_OBJ_T ) {
192  snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s",
193  collEnt.collName, collEnt.dataName );
194 
195  int status = phymvDataObjUtil( conn, srcChildPath,
196  rodsArgs, dataObjInp );
197  if ( status < 0 ) {
199  "phymvCollUtil: phymvDataObjUtil failed for %s. status = %d",
200  srcChildPath, status );
201  /* need to set global error here */
202  savedStatus = status;
203  }
204  }
205  else if ( collEnt.objType == COLL_OBJ_T ) {
206  dataObjInp_t childDataObjInp;
207  childDataObjInp = *dataObjInp;
208  if ( collEnt.specColl.collClass != NO_SPEC_COLL ) {
209  childDataObjInp.specColl = &collEnt.specColl;
210  }
211  int status = phymvCollUtil( conn, collEnt.collName, myRodsEnv,
212  rodsArgs, &childDataObjInp );
213  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
214  savedStatus = status;
215  }
216  }
217  }
218  rclCloseCollection( &collHandle );
219 
220  if ( savedStatus < 0 ) {
221  return savedStatus;
222  }
223  else if ( status == CAT_NO_ROWS_FOUND ) {
224  return 0;
225  }
226  else {
227  return status;
228  }
229 }
230 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
rcComm_t
Definition: rcConnect.h:95
NULL
#define NULL
Definition: rodsDef.h:70
True
#define True
Definition: parseCommandLine.h:11
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
rodsPath.h
rclOpenCollection
int rclOpenCollection(rcComm_t *conn, char *collection, int flag, collHandle_t *collHandle)
Definition: miscUtil.cpp:1057
rodsArguments_t
Definition: parseCommandLine.h:14
phymvUtil
int phymvUtil(rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: phymvUtil.cpp:14
DataObjInp::specColl
specColl_t * specColl
Definition: dataObjInpOut.h:73
UNKNOWN_OBJ_T
@ UNKNOWN_OBJ_T
Definition: rodsType.h:37
RodsPathInp
Definition: rodsPath.h:33
collHandle_t
Definition: miscUtil.h:97
rodsArguments_t::verbose
int verbose
Definition: parseCommandLine.h:107
rodsArguments_t::srcRescString
char * srcRescString
Definition: parseCommandLine.h:93
CollEnt::collName
char * collName
Definition: miscUtil.h:119
RodsPath::objState
objStat_t objState
Definition: rodsPath.h:20
REPL_NUM_KW
#define REPL_NUM_KW
Definition: rodsKeyWdDef.h:30
rodsArguments_t::resource
int resource
Definition: parseCommandLine.h:86
rcGlobalExtern.h
RodsPathInp::srcPath
rodsPath_t * srcPath
Definition: rodsPath.h:35
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
RodsPath::objType
objType_t objType
Definition: rodsPath.h:19
transferStat_t::bytesWritten
rodsLong_t bytesWritten
Definition: objInfo.h:294
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
DEST_RESC_NAME_KW
#define DEST_RESC_NAME_KW
Definition: rodsKeyWdDef.h:20
rodsArguments_t::srcResc
int srcResc
Definition: parseCommandLine.h:92
LINKED_COLL
@ LINKED_COLL
Definition: objInfo.h:49
rodsArguments_t::admin
int admin
Definition: parseCommandLine.h:20
rclCloseCollection
int rclCloseCollection(collHandle_t *collHandle)
Definition: miscUtil.cpp:1354
phymvCollUtil
int phymvCollUtil(rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: phymvUtil.cpp:152
CollEnt
Definition: miscUtil.h:113
CollEnt::specColl
specColl_t specColl
Definition: miscUtil.h:130
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
collHandle_t::rodsObjStat
rodsObjStat_t * rodsObjStat
Definition: miscUtil.h:102
rmKeyVal
int rmKeyVal(keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:710
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
phymvDataObjUtil
int phymvDataObjUtil(rcComm_t *conn, char *srcPath, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: phymvUtil.cpp:74
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
NO_SPEC_COLL
@ NO_SPEC_COLL
Definition: objInfo.h:46
TRANSLATED_PATH_KW
#define TRANSLATED_PATH_KW
Definition: rodsKeyWdDef.h:97
rodsLog.h
rodsArguments_t::resourceString
char * resourceString
Definition: parseCommandLine.h:87
rcDataObjPhymv
int rcDataObjPhymv(rcComm_t *conn, dataObjInp_t *dataObjInp)
Definition: rcDataObjPhymv.cpp:68
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
CollEnt::dataName
char * dataName
Definition: miscUtil.h:120
rodsEnv::rodsDefResource
char rodsDefResource[64]
Definition: getRodsEnv.h:17
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
printTiming
int printTiming(rcComm_t *conn, char *objPath, rodsLong_t fileSize, char *localFile, struct timeval *startTime, struct timeval *endTime)
Definition: miscUtil.cpp:396
rodsArguments_t::recursive
int recursive
Definition: parseCommandLine.h:85
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
USER_INPUT_OPTION_ERR
@ USER_INPUT_OPTION_ERR
Definition: rodsErrorTable.h:249
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
rodsArguments_t::replNum
int replNum
Definition: parseCommandLine.h:63
rcComm_t::transStat
transferStat_t transStat
Definition: rcConnect.h:108
CollEnt::objType
objType_t objType
Definition: miscUtil.h:114
rclReadCollection
int rclReadCollection(rcComm_t *conn, collHandle_t *collHandle, collEnt_t *collEnt)
Definition: miscUtil.cpp:1108
initCondForPhymv
int initCondForPhymv(rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: phymvUtil.cpp:103
rodsErrorTable.h
rodsObjStat::specColl
specColl_t * specColl
Definition: objStat.h:18
miscUtil.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
rodsEnv
Definition: getRodsEnv.h:8
phymvUtil.h
NOT_EXIST_ST
@ NOT_EXIST_ST
Definition: rodsType.h:48
rodsArguments_t::replNumValue
char * replNumValue
Definition: parseCommandLine.h:64
getRodsObjType
int getRodsObjType(rcComm_t *conn, rodsPath_t *rodsPath)
Definition: miscUtil.cpp:200
USER_INPUT_PATH_ERR
@ USER_INPUT_PATH_ERR
Definition: rodsErrorTable.h:248
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247