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)  

rodsConnect.cpp
Go to the documentation of this file.
1 
4 /* initServer.cpp - Server initialization routines
5  */
6 
7 #include "rcMisc.h"
8 #include "rodsConnect.h"
9 #include "rsGlobalExtern.hpp"
10 #include "rcGlobalExtern.h"
11 #include "miscServerFunct.hpp"
12 #include "getRemoteZoneResc.h"
14 #include "rsLog.hpp"
15 
16 /* getAndConnRcatHost - get the rcat enabled host (result given in
17  * rodsServerHost) based on the rcatZoneHint.
18  * rcatZoneHint is the hint for which zone to go it. It can be :
19  * a full path - e.g., /A/B/C. In this case, "A" will be taken as the zone
20  * a zone name - a string wth the first character that is no '/' is taken
21  * as a zone name.
22  * NULL string - default to local zone
23  * If the rcat host is remote, it will automatically connect to the rcat host.
24  */
25 
27  rsComm_t *rsComm,
28  int rcatType,
29  const char *rcatZoneHint,
31 
32  int status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost );
33 
34  if ( status < 0 ) {
36  "getAndConnRcatHost:getRcatHost() failed. erro=%d", status );
37  return status;
38  }
39 
40  if ( ( *rodsServerHost )->localFlag == LOCAL_HOST ) {
41  return LOCAL_HOST;
42  }
44 
45  if ( status < 0 ) {
47  "getAndConnRcatHost: svrToSvrConnect to %s failed",
48  ( *rodsServerHost )->hostName->name );
49  if ( ( *rodsServerHost )->rcatEnabled == REMOTE_ICAT ) {
51  }
52  }
53  if ( status >= 0 ) {
54  return REMOTE_HOST;
55  }
56  else {
57  return status;
58  }
59 }
60 
61 int
62 getAndConnRcatHostNoLogin( rsComm_t *rsComm, int rcatType, char *rcatZoneHint,
64  int status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost );
65 
66  if ( status < 0 ) {
67  return status;
68  }
69 
70  if ( ( *rodsServerHost )->localFlag == LOCAL_HOST ) {
71  return LOCAL_HOST;
72  }
73 
75 
76  if ( status < 0 ) {
78  "getAndConnRcatHost: svrToSvrConnectNoLogin to %s failed",
79  ( *rodsServerHost )->hostName->name );
80  if ( ( *rodsServerHost )->rcatEnabled == REMOTE_ICAT ) {
82  }
83  }
84  return status;
85 }
86 
87 int
88 getRcatHost( int rcatType, const char *rcatZoneHint,
90  int status;
91  zoneInfo_t *myZoneInfo = NULL;
92 
93  status = getZoneInfo( rcatZoneHint, &myZoneInfo );
94  if ( status < 0 ) {
95  return status;
96  }
97 
98  if ( rcatType == MASTER_RCAT ||
99  myZoneInfo->slaveServerHost == NULL ) {
100  *rodsServerHost = myZoneInfo->masterServerHost;
101  return myZoneInfo->masterServerHost->localFlag;
102  }
103  else {
104  *rodsServerHost = myZoneInfo->slaveServerHost;
105  return myZoneInfo->slaveServerHost->localFlag;
106  }
107 }
108 
110 mkServerHost( char *myHostAddr, char *zoneName ) {
111  rodsServerHost_t *tmpRodsServerHost;
112  int status;
113 
114  tmpRodsServerHost = ( rodsServerHost_t* )malloc( sizeof( rodsServerHost_t ) );
115  memset( tmpRodsServerHost, 0, sizeof( rodsServerHost_t ) );
116 
117  /* XXXXX need to lookup the zone table when available */
118  status = queHostName( tmpRodsServerHost, myHostAddr, 0 );
119  if ( status < 0 ) {
120  free( tmpRodsServerHost );
121  return NULL;
122  }
123 
124  tmpRodsServerHost->localFlag = UNKNOWN_HOST_LOC;
125 
126  status = queAddr( tmpRodsServerHost, myHostAddr );
127 
128  status = matchHostConfig( tmpRodsServerHost );
129 
130  status = getZoneInfo( zoneName,
131  ( zoneInfo_t ** )( static_cast< void * >( &tmpRodsServerHost->zoneInfo ) ) );
132 
133  if ( status < 0 ) {
134  free( tmpRodsServerHost );
135  return NULL;
136  }
137  else {
138  return tmpRodsServerHost;
139  }
140 }
141 
142 int
144  if ( rodsServerHost == NULL || myHostName == NULL ) {
145  return 0;
146  }
147 
148  // JMC :: consider empty host for coordinating nodes
150  time_t beforeTime = time( 0 );
151  char canonicalName[260]; // DNS specification limits hostnames to 255-ish bytes
152  const int ret_get_canonical_name = get_canonical_name(myHostName, canonicalName, sizeof(canonicalName));
153  if (ret_get_canonical_name != 0) {
154  if ( ProcessType == SERVER_PT ) {
156  "queAddr: get_canonical_name error for [%s], status [%d]",
157  myHostName, ret_get_canonical_name);
158  }
159  return SYS_GET_HOSTNAME_ERR;
160  }
161  time_t afterTime = time( 0 );
162  if ( afterTime - beforeTime >= 2 ) {
164  "get_canonical_name of %s is taking %d seconds. This could severely affect the interactivity of your iRODS system.",
165  myHostName, afterTime - beforeTime );
166  /* XXXXXX may want to mark resource down later */
167  }
168  if ( strcasecmp( myHostName, canonicalName ) != 0 ) {
169  queHostName( rodsServerHost, canonicalName, 0 );
170  }
171  }
172 
173  return 0;
174 }
175 
176 int
177 queHostName( rodsServerHost_t *rodsServerHost, const char *myName, int topFlag ) {
178  hostName_t *myHostName, *lastHostName;
179  hostName_t *tmpHostName;
180 
181  myHostName = lastHostName = rodsServerHost->hostName;
182 
183  while ( myHostName != NULL ) {
184  if ( strcmp( myName, myHostName->name ) == 0 ) {
185  return 0;
186  }
187  lastHostName = myHostName;
188  myHostName = myHostName->next;
189  }
190 
191  tmpHostName = ( hostName_t* )malloc( sizeof( hostName_t ) );
192  tmpHostName->name = strdup( myName );
193 
194  if ( topFlag > 0 ) {
195  tmpHostName->next = rodsServerHost->hostName;
196  rodsServerHost->hostName = tmpHostName;
197  }
198  else {
199  if ( lastHostName == NULL ) {
200  rodsServerHost->hostName = tmpHostName;
201  }
202  else {
203  lastHostName->next = tmpHostName;
204  }
205  tmpHostName->next = NULL;
206  }
207 
208  return 0;
209 }
210 
211 int
212 queRodsServerHost( rodsServerHost_t **rodsServerHostHead,
213  rodsServerHost_t *myRodsServerHost ) {
214  rodsServerHost_t *lastRodsServerHost, *tmpRodsServerHost;
215 
216  lastRodsServerHost = tmpRodsServerHost = *rodsServerHostHead;
217  while ( tmpRodsServerHost != NULL ) {
218  lastRodsServerHost = tmpRodsServerHost;
219  tmpRodsServerHost = tmpRodsServerHost->next;
220  }
221 
222  if ( lastRodsServerHost == NULL ) {
223  *rodsServerHostHead = myRodsServerHost;
224  }
225  else {
226  lastRodsServerHost->next = myRodsServerHost;
227  }
228  myRodsServerHost->next = NULL;
229 
230  return 0;
231 }
232 
234  const char* zoneName,
235  int portNum,
236  rodsServerHost_t* masterServerHost,
237  rodsServerHost_t* slaveServerHost ) {
238 
239  bool zoneAlreadyInList = false;
240 
241  zoneInfo_t *tmpZoneInfo, *lastZoneInfo;
242  zoneInfo_t *myZoneInfo;
243 
244  myZoneInfo = ( zoneInfo_t * ) malloc( sizeof( zoneInfo_t ) );
245 
246  memset( myZoneInfo, 0, sizeof( zoneInfo_t ) );
247 
248  rstrcpy( myZoneInfo->zoneName, zoneName, NAME_LEN );
249  if ( masterServerHost != NULL ) {
250  myZoneInfo->masterServerHost = masterServerHost;
251  masterServerHost->zoneInfo = myZoneInfo;
252  }
253  if ( slaveServerHost != NULL ) {
254  myZoneInfo->slaveServerHost = slaveServerHost;
255  slaveServerHost->zoneInfo = myZoneInfo;
256  }
257 
258  if ( portNum <= 0 ) {
259  if ( ZoneInfoHead != NULL ) {
260  myZoneInfo->portNum = ZoneInfoHead->portNum;
261  }
262  else {
264  "queZone: Bad input portNum %d for %s", portNum, zoneName );
265  free( myZoneInfo );
267  }
268  }
269  else {
270  myZoneInfo->portNum = portNum;
271  }
272 
273  /* queue it */
274 
275  lastZoneInfo = tmpZoneInfo = ZoneInfoHead;
276  while ( tmpZoneInfo != NULL ) {
277  if (strcmp(tmpZoneInfo->zoneName, myZoneInfo->zoneName) == 0 ) {
278  zoneAlreadyInList = true;
279  }
280  lastZoneInfo = tmpZoneInfo;
281  tmpZoneInfo = tmpZoneInfo->next;
282  }
283 
284  if ( lastZoneInfo == NULL ) {
285  ZoneInfoHead = myZoneInfo;
286  } else if (!zoneAlreadyInList) {
287  lastZoneInfo->next = myZoneInfo;
288  }
289  myZoneInfo->next = NULL;
290 
291  if ( masterServerHost == NULL ) {
293  "queZone: masterServerHost for %s is NULL", zoneName );
295  }
296  else {
297  return 0;
298  }
299 }
300 
301 int
302 matchHostConfig( rodsServerHost_t *myRodsServerHost ) {
303  rodsServerHost_t *tmpRodsServerHost;
304  int status;
305 
306  if ( myRodsServerHost == NULL ) {
307  return 0;
308  }
309 
310  if ( myRodsServerHost->localFlag == LOCAL_HOST ) {
311  tmpRodsServerHost = HostConfigHead;
312  while ( tmpRodsServerHost != NULL ) {
313  if ( tmpRodsServerHost->localFlag == LOCAL_HOST ) {
314  status = queConfigName( tmpRodsServerHost, myRodsServerHost );
315  return status;
316  }
317  tmpRodsServerHost = tmpRodsServerHost->next;
318  }
319  }
320  else {
321  tmpRodsServerHost = HostConfigHead;
322  while ( tmpRodsServerHost != NULL ) {
323  hostName_t *tmpHostName, *tmpConfigName;
324 
325  if ( tmpRodsServerHost->localFlag == LOCAL_HOST &&
326  myRodsServerHost->localFlag != UNKNOWN_HOST_LOC ) {
327  tmpRodsServerHost = tmpRodsServerHost->next;
328  continue;
329  }
330 
331  tmpConfigName = tmpRodsServerHost->hostName;
332  while ( tmpConfigName != NULL ) {
333  tmpHostName = myRodsServerHost->hostName;
334  while ( tmpHostName != NULL ) {
335  if ( strcmp( tmpHostName->name, tmpConfigName->name ) == 0 ) {
336  myRodsServerHost->localFlag =
337  tmpRodsServerHost->localFlag;
338  status = queConfigName( tmpRodsServerHost,
339  myRodsServerHost );
340  return 0;
341  }
342  tmpHostName = tmpHostName->next;
343  }
344  tmpConfigName = tmpConfigName->next;
345  }
346  tmpRodsServerHost = tmpRodsServerHost->next;
347  }
348  }
349 
350  return 0;
351 }
352 
353 int
354 queConfigName( rodsServerHost_t *configServerHost,
355  rodsServerHost_t *myRodsServerHost ) {
356  hostName_t *tmpHostName = configServerHost->hostName;
357  int cnt = 0;
358 
359  while ( tmpHostName != NULL ) {
360  if ( cnt == 0 ) {
361  /* queue the first one on top */
362  queHostName( myRodsServerHost, tmpHostName->name, 1 );
363  }
364  else {
365  queHostName( myRodsServerHost, tmpHostName->name, 0 );
366  }
367  cnt ++;
368  tmpHostName = tmpHostName->next;
369  }
370 
371  return 0;
372 }
373 
374 int
376  rodsServerHost_t *tmpRodsServerHost = 0;
377  char *myHostAddr = 0;
378  char *myZoneName = 0;
379 
380  /* check if host exist */
381 
382  myHostAddr = addr->hostAddr;
383 
384  if ( strlen( myHostAddr ) == 0 ) {
386  return LOCAL_HOST;
387  }
388  if ( strlen( addr->zoneName ) == 0 ) {
389  myZoneName = ZoneInfoHead->zoneName;
390  }
391  else {
392  myZoneName = addr->zoneName;
393  }
394 
395  tmpRodsServerHost = ServerHostHead;
396  while ( tmpRodsServerHost != NULL ) {
397  hostName_t *tmpName;
398  zoneInfo_t *serverZoneInfo = ( zoneInfo_t * ) tmpRodsServerHost->zoneInfo;
399  if ( strcmp( myZoneName, serverZoneInfo->zoneName ) == 0 ) {
400  tmpName = tmpRodsServerHost->hostName;
401  while ( tmpName != NULL ) {
402  if ( strcasecmp( tmpName->name, myHostAddr ) == 0 ) {
403  *rodsServerHost = tmpRodsServerHost;
404  return tmpRodsServerHost->localFlag;
405  }
406  tmpName = tmpName->next;
407  }
408  }
409  tmpRodsServerHost = tmpRodsServerHost->next;
410  }
411 
412  /* no match */
413 
414  tmpRodsServerHost = mkServerHost( myHostAddr, myZoneName );
415 
416  if ( tmpRodsServerHost == NULL ) {
418  "resolveHost: mkServerHost error" );
420  }
421 
422  /* assume it is remote */
423  if ( tmpRodsServerHost->localFlag == UNKNOWN_HOST_LOC ) {
424  tmpRodsServerHost->localFlag = REMOTE_HOST;
425  }
426 
427  int status = queRodsServerHost( &ServerHostHead, tmpRodsServerHost );
428  if ( status < 0 ) {
429  rodsLog( LOG_ERROR, "resolveHost - queRodsServerHost failed." );
430  }
431  *rodsServerHost = tmpRodsServerHost;
432 
433  return tmpRodsServerHost->localFlag;
434 }
435 
436 int
439  int status;
440  rodsHostAddr_t addr;
441  int remoteFlag;
442  if ( dataObjInfo == NULL ) {
444  "resolveHostByDataObjInfo: NULL dataObjInfo" );
446  }
447 
448  // =-=-=-=-=-=-=-
449  // extract the host location from the resource hierarchy
450  std::string location;
451  irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
452  if ( !ret.ok() ) {
453  irods::log( PASSMSG( "resoAndConnHostByDataObjInfo - failed in get_loc_for_hier_string", ret ) );
454  return ret.code();
455  }
456 
457 
458  memset( &addr, 0, sizeof( addr ) );
459  rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN );
460 
461  remoteFlag = resolveHost( &addr, rodsServerHost );
462 
463  if ( remoteFlag == REMOTE_HOST ) {
464  status = svrToSvrConnect( rsComm, *rodsServerHost );
465  if ( status < 0 ) {
467  "resAndConnHostByDataObjInfo: svrToSvrConnect to %s failed",
468  ( *rodsServerHost )->hostName->name );
469  }
470  }
471  return remoteFlag;
472 }
473 
474 int
476  hostName_t *tmpHostName;
477 
478  if ( myServerHost->localFlag == LOCAL_HOST ) {
479 #ifdef SYSLOG
480  rodsLog( LOG_NOTICE, " LocalHostName: " );
481 #else /* SYSLOG */
482  fprintf( stderr, " LocalHostName: " );
483 #endif /* SYSLOG */
484  }
485  else {
486 #ifdef SYSLOG
487  rodsLog( LOG_NOTICE, " RemoteHostName: " );
488 #else /* SYSLOG */
489  fprintf( stderr, " RemoteHostName: " );
490 #endif /* SYSLOG */
491  }
492 
493  tmpHostName = myServerHost->hostName;
494 
495  while ( tmpHostName != NULL ) {
496 #ifdef SYSLOG
497  rodsLog( LOG_NOTICE, " %s,", tmpHostName->name );
498 #else /* SYSLOG */
499  fprintf( stderr, " %s,", tmpHostName->name );
500 #endif /* SYSLOG */
501  tmpHostName = tmpHostName->next;
502  }
503 
504 #ifdef SYSLOG
505  rodsLog( LOG_NOTICE, " Port Num: %d.\n\n", ( ( zoneInfo_t * )myServerHost->zoneInfo )->portNum );
506 #else /* SYSLOG */
507  fprintf( stderr, " Port Num: %d.\n\n",
508  ( ( zoneInfo_t * )myServerHost->zoneInfo )->portNum );
509 #endif /* SYSLOG */
510 
511  return 0;
512 }
513 
514 int
516  zoneInfo_t *tmpZoneInfo;
517  rodsServerHost_t *tmpRodsServerHost;
518 
519  tmpZoneInfo = ZoneInfoHead;
520 #ifdef SYSLOG
521  rodsLog( LOG_NOTICE, "Zone Info:\n" );
522 #else /* SYSLOG */
523  fprintf( stderr, "Zone Info:\n" );
524 #endif /* SYSLOG */
525  while ( tmpZoneInfo != NULL ) {
526  /* print the master */
527  tmpRodsServerHost = ( rodsServerHost_t * ) tmpZoneInfo->masterServerHost;
528 #ifdef SYSLOG
529  rodsLog( LOG_NOTICE, " ZoneName: %s ", tmpZoneInfo->zoneName );
530 #else /* SYSLOG */
531  fprintf( stderr, " ZoneName: %s ", tmpZoneInfo->zoneName );
532 #endif /* SYSLOG */
533 
534  if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) {
535 #ifdef SYSLOG
536  rodsLog( LOG_NOTICE, "Type: LOCAL_ICAT " );
537 #else /* SYSLOG */
538  fprintf( stderr, "Type: LOCAL_ICAT " );
539 #endif /* SYSLOG */
540  }
541  else {
542 #ifdef SYSLOG
543  rodsLog( LOG_NOTICE, "Type: REMOTE_ICAT " );
544 #else /* SYSLOG */
545  fprintf( stderr, "Type: REMOTE_ICAT " );
546 #endif /* SYSLOG */
547  }
548 
549 #ifdef SYSLOG
550  rodsLog( LOG_NOTICE, " HostAddr: %s PortNum: %d\n\n",
551  tmpRodsServerHost->hostName->name, tmpZoneInfo->portNum );
552 #else /* SYSLOG */
553  fprintf( stderr, " HostAddr: %s PortNum: %d\n\n",
554  tmpRodsServerHost->hostName->name, tmpZoneInfo->portNum );
555 #endif /* SYSLOG */
556 
557  /* print the slave */
558  tmpRodsServerHost = ( rodsServerHost_t * ) tmpZoneInfo->slaveServerHost;
559  if ( tmpRodsServerHost != NULL ) {
560 #ifdef SYSLOG
561  rodsLog( LOG_NOTICE, " ZoneName: %s ", tmpZoneInfo->zoneName );
562  rodsLog( LOG_NOTICE, "Type: LOCAL_SLAVE_ICAT " );
563  rodsLog( LOG_NOTICE, " HostAddr: %s PortNum: %d\n\n",
564  tmpRodsServerHost->hostName->name, tmpZoneInfo->portNum );
565 #else /* SYSLOG */
566  fprintf( stderr, " ZoneName: %s ", tmpZoneInfo->zoneName );
567  fprintf( stderr, "Type: LOCAL_SLAVE_ICAT " );
568  fprintf( stderr, " HostAddr: %s PortNum: %d\nn",
569  tmpRodsServerHost->hostName->name, tmpZoneInfo->portNum );
570 #endif /* SYSLOG */
571  }
572 
573  tmpZoneInfo = tmpZoneInfo->next;
574  }
575  /* print the reHost */
576  if ( getReHost( &tmpRodsServerHost ) >= 0 ) {
577 #ifdef SYSLOG
578  rodsLog( LOG_NOTICE, "reHost: %s", tmpRodsServerHost->hostName->name );
579 #else /* SYSLOG */
580  fprintf( stderr, "reHost: %s\n\n", tmpRodsServerHost->hostName->name );
581 #endif /* SYSLOG */
582  }
583  else {
584 #ifdef SYSLOG
585  rodsLog( LOG_ERROR, "reHost error" );
586 #else /* SYSLOG */
587  fprintf( stderr, "reHost error" );
588 #endif /* SYSLOG */
589  }
590 
591  if ( getXmsgHost( &tmpRodsServerHost ) >= 0 ) {
592 #ifdef SYSLOG
593  rodsLog( LOG_NOTICE, "xmsgHost", tmpRodsServerHost->hostName->name );
594 #else /* SYSLOG */
595  fprintf( stderr, "xmsgHost: %s\n\n", tmpRodsServerHost->hostName->name );
596 #endif /* SYSLOG */
597  }
598 
599  return 0;
600 }
601 
602 int
603 convZoneSockError( int inStatus ) {
604  int unixErr = getErrno( inStatus );
605  if ( inStatus + unixErr == USER_SOCK_CONNECT_ERR ) {
606  return CROSS_ZONE_SOCK_CONNECT_ERR - unixErr;
607  }
608  else {
609  return inStatus;
610  }
611 }
612 
613 int
614 getZoneInfo( const char *rcatZoneHint, zoneInfo_t **myZoneInfo ) {
615  int status;
616  zoneInfo_t *tmpZoneInfo;
617  int zoneInput;
618  char zoneName[NAME_LEN];
619 
620  if ( rcatZoneHint == NULL || strlen( rcatZoneHint ) == 0 ) {
621  zoneInput = 0;
622  }
623  else {
624  zoneInput = 1;
625  getZoneNameFromHint( rcatZoneHint, zoneName, NAME_LEN );
626  }
627 
628  *myZoneInfo = NULL;
629  tmpZoneInfo = ZoneInfoHead;
630  while ( tmpZoneInfo != NULL ) {
631  if ( zoneInput == 0 ) { /* assume local */
632  if ( tmpZoneInfo->masterServerHost->rcatEnabled == LOCAL_ICAT ) {
633  *myZoneInfo = tmpZoneInfo;
634  }
635  }
636  else { /* remote zone */
637  if ( strcmp( zoneName, tmpZoneInfo->zoneName ) == 0 ) {
638  *myZoneInfo = tmpZoneInfo;
639  }
640  }
641  if ( *myZoneInfo != NULL ) {
642  return 0;
643  }
644  tmpZoneInfo = tmpZoneInfo->next;
645  }
646 
647  if ( zoneInput == 0 ) {
649  "getRcatHost: No local Rcat" );
650  return SYS_INVALID_ZONE_NAME;
651  }
652  else {
654  "getZoneInfo: Invalid zone name from hint %s", rcatZoneHint );
655  status = getZoneInfo( ( const char* )NULL, myZoneInfo );
656  if ( status < 0 ) {
657  return SYS_INVALID_ZONE_NAME;
658  }
659  else {
660  return 0;
661  }
662  }
663 }
664 
665 int
666 getLocalZoneInfo( zoneInfo_t **outZoneInfo ) {
667  zoneInfo_t *tmpZoneInfo;
668 
669  tmpZoneInfo = ZoneInfoHead;
670  while ( tmpZoneInfo != NULL ) {
671  if ( tmpZoneInfo->masterServerHost->rcatEnabled == LOCAL_ICAT ) {
672  *outZoneInfo = tmpZoneInfo;
673  return 0;
674  }
675  tmpZoneInfo = tmpZoneInfo->next;
676  }
678  "getLocalZoneInfo: Local Zone does not exist" );
679 
680  *outZoneInfo = NULL;
681  return SYS_INVALID_ZONE_NAME;
682 }
683 
684 char*
686  zoneInfo_t *tmpZoneInfo;
687 
688  if ( getLocalZoneInfo( &tmpZoneInfo ) >= 0 ) {
689  return tmpZoneInfo->zoneName;
690  }
691  else {
692  return NULL;
693  }
694 }
695 
696 /* Check if there is a connected ICAT host, and if there is, disconnect */
697 int
698 getAndDisconnRcatHost( int rcatType, char *rcatZoneHint,
700  int status;
701 
702  status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost );
703 
704  if ( status < 0 ) {
705  return status;
706  }
707 
708  if ( ( *rodsServerHost )->conn != NULL ) { /* a connection exists */
709  status = rcDisconnect( ( *rodsServerHost )->conn );
710  return status;
711  }
712  return 0;
713 }
714 
715 int
716 disconnRcatHost( int rcatType, const char *rcatZoneHint ) {
717  int status;
719 
720  status = getRcatHost( rcatType, rcatZoneHint, &rodsServerHost );
721 
722  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
723  return status;
724  }
725 
726  if ( ( rodsServerHost )->localFlag == LOCAL_HOST ) {
727  return LOCAL_HOST;
728  }
729 
730  if ( rodsServerHost->conn != NULL ) { /* a connection exists */
733  }
734  if ( status >= 0 ) {
735  return REMOTE_HOST;
736  }
737  else {
738  return status;
739  }
740 }
741 
742 /* resetRcatHost is similar to disconnRcatHost except it does not disconnect */
743 
744 int
745 resetRcatHost( int rcatType, const char *rcatZoneHint ) {
747  int status = getRcatHost( rcatType, rcatZoneHint, &rodsServerHost );
748 
749  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
750  return status;
751  }
752 
753  if ( rodsServerHost->localFlag == LOCAL_HOST ) {
754  return LOCAL_HOST;
755  }
756 
758  return REMOTE_HOST;
759 }
760 
761 int
763  rodsServerHost_t *tmpRodsServerHost;
764 
765  /* check if host exist */
766 
767  tmpRodsServerHost = ServerHostHead;
768  while ( tmpRodsServerHost != NULL ) {
769  if ( tmpRodsServerHost->conn != NULL ) {
770  rcDisconnect( tmpRodsServerHost->conn );
771  tmpRodsServerHost->conn = NULL;
772  }
773  tmpRodsServerHost = tmpRodsServerHost->next;
774  }
775  return 0;
776 }
777 
778 /* getAndConnRemoteZone - get the remote zone host (result given in
779  * rodsServerHost) based on the dataObjInp->objPath as zoneHint.
780  * If the host is a remote zone, automatically connect to the host.
781  */
782 
783 int
785  rodsServerHost_t **rodsServerHost, char *remoteZoneOpr ) {
786  int status;
787 
788  status = getRemoteZoneHost( rsComm, dataObjInp, rodsServerHost,
789  remoteZoneOpr );
790 
791  if ( status == LOCAL_HOST ) {
792  return LOCAL_HOST;
793  }
794  else if ( status < 0 ) {
795  return status;
796  }
797 
798  status = svrToSvrConnect( rsComm, *rodsServerHost );
799 
800  if ( status < 0 ) {
802  "getAndConnRemoteZone: svrToSvrConnect to %s failed",
803  ( *rodsServerHost )->hostName->name );
804  }
805  if ( status >= 0 ) {
806  return REMOTE_HOST;
807  }
808  else {
809  return status;
810  }
811 }
812 
813 int
816  int status;
817  dataObjInp_t *srcDataObjInp, *destDataObjInp;
818  rodsServerHost_t *srcIcatServerHost = NULL;
819  rodsServerHost_t *destIcatServerHost = NULL;
820 
821  srcDataObjInp = &dataObjCopyInp->srcDataObjInp;
822  destDataObjInp = &dataObjCopyInp->destDataObjInp;
823 
824  status = getRcatHost( MASTER_RCAT, srcDataObjInp->objPath,
825  &srcIcatServerHost );
826 
827  if ( status < 0 || NULL == srcIcatServerHost ) { // JMC cppcheck - nullptr
829  "getAndConnRemoteZoneForCopy: getRcatHost error for %s",
830  srcDataObjInp->objPath );
831  return status;
832  }
833 
834  if ( srcIcatServerHost->rcatEnabled != REMOTE_ICAT ) {
835  /* local zone. nothing to do */
836  return LOCAL_HOST;
837  }
838 
839  status = getRcatHost( MASTER_RCAT, destDataObjInp->objPath,
840  &destIcatServerHost );
841 
842  if ( status < 0 || NULL == destIcatServerHost ) { // JMC cppcheck - nullptr
844  "getAndConnRemoteZoneForCopy: getRcatHost error for %s",
845  destDataObjInp->objPath );
846  return status;
847  }
848 
849  if ( destIcatServerHost->rcatEnabled != REMOTE_ICAT ) {
850  /* local zone. nothing to do */
851  return LOCAL_HOST;
852  }
853 
854  /* remote zone to different remote zone copy. Have to handle it
855  * locally because of proxy admin user privilege issue */
856  if ( srcIcatServerHost != destIcatServerHost ) {
857  return LOCAL_HOST;
858  }
859 
860  /* from the same remote zone. do it in the remote zone */
861 
862  status = getAndConnRemoteZone( rsComm, destDataObjInp, rodsServerHost,
863  REMOTE_CREATE );
864 
865  return status;
866 }
867 
868 int
870  int status;
871  rodsServerHost_t *icatServerHost = NULL;
872 
873  status = getRcatHost( MASTER_RCAT, zoneHint, &icatServerHost );
874 
875  if ( status < 0 || NULL == icatServerHost ) { // JMC cppcheck - nullptr
876  return 0;
877  }
878 
879  if ( icatServerHost->rcatEnabled != REMOTE_ICAT ) {
880  /* local zone. */
881  return 1;
882  }
883  else {
884  return 0;
885  }
886 }
887 
888 /* isSameZone - return 1 if from same zone, otherwise return 0
889  */
890 int
891 isSameZone( char *zoneHint1, char *zoneHint2 ) {
892  char zoneName1[NAME_LEN], zoneName2[NAME_LEN];
893 
894  if ( zoneHint1 == NULL || zoneHint2 == NULL ) {
895  return 0;
896  }
897 
898  getZoneNameFromHint( zoneHint1, zoneName1, NAME_LEN );
899  getZoneNameFromHint( zoneHint2, zoneName2, NAME_LEN );
900 
901  if ( strcmp( zoneName1, zoneName2 ) == 0 ) {
902  return 1;
903  }
904  else {
905  return 0;
906  }
907 }
908 
909 int
911  rodsServerHost_t **rodsServerHost, char *remoteZoneOpr ) {
912  int status;
913  rodsServerHost_t *icatServerHost = NULL;
914  rodsHostAddr_t *rescAddr = NULL;
915 
916  status = getRcatHost( MASTER_RCAT, dataObjInp->objPath, &icatServerHost );
917 
918  if ( status < 0 || NULL == icatServerHost ) { // JMC cppcheck - nullptr
919  return status;
920  }
921 
922  if ( icatServerHost->rcatEnabled != REMOTE_ICAT ) {
923  /* local zone. nothing to do */
924  return LOCAL_HOST;
925  }
926 
927  status = svrToSvrConnect( rsComm, icatServerHost );
928 
929  if ( status < 0 ) {
931  "getRemoteZoneHost: svrToSvrConnect to %s failed, status = %d",
932  icatServerHost->hostName->name, status );
934  return status;
935  }
936 
937  addKeyVal( &dataObjInp->condInput, REMOTE_ZONE_OPR_KW, remoteZoneOpr );
938 
939  status = rcGetRemoteZoneResc( icatServerHost->conn, dataObjInp, &rescAddr );
940  if ( status < 0 ) {
942  "getRemoteZoneHost: rcGetRemoteZoneResc for %s failed, status = %d",
943  dataObjInp->objPath, status );
944  return status;
945  }
946 
947  status = resolveHost( rescAddr, rodsServerHost );
948 
949  free( rescAddr );
950 
951  return status;
952 }
953 
954 int
955 isLocalHost( const char *hostAddr ) {
956  int remoteFlag;
958  rodsHostAddr_t addr;
959 
960  bzero( &addr, sizeof( addr ) );
961  rstrcpy( addr.hostAddr, hostAddr, NAME_LEN );
962  remoteFlag = resolveHost( &addr, &rodsServerHost );
963  if ( remoteFlag == LOCAL_HOST ) {
964  return 1;
965  }
966  else {
967  return 0;
968  }
969 }
970 
971 int
973  int status;
974 
975  rodsServerHost_t *tmpRodsServerHost;
976 
977  tmpRodsServerHost = ServerHostHead;
978  while ( tmpRodsServerHost != NULL ) {
979  if ( tmpRodsServerHost->reHostFlag == 1 ) {
980  *rodsServerHost = tmpRodsServerHost;
981  return 0;
982  }
983  tmpRodsServerHost = tmpRodsServerHost->next;
984  }
985  status = getRcatHost( MASTER_RCAT, ( const char* )NULL, rodsServerHost );
986 
987  return status;
988 }
989 
990 int
992  rodsServerHost_t *tmpRodsServerHost;
993 
994  tmpRodsServerHost = ServerHostHead;
995  while ( tmpRodsServerHost != NULL ) {
996  if ( tmpRodsServerHost->xmsgHostFlag == 1 ) {
997  *rodsServerHost = tmpRodsServerHost;
998  return 0;
999  }
1000  tmpRodsServerHost = tmpRodsServerHost->next;
1001  }
1002  *rodsServerHost = NULL;
1003 
1004  return SYS_INVALID_SERVER_HOST;
1005 }
1006 
1007 
1008 /* getAndConnReHost - Get the irodsReServer host (result given in
1009  * rodsServerHost).
1010  * If the is remote, it will automatically connect to the server where
1011  * irodsReServer is run.
1012  */
1013 
1014 int
1016  int status;
1017 
1019 
1020  if ( status < 0 ) {
1022  "getAndConnReHost:getReHost() failed. erro=%d", status );
1023  return status;
1024  }
1025 
1026  if ( ( *rodsServerHost )->localFlag == LOCAL_HOST ) {
1027  return LOCAL_HOST;
1028  }
1029 
1030  status = svrToSvrConnect( rsComm, *rodsServerHost );
1031 
1032  if ( status < 0 ) {
1034  "getAndConnReHost: svrToSvrConnect to %s failed",
1035  ( *rodsServerHost )->hostName->name );
1036  }
1037  if ( status >= 0 ) {
1038  return REMOTE_HOST;
1039  }
1040  else {
1041  return status;
1042  }
1043 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
LOCAL_ICAT
#define LOCAL_ICAT
Definition: rodsConnect.h:52
NULL
#define NULL
Definition: rodsDef.h:70
zoneInfo::masterServerHost
rodsServerHost_t * masterServerHost
Definition: rodsConnect.h:77
rsComm_t
Definition: rcConnect.h:145
DataObjCopyInp::srcDataObjInp
dataObjInp_t srcDataObjInp
Definition: dataObjCopy.h:26
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
getRemoteZoneResc.h
DataObjCopyInp
Definition: dataObjCopy.h:25
rsLog.hpp
myHostName
char myHostName[(1024+64)]
Definition: nre.reHelpers1.cpp:45
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
isSameZone
int isSameZone(char *zoneHint1, char *zoneHint2)
Definition: rodsConnect.cpp:891
rodsServerHost::rcatEnabled
int rcatEnabled
Definition: rodsConnect.h:65
irods::EMPTY_RESC_HOST
const std::string EMPTY_RESC_HOST("EMPTY_RESC_HOST")
LOG_WARNING
#define LOG_WARNING
Definition: rodsLog.h:38
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
queZone
int queZone(const char *zoneName, int portNum, rodsServerHost_t *masterServerHost, rodsServerHost_t *slaveServerHost)
Definition: rodsConnect.cpp:233
rcMisc.h
ServerHostHead
rodsServerHost_t * ServerHostHead
Definition: irods_server_globals.cpp:21
disconnectAllSvrToSvrConn
int disconnectAllSvrToSvrConn()
Definition: rodsConnect.cpp:762
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
isLocalZone
int isLocalZone(char *zoneHint)
Definition: rodsConnect.cpp:869
getLocalZoneName
char * getLocalZoneName()
Definition: rodsConnect.cpp:685
zoneInfo::zoneName
char zoneName[64]
Definition: rodsConnect.h:75
irods_resource_backport.hpp
resolveHost
int resolveHost(rodsHostAddr_t *addr, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:375
rodsServerHost::next
struct rodsServerHost * next
Definition: rodsConnect.h:71
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rcGlobalExtern.h
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
getXmsgHost
int getXmsgHost(rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:991
ZoneInfoHead
zoneInfo_t * ZoneInfoHead
Definition: irods_server_globals.cpp:23
rodsConnect.h
REMOTE_ICAT
#define REMOTE_ICAT
Definition: rodsConnect.h:54
ProcessType
int ProcessType
Definition: rcGlobal.cpp:16
isLocalHost
int isLocalHost(const char *hostAddr)
Definition: rodsConnect.cpp:955
printZoneInfo
int printZoneInfo()
Definition: rodsConnect.cpp:515
hostName::next
struct hostName * next
Definition: rodsConnect.h:39
rsGlobalExtern.hpp
queHostName
int queHostName(rodsServerHost_t *rodsServerHost, const char *myName, int topFlag)
Definition: rodsConnect.cpp:177
irods::error::code
long long code() const
Definition: irods_error.cpp:194
SYS_INVALID_ZONE_NAME
@ SYS_INVALID_ZONE_NAME
Definition: rodsErrorTable.h:94
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
hostName
Definition: rodsConnect.h:37
get_canonical_name
int get_canonical_name(const char *_hostname, char *_buf, size_t _len)
Definition: rcMisc.cpp:4580
queConfigName
int queConfigName(rodsServerHost_t *configServerHost, rodsServerHost_t *myRodsServerHost)
Definition: rodsConnect.cpp:354
UNKNOWN_HOST_LOC
#define UNKNOWN_HOST_LOC
Definition: rodsConnect.h:43
REMOTE_ZONE_OPR_KW
#define REMOTE_ZONE_OPR_KW
Definition: rodsKeyWdDef.h:81
hostName::name
char * name
Definition: rodsConnect.h:38
USER_SOCK_CONNECT_ERR
@ USER_SOCK_CONNECT_ERR
Definition: rodsErrorTable.h:236
HostConfigHead
rodsServerHost_t * HostConfigHead
Definition: irods_server_globals.cpp:22
REMOTE_CREATE
#define REMOTE_CREATE
Definition: getRemoteZoneResc.h:4
DataObjInp
Definition: dataObjInpOut.h:65
getZoneNameFromHint
int getZoneNameFromHint(const char *rcatZoneHint, char *zoneName, int len)
Definition: rcMisc.cpp:514
zoneInfo::next
struct zoneInfo * next
Definition: rodsConnect.h:79
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
CROSS_ZONE_SOCK_CONNECT_ERR
@ CROSS_ZONE_SOCK_CONNECT_ERR
Definition: rodsErrorTable.h:157
queRodsServerHost
int queRodsServerHost(rodsServerHost_t **rodsServerHostHead, rodsServerHost_t *myRodsServerHost)
Definition: rodsConnect.cpp:212
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
getRemoteZoneHost
int getRemoteZoneHost(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remoteZoneOpr)
Definition: rodsConnect.cpp:910
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsServerHost::xmsgHostFlag
int xmsgHostFlag
Definition: rodsConnect.h:67
zoneHint
char zoneHint[(1024+64)]
Definition: lsUtil.cpp:13
zoneInfo::portNum
int portNum
Definition: rodsConnect.h:76
rcGetRemoteZoneResc
int rcGetRemoteZoneResc(rcComm_t *conn, dataObjInp_t *dataObjInp, rodsHostAddr_t **rescAddr)
Definition: rcGetRemoteZoneResc.cpp:39
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
getAndConnRemoteZoneForCopy
int getAndConnRemoteZoneForCopy(rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:814
getAndConnRcatHostNoLogin
int getAndConnRcatHostNoLogin(rsComm_t *rsComm, int rcatType, char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:62
SYS_GET_HOSTNAME_ERR
@ SYS_GET_HOSTNAME_ERR
Definition: rodsErrorTable.h:85
irods::error
Definition: irods_error.hpp:23
getZoneInfo
int getZoneInfo(const char *rcatZoneHint, zoneInfo_t **myZoneInfo)
Definition: rodsConnect.cpp:614
miscServerFunct.hpp
rodsServerHost::reHostFlag
int reHostFlag
Definition: rodsConnect.h:66
mkServerHost
rodsServerHost_t * mkServerHost(char *myHostAddr, char *zoneName)
Definition: rodsConnect.cpp:110
getReHost
int getReHost(rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:972
DataObjCopyInp::destDataObjInp
dataObjInp_t destDataObjInp
Definition: dataObjCopy.h:27
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
rodsServerHost
Definition: rodsConnect.h:62
getAndDisconnRcatHost
int getAndDisconnRcatHost(int rcatType, char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:698
rodsHostAddr_t::hostAddr
char hostAddr[256]
Definition: rodsDef.h:297
getAndConnReHost
int getAndConnReHost(rsComm_t *rsComm, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:1015
svrToSvrConnectNoLogin
int svrToSvrConnectNoLogin(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:74
rcDisconnect
int rcDisconnect(rcComm_t *conn)
Definition: rcConnect.cpp:246
resoAndConnHostByDataObjInfo
int resoAndConnHostByDataObjInfo(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:437
resetRcatHost
int resetRcatHost(int rcatType, const char *rcatZoneHint)
Definition: rodsConnect.cpp:745
disconnRcatHost
int disconnRcatHost(int rcatType, const char *rcatZoneHint)
Definition: rodsConnect.cpp:716
SERVER_PT
#define SERVER_PT
Definition: rodsDef.h:78
rodsServerHost::zoneInfo
void * zoneInfo
Definition: rodsConnect.h:70
zoneInfo::slaveServerHost
rodsServerHost_t * slaveServerHost
Definition: rodsConnect.h:78
getLocalZoneInfo
int getLocalZoneInfo(zoneInfo_t **outZoneInfo)
Definition: rodsConnect.cpp:666
convZoneSockError
int convZoneSockError(int inStatus)
Definition: rodsConnect.cpp:603
printServerHost
int printServerHost(rodsServerHost_t *myServerHost)
Definition: rodsConnect.cpp:475
rodsServerHost::hostName
hostName_t * hostName
Definition: rodsConnect.h:63
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
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
zoneInfo
Definition: rodsConnect.h:74
matchHostConfig
int matchHostConfig(rodsServerHost_t *myRodsServerHost)
Definition: rodsConnect.cpp:302
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
queAddr
int queAddr(rodsServerHost_t *rodsServerHost, char *myHostName)
Definition: rodsConnect.cpp:143
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
getAndConnRemoteZone
int getAndConnRemoteZone(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remoteZoneOpr)
Definition: rodsConnect.cpp:784
rodsHostAddr_t::zoneName
char zoneName[64]
Definition: rodsDef.h:298
rodsHostAddr_t
Definition: rodsDef.h:296
getRcatHost
int getRcatHost(int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:88