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)  

chksumUtil.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 "miscUtil.h"
9 #include "rodsLog.h"
10 #include "chksumUtil.h"
11 #include "rcGlobalExtern.h"
12 
13 static int ChksumCnt = 0;
14 static int FailedChksumCnt = 0;
15 int
16 chksumUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
17  rodsPathInp_t *rodsPathInp ) {
18  if ( rodsPathInp == NULL ) {
19  return USER__NULL_INPUT_ERR;
20  }
21 
22  collInp_t collInp;
23  dataObjInp_t dataObjInp;
24  int savedStatus = initCondForChksum( myRodsArgs, &dataObjInp, &collInp );
25 
26  if ( savedStatus < 0 ) {
27  return savedStatus;
28  }
29 
30  for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
31  if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
32  getRodsObjType( conn, &rodsPathInp->srcPath[i] );
33  if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
34  rodsLog( LOG_ERROR, "chksumUtil: srcPath %s does not exist", rodsPathInp->srcPath[i].outPath );
35  savedStatus = USER_INPUT_PATH_ERR;
36  continue;
37  }
38  }
39 
40  int status = 0;
41  if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
42  rmKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW );
43  status = chksumDataObjUtil( conn, rodsPathInp->srcPath[i].outPath, myRodsArgs, &dataObjInp );
44  }
45 
46  else if ( rodsPathInp->srcPath[i].objType == COLL_OBJ_T ) {
47  addKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW, "" );
48  status = chksumCollUtil( conn, rodsPathInp->srcPath[i].outPath, myRodsEnv, myRodsArgs, &dataObjInp, &collInp );
49  }
50 
51  else {
52  /* should not be here */
53  rodsLog( LOG_ERROR, "chksumUtil: invalid chksum objType %d for %s",
54  rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
55  return USER_INPUT_PATH_ERR;
56  }
57  /* XXXX may need to return a global status */
58  if ( status < 0 &&
60  rodsLogError( LOG_ERROR, status, "chksumUtil: chksum error for %s, status = %d",
61  rodsPathInp->srcPath[i].outPath, status );
62  savedStatus = status;
63  }
64  }
65 
66  printf( "Total checksum performed = %d, Failed checksum = %d\n",
68 
69  return savedStatus;
70 }
71 
72 int
73 chksumDataObjUtil( rcComm_t *conn, char *srcPath,
74  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
75  int status;
76  struct timeval startTime, endTime;
77  char *chksumStr = NULL;
78  char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
79 
80  if ( srcPath == NULL ) {
81 
83  "chksumDataObjUtil: NULL srcPath input" );
84  return USER__NULL_INPUT_ERR;
85  }
86 
87  if ( rodsArgs->verbose == True ) {
88  ( void ) gettimeofday( &startTime, ( struct timezone * )0 );
89  }
90 
91  rstrcpy( dataObjInp->objPath, srcPath, MAX_NAME_LEN );
92 
93  status = rcDataObjChksum( conn, dataObjInp, &chksumStr );
94 
95  ChksumCnt++;
96 
97  if ( status < 0 ) {
100  "chksumDataObjUtil: rcDataObjChksum error for %s",
101  dataObjInp->objPath );
102  printErrorStack(conn->rError);
103  freeRError(conn->rError);
104  conn->rError = NULL;
105  return status;
106  }
107 
108  status = splitPathByKey( dataObjInp->objPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' );
109 
110  if ( 0 == status && rodsArgs->silent == False ) {
111  printf( " %s %s\n", myFile, chksumStr );
112  free( chksumStr );
113  if ( rodsArgs->verbose == True ) {
114  ( void ) gettimeofday( &endTime, ( struct timezone * )0 );
115  printTiming( conn, dataObjInp->objPath, -1, NULL,
116  &startTime, &endTime );
117  }
118  }
119 
120  return status;
121 }
122 
123 int
125  dataObjInp_t *dataObjInp, collInp_t *collInp ) {
126  if ( dataObjInp == NULL ) {
128  "initCondForChksum: NULL dataObjInp input" );
129  return USER__NULL_INPUT_ERR;
130  }
131 
132  memset( dataObjInp, 0, sizeof( dataObjInp_t ) );
133  memset( collInp, 0, sizeof( collInp_t ) );
134 
135  if ( rodsArgs == NULL ) {
136  return 0;
137  }
138 
139  if ( rodsArgs->force == True && rodsArgs->verifyChecksum ) {
141  "initCondForChksum: the 'K' and 'f' option cannot be used together" );
142  return USER_OPTION_INPUT_ERR;
143  }
144 
145  if ( rodsArgs->all == True && rodsArgs->replNum == True ) {
147  "initCondForChksum: the 'N' and 'a' option cannot be used together" );
148  return USER_OPTION_INPUT_ERR;
149  }
150 
151  if ( rodsArgs->admin == True ) {
152  addKeyVal( &dataObjInp->condInput, ADMIN_KW, "" );
153  }
154 
155  if ( rodsArgs->force == True ) {
156  addKeyVal( &dataObjInp->condInput, FORCE_CHKSUM_KW, "" );
157  addKeyVal( &collInp->condInput, FORCE_CHKSUM_KW, "" );
158  }
159 
160  if ( rodsArgs->all == True ) {
161  addKeyVal( &dataObjInp->condInput, CHKSUM_ALL_KW, "" );
162  addKeyVal( &collInp->condInput, CHKSUM_ALL_KW, "" );
163  }
164 
165  if ( rodsArgs->verifyChecksum == True ) {
166  addKeyVal( &dataObjInp->condInput, VERIFY_CHKSUM_KW, "" );
167  addKeyVal( &collInp->condInput, VERIFY_CHKSUM_KW, "" );
168  }
169 
170  if ( rodsArgs->replNum == True ) {
171  addKeyVal( &dataObjInp->condInput, REPL_NUM_KW,
172  rodsArgs->replNumValue );
173  }
174 
175  if ( rodsArgs->resource == True ) {
176  addKeyVal( &dataObjInp->condInput, RESC_NAME_KW,
177  rodsArgs->resourceString );
178  }
179 
180  if (rodsArgs->verify == True) {
181  if (rodsArgs->verifyChecksum == True) {
183  } else {
184  rodsLog(LOG_ERROR, "initCondForChksum: if --verify is used, -K must also be used");
185  return USER_OPTION_INPUT_ERR;
186  }
187  }
188 
189  /* XXXXX need to add -u register cond */
190 
191  dataObjInp->openFlags = O_RDONLY;
192 
193  return 0;
194 }
195 
196 int
197 chksumCollUtil( rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv,
198  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp ) {
199  int savedStatus = 0;
200  char srcChildPath[MAX_NAME_LEN];
201  collHandle_t collHandle;
202  collEnt_t collEnt;
203  int queryFlags;
204 
205  if ( srcColl == NULL ) {
207  "chksumCollUtil: NULL srcColl input" );
208  return USER__NULL_INPUT_ERR;
209  }
210 
211  fprintf( stdout, "C- %s:\n", srcColl );
212 
213  if ( rodsArgs->resource == True ) {
214  queryFlags = INCLUDE_CONDINPUT_IN_QUERY;
215  bzero( &collHandle, sizeof( collHandle ) );
216  replKeyVal( &dataObjInp->condInput, &collHandle.dataObjInp.condInput );
217  }
218  else {
219  queryFlags = 0;
220  }
221  int status = rclOpenCollection( conn, srcColl, queryFlags, &collHandle );
222  if ( status < 0 ) {
224  "chksumCollUtil: rclOpenCollection of %s error. status = %d",
225  srcColl, status );
226  return status;
227  }
228  if ( collHandle.rodsObjStat->specColl != NULL &&
229  collHandle.rodsObjStat->specColl->collClass != LINKED_COLL ) {
230  /* no trim for mounted coll */
231  rclCloseCollection( &collHandle );
232  return 0;
233  }
234  while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) {
235  if ( collEnt.objType == DATA_OBJ_T ) {
236  snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s",
237  collEnt.collName, collEnt.dataName );
238  /* screen unnecessary call to chksumDataObjUtil if user input a
239  * resource. */
240  int status = chksumDataObjUtil( conn, srcChildPath,
241  rodsArgs, dataObjInp );
242  if ( status < 0 ) {
244  "chksumCollUtil:chksumDataObjU failed for %s.stat = %d",
245  srcChildPath, status );
246  /* need to set global error here */
247  savedStatus = status;
248  }
249  }
250  else if ( collEnt.objType == COLL_OBJ_T ) {
251  dataObjInp_t childDataObjInp;
252  childDataObjInp = *dataObjInp;
253  if ( collEnt.specColl.collClass != NO_SPEC_COLL ) {
254  childDataObjInp.specColl = &collEnt.specColl;
255  }
256  else {
257  childDataObjInp.specColl = NULL;
258  }
259  int status = chksumCollUtil( conn, collEnt.collName, myRodsEnv,
260  rodsArgs, &childDataObjInp, collInp );
261  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
262  return status;
263  }
264  }
265  }
266  rclCloseCollection( &collHandle );
267  if ( savedStatus < 0 ) {
268  return savedStatus;
269  }
270  else if ( status == CAT_NO_ROWS_FOUND ) {
271  return 0;
272  }
273  else {
274  return status;
275  }
276 }
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::all
int all
Definition: parseCommandLine.h:18
DataObjInp::openFlags
int openFlags
Definition: dataObjInpOut.h:68
rodsArguments_t
Definition: parseCommandLine.h:14
CollInp
Definition: dataObjInpOut.h:157
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
CollEnt::collName
char * collName
Definition: miscUtil.h:119
rcComm_t::rError
rError_t * rError
Definition: rcConnect.h:106
freeRError
int freeRError(rError_t *myError)
Definition: rcMisc.cpp:170
chksumDataObjUtil
int chksumDataObjUtil(rcComm_t *conn, char *srcPath, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: chksumUtil.cpp:73
VERIFY_VAULT_SIZE_EQUALS_DATABASE_SIZE_KW
#define VERIFY_VAULT_SIZE_EQUALS_DATABASE_SIZE_KW
Definition: rodsKeyWdDef.h:84
chksumCollUtil
int chksumCollUtil(rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
Definition: chksumUtil.cpp:197
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
rodsArguments_t::verify
int verify
Definition: parseCommandLine.h:112
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
printErrorStack
int printErrorStack(rError_t *rError)
Definition: rcMisc.cpp:2327
rodsArguments_t::verifyChecksum
int verifyChecksum
Definition: parseCommandLine.h:53
LINKED_COLL
@ LINKED_COLL
Definition: objInfo.h:49
rodsArguments_t::admin
int admin
Definition: parseCommandLine.h:20
initCondForChksum
int initCondForChksum(rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
Definition: chksumUtil.cpp:124
rclCloseCollection
int rclCloseCollection(collHandle_t *collHandle)
Definition: miscUtil.cpp:1354
rcDataObjChksum
int rcDataObjChksum(rcComm_t *conn, dataObjInp_t *dataObjChksumInp, char **outChksum)
Definition: rcDataObjChksum.cpp:70
CHKSUM_ALL_KW
#define CHKSUM_ALL_KW
Definition: rodsKeyWdDef.h:59
CollEnt
Definition: miscUtil.h:113
CollEnt::specColl
specColl_t specColl
Definition: miscUtil.h:130
DataObjInp
Definition: dataObjInpOut.h:65
collHandle_t::dataObjInp
dataObjInp_t dataObjInp
Definition: miscUtil.h:105
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
CollInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:161
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
INCLUDE_CONDINPUT_IN_QUERY
#define INCLUDE_CONDINPUT_IN_QUERY
Definition: miscUtil.h:95
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
splitPathByKey
int splitPathByKey(const char *srcPath, char *dir, size_t maxDirLen, char *file, size_t maxFileLen, char key)
Definition: stringOpr.cpp:222
rodsLog.h
rodsArguments_t::resourceString
char * resourceString
Definition: parseCommandLine.h:87
FailedChksumCnt
static int FailedChksumCnt
Definition: chksumUtil.cpp:14
rodsArguments_t::force
int force
Definition: parseCommandLine.h:38
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
ChksumCnt
static int ChksumCnt
Definition: chksumUtil.cpp:13
CollEnt::dataName
char * dataName
Definition: miscUtil.h:120
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
chksumUtil.h
printTiming
int printTiming(rcComm_t *conn, char *objPath, rodsLong_t fileSize, char *localFile, struct timeval *startTime, struct timeval *endTime)
Definition: miscUtil.cpp:396
FORCE_CHKSUM_KW
#define FORCE_CHKSUM_KW
Definition: rodsKeyWdDef.h:60
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
VERIFY_CHKSUM_KW
#define VERIFY_CHKSUM_KW
Definition: rodsKeyWdDef.h:16
USER_OPTION_INPUT_ERR
@ USER_OPTION_INPUT_ERR
Definition: rodsErrorTable.h:259
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
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
rodsErrorTable.h
False
#define False
Definition: parseCommandLine.h:12
rodsObjStat::specColl
specColl_t * specColl
Definition: objStat.h:18
chksumUtil
int chksumUtil(rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: chksumUtil.cpp:16
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
rodsArguments_t::silent
int silent
Definition: parseCommandLine.h:128
rodsEnv
Definition: getRodsEnv.h:8
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
replKeyVal
int replKeyVal(const keyValPair_t *srcCondInput, keyValPair_t *destCondInput)
Definition: rcMisc.cpp:739
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247