GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rawapin.c
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright:
3  * GSI, Gesellschaft fuer Schwerionenforschung mbH
4  * Planckstr. 1
5  * D-64291 Darmstadt
6  * Germany
7  * created 4.12.2000 by Horst Goeringer
8  ********************************************************************
9  * rawapin.c
10  * procedures for RFIO API client
11  * new version (corresponds to tsmcli)
12  *
13  * fully implemented (! GSI extension):
14  *
15  * rfio_open_gsidaq: ! open remote file in gStore and lustre
16  * rfio_open: open remote file in GSI mass storage
17  * rfio_endfile: ! close remote file, but keep connection to DM
18  * rfio_newfile: ! continue with next remote file in GSI mass storage
19  * rfio_read: read remote file in GSI mass storage
20  * rfio_write: write remote file in GSI mass storage
21  * rfio_close: close remote file and connection to GSI mass storage
22  * rfio_lseek: move read/write file pointer in remote file
23  * rfio_stat: get file status (32 bit file size)
24  * rfio_stat64: get file status (64 bit file size)
25  * rfio_cache_stat: ! returns cache status of file
26  *
27  * rfio_fopen_gsidaq_dm: ! open remote file in gStore and lustre,
28  * provide DM name and no.
29  * rfio_fopen_gsidaq: ! open remote file in gStore and lustre
30  * rfio_fopen: open remote file in GSI mass storage
31  * rfio_fendfile: ! close remote file, but keep connection to DM
32  * rfio_fnewfile: ! continue with next remote file in GSI mass storage
33  * rfio_fread: read remote file in GSI mass storage
34  * rfio_fwrite: write remote file in GSI mass storage
35  * rfio_fclose: close remote file and connection to GSI mass storage
36  * rfio_fstat: get file status (32 bit file size)
37  * rfio_fstat64: get file status (64 bit file size)
38  *
39  * implemented only as dummy:
40  *
41  * rfio_open64: needed, calls rfio_open
42  * rfio_lseek64: needed, calls rfio_lseek
43  * rfio_preseek64:
44  * rfio_mkdir: not needed, implicitly done
45  * rfio_opendir: not needed, implicitly done
46  * rfio_closedir: not needed, implicitly done
47  * rfio_readdir:
48  *
49  * rfio_access: get access status
50  * rfio_parse: parse name to host and path
51  * rfio_perror: print error message to stderr
52  * rfio_serror: print last error message to string
53  * rfio_unlink:
54  * rfiosetopt:
55  *
56  **********************************************************************
57  * 5. 8.2002, H.G.: new argument list in rawGetLLName
58  * 6. 8.2002, H.G.: connect to master server and data mover
59  * enhanced error handling
60  * 8. 8.2002, H.G.: shutdown of server processes after CTL C
61  * 9. 9.2002, H.G.: rfiosetopt added
62  * 17. 9.2002, H.G.: server node name added
63  * 23. 9.2002, H.G.: RFIO write functions added (for RFIO disk server)
64  * 14.10.2002, H.G.: ported to Lynx
65  * 18. 3.2003, H.G.: rawdef.h -> rawdefn.h
66  * 18. 7.2003, H.G.: remove CTL_C-handling
67  * 28. 8.2003, H.G.: add rfio_closedir, rfio_mkdir, rfio_opendir,
68  * rfio_readdir, rfio_stat as dummies
69  * 25. 9.2003, H.G.: take synchronization into account
70  * 29. 4.2004, H.G.: catch action without open in advance
71  * 16. 7.2004, H.G.: new entries: rfio_[f]endfile, rfio_[f]newfile
72  * 4. 8.2004, H.G.: new entries for rfiodaq
73  * 18. 8.2004, H.G.: new entries for rfiocopy
74  * 22.11.2004, H.G.: implement rfio_fstat
75  * 25.11.2004, H.G.: implement rfio_stat
76  * 26. 1.2005, H.G.: rawapitd-gsi.h -> rawapitd-gsin.h, new media names:
77  * GSI_CACHE_LOCKED, GSI_CACHE_INCOMPLETE
78  * 10. 5.2005, H.G.: handle data mover switch
79  * 16.12.2005, H.G.: rename rawGetFSName to rawGetFSpName
80  * 3. 4.2006, H.G.: ported to sarge
81  * 18. 4.2006, H.G.: new entry server lxgstore
82  * 25. 4.2006, H.G.: read via rfiocopy implemented
83  * 9. 5.2006, H.G.: rename QUERY_RETRIEVE_API -> QUERY_RETRIEVE_RECORD
84  * 1.11.2006, H.G.: iMode=1: no connection to DM (only query)
85  * 2.11.2006, H.G.: remove explicit query on alternate host:
86  * is done automatically on entry server
87  * 16. 3.2007, H.G.: handle data of both ATL servers
88  * 18. 4.2007, H.G.: new prefix node 'gstore', no longer 'adsmexp'
89  * 22. 5.2007, H.G.: new entries rfio_open64, rfio_lseek64
90  * 29. 5.2007, H.G.: new entries rfio_stat64, rfio_fstat64
91  * 1. 6.2007, H.G.: iMode=-1: no connection to DM (only query)
92  * iMode>0 wird von Root gesetzt (file permissions)
93  * add externals for Root 512-00
94  * 5. 7.2007, H.G.: rfio_access implemented
95  * 23. 8.2007, H.G.: writing: handling of DM session in file loop
96  * 24. 8.2007, H.G.: use iPoolIdRC, iPoolIdWC in srawComm
97  * 28. 8.2007, H.G.: use fprintm in Lynx,
98  * remove length restriction for obj name
99  * 25. 4.2008, H.G.: exclude usage of central data FS
100  * 16. 5.2008, H.G.: rfio_open, rfio_newfile: remove './' and
101  * trailing '/.' in gStore path name
102  * 29. 5.2008, H.G.: new entry rfio_preseek64 (dummy version)
103  * 5.11.2008, H.G.: rfio_open, rfio_read:
104  * improved error handling after rc=0 from recv()
105  * calling rawRecv...(): arg char ** -> char *
106  * 11.11.2008, H.G.: add suggestions of Hakan
107  * 12.11.2008, H.G.: new entry rfio_cache_stat implemented
108  * 13.11.2008, H.G.: inhibit using rfio_newfile/rfio_endfile for read
109  * 17.11.2008, H.G.: mod file args from 'char *' to 'const char *' in:
110  * rfio_access, rfio_fwrite, rfio_open, rfio_open64,
111  * rfio_unlink, rfio_write
112  * 3.12.2008, H.G.: add suggestions of Hakan, part II
113  * 10. 2.2009, H.G.: new entries rfio_fopen_gsidaq, rfio_open_gsidaq
114  * 26. 6.2009, H.G.: for 64 bit client: replace int args by size_t:
115  * rfio_fread: args 2, 3
116  * rfio_fwrite: args 2, 3
117  * rfio_read: arg 3
118  * rfio_write: arg 3
119  * 21. 8.2009, H.G.: rfio_newfile: optimize handling of large buflen
120  * 6.11.2009, H.G.: rfio_cache_stat: support call in loop
121  * 9.11.2009, H.G.: rfio_open_gsidaq: close if open for query only
122  * iOnlyQuery now global, no more DM selection if set
123  * rfio_cache_stat, rfio_stat: no more close needed
124  * 4.12.2009, H.G.: handle enhanced structure srawObjAttr
125  * 29. 1.2010, H.G.: enhance 256 -> STATUS_LEN for:
126  * cMsg, cTemp, cPrefix, rfio_errmsg
127  * 15. 2.2010, H.G.: add flag __USE_LARGEFILE64 for 64 bit functions
128  * 25. 2.2010, H.G.: rfio_cache_stat, rfio_stat:
129  * improve handling of already open files
130  * rfio_open_gsidaq:
131  * inhibit handling of already open files
132  * 26. 2.2010, H.G.: rawQueryString: add parameter (len output string)
133  * rfio_gsi_query: add parameter (len output string)
134  * 9. 3.2010, H.G.: take entry server name from URL specified
135  * 16. 4.2010, H.G.: srawDataMoverAttr: iSynchId -> iATLServer
136  * 23. 4.2010, H.G.: new entry rfio_fopen_gsidaq_dm
137  * rfio_open_gsidaq: clean control block after error
138  * copy fraction 0 specified: assume 1
139  * 22. 9.2010, H.G.: handle nodename 'lxgstore.gsi.de'
140  * 24. 9.2010, H.G.: handle 64 bit filesizes, now also in
141  * rfio_fstat64, rfio_stat64
142  * 23.11.2010, H.G.: gStore files >=4GB: inhibit read, incomplete query
143  **********************************************************************
144  */
145 
146 #include <stdio.h>
147 #include <ctype.h>
148 #include <string.h>
149 #include <fcntl.h>
150 #include <time.h>
151 #include <stdlib.h>
152 
153 #ifdef Linux
154 #include <netinet/in.h>
155 #include <sys/stat.h>
156 #include <unistd.h>
157 #endif
158 
159 FILE *fLogClient = NULL; /* client log */
160 #define MAX_LOG_FILE 64 /* max length of client log file name */
161 static char cLogClient[MAX_LOG_FILE] = "";
162 static int iLogFile = 1; /* default: client log to file */
163 static int iOS64 = 0; /* =0: 4 byte filesize, =1: 8 byte filesize */
164 
165 #ifdef Lynx
166 #include "error_mac.h"
167 #include "errnum_def.h"
168 #include "err_mask_def.h"
169 #include "f_ut_printm.h"
170 
171 #define fprintf fprintm
172 
173 #endif
174 
175 #include "rawdefn.h"
176 #include "rawapin.h" /* has includes for rawcommn.c and rawclin.h */
177 #include "rawentn.h"
178 
179 #include "rawapitd.h"
180 #include "rawapitd-gsin.h"
181 #include "rawapplcli.h"
182 
183 int* piEntryList; /* external in some utility functions */
184 int imySigS; /* if = 1: CTL C specified (extern in rconnect) */
185 FILE *fLogFile = NULL; /* external in some utility functions */
186 
187 /* externals for ROOT: TRFIOFile.cxx */
188 int serrno; /* id system error message */
189 int rfio_errno; /* id RFIO error message */
190 int tStageHostKey; /* Castor, root 512-00 */
191 int tStagePortKey; /* Castor, root 512-00 */
192 int tSvcClassKey; /* Castor, root 512-00 */
193 int tCastorVersionKey; /* Castor, root 512-00 */
194 
195 char *rawGetFSpName(char *);
196 
197 static char rfio_errmsg[STATUS_LEN] = ""; /* msg for stderr */
198 
199 #define MAX_BUFSIZE 32768
200 static int iint = sizeof(int);
201 static int irawComm = sizeof(srawComm);
202 static int iObjAttr = sizeof(srawObjAttr);
203 static int irawFileSystem = sizeof(srawFileSystem);
204 static int irawCopyCache = sizeof(srawCopyCache);
205 static int irawAPIFile = sizeof(srawAPIFile);
206  /* API file control block */
207 static int iOnlyQuery = 0; /* =1: query only, no connection to DM */
208 static char cPrefix[MAX_FULL_FILE] = "";
209 static char cNodePrefix[MAX_NODE] = "";
210 static char cNodeMaster[MAX_NODE] = "";
211 static char cNodeMover[MAX_NODE] = "";
213 static int iPortMover = PORT_MOVER;
214 static int iATLServer; /* =1: aixtsm1(AIX), =2: gsitsma(Windows)
215  if < 0: corresponding test system */
216 
218  /* max iteration no. receiving status */
220  /* sleep time (s) waiting for cache cleaning */
221 static int iFileCount = 0; /* currently open remote files */
222 static int iFileMax = 10; /* API file control blocks available */
223 static RFILE *pAPIFile[10] = /* ptrs to API file control blocks */
224  {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
225 
226 #ifdef __USE_LARGEFILE64
227 
228 /********************************************************************
229  * rfio_open64: open remote file in GSI mass storage
230  *
231  * created 22. 5.2007, Horst Goeringer
232  ********************************************************************
233  */
234 
235 int rfio_open64(const char *pcFile, /* file name */
236  int iFlags,
237  int iMode)
238 {
239  char cModule[32] = "rfio_open64";
240  int iDebug = 0;
241  int iFileId = -1;
242  int ii;
243 
244  if (iDebug) fprintf(fLogClient,
245  "\n-D- begin %s: file %s, flags %d, mode %d\n",
246  cModule, pcFile, iFlags, iMode);
247 
248  ii = sizeof(long);
249  if (ii < 8)
250  {
251  fprintf(fLogClient,
252  "-E- 32 bit client: %s not supported\n", cModule);
253 
254  return -1;
255  }
256 
257  iFileId = rfio_open(pcFile, iFlags, iMode);
258 
259  if (iDebug) fprintf(fLogClient,
260  "-D- end %s: iFileId(rfio_open) = %d\n\n", cModule, iFileId);
261 
262  return iFileId;
263 
264 } /* rfio_open64 */
265 
266 #endif /* __USE_LARGEFILE64 */
267 
268 /********************************************************************
269  * rfio_open: open connection to gStore server and file
270  *
271  * created 4.12.2000, Horst Goeringer
272  ********************************************************************
273  */
274 
275 int rfio_open(const char *pcFile, /* file name */
276  int iFlags,
277  int iOpenMode)
278 {
279  char cModule[32] = "rfio_open";
280  int iDebug = 0;
281  int iFileId = -1;
282  int iCopyMode = 0; /* ignore parameters for data stream copy */
283  char *pcCopyPath = NULL;
284  int iCopyFraction = 0;
285  int iMaxFile = 0;
286  int iPathConvention = 0;
287 
288  if (iDebug)
289  printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
290 
291  iFileId = rfio_open_gsidaq(pcFile, iFlags, iOpenMode,
292  iCopyMode,
293  pcCopyPath,
294  iCopyFraction,
295  iMaxFile,
296  iPathConvention);
297 
298  if (iDebug) printf(
299  "-D- end %s, iFileId(rfio_open_gsidaq) = %d\n\n",
300  cModule, iFileId);
301 
302  return iFileId;
303 
304 } /* rfio_open */
305 
306 /********************************************************************
307  * rfio_open_gsidaq: open connection to gStore server and file and
308  * prepare copy to lustre or read cache before migration to tape
309  *
310  * created 4.12.2000, Horst Goeringer
311  ********************************************************************
312  */
313 
315  const char *pcFile, /* fully qualified gStore file name */
316  int iFlags,
317  int iOpenMode,
318  int iCopyMode,
319  /* = 0: standard RFIO, ignore following arguments
320  = 1: copy to pcCopyPath after file written to WC
321  (for high data rates,
322  don't interfere writing to cache)
323  = 2: for lustre only:
324  write each data buffer in parallel to
325  write cache and to pcCopyPath
326  (for low data rates, anyhow first buffers
327  quickly available in lustre)
328  */
329  char *pcCopyPath,
330  /* destination where to be copied
331  = "/lustre..." => fully qualified path name
332  if not existing: will be created according
333  to user conventions:
334  ".../d" => Hades, create .../dyydddhhmm
335  = "RC" => read cache (not implemented)
336  */
337  int iCopyFraction,
338  /* = i>0: copy each ith file to pcCopyPath
339  */
340  int iMaxFile,
341  /* for dataFS only:
342  = 0: no file limit
343  > 0: max no. of files to be written to directory
344  files already existing are ignored
345  if iMaxFile reached, new dir will be created
346  (same level as previous one)
347  */
348  int iPathConvention)
349  /* rules for creation of initial/new path
350  = 0: default convention
351  initially specified .../xxx => .../xxx
352  last .../xxx => create ...xxx1
353  last .../xxxi => create ...xxxj j=i+1
354  = 1: Hades convention: path name contains time stamp
355  initially specified .../xxx => .../xxxyydddhhmm
356  new => .../xxxyydddhhmm
357  */
358 {
359  char cModule[32] = "rfio_open_gsidaq";
360  int iDebug = 0;
361  int iRC;
362  int iMaxConnect = 0; /* try connection to servers once */
363  int ii1, ii2;
364 
365 #ifndef Lynx
366  char cstr[16];
367  time_t tstr;
368  time_t tcur;
369  struct tm *ptloc;
370  pid_t pstr;
371 #endif
372 
373  unsigned long *plFileSizeC; /* ptr to file size in sComm */
374  int iObjInit = 1; /* default: gStore object will be initialized */
375  int iMassSto = -1;
376  /* >0: connect to gStore
377  =2: from DAQ to DAQPool (prefix contains rfiodaq:)
378  =1: to other pools (RC or ArchivePool/WC)
379  =0: connect to RFIO read/write server */
380  int iStage = 0; /* = 1: file in stage pool */
381  int iCache = 0; /* = 1: file in write cache */
382  int iStatus = 0;
383  int iStatusLen = 0;
384  int iIdent;
385  int iBuf, iBufl;
386  int iDataMoverSelect = 0;
387 
388  int iStatusOkay = 0;
389  int iStatusLoop = 0; /* current iteration no. receiving status */
390 
391  int iPoolId = 0;
392  /* for cmd buffer read action: =2 (StagePool)
393  for cmd buffer write action: =3: ArchivePool =4: DaqPool */
394  int iAction = 0; /* =1: read, =2: write */
395  int iError = 0;
396  int iSendEOS = 0;
397  /* =1: send EOS to connected servers (master and/or data mover) */
398 
399  int iFileId = -1; /* file identifier for server connection */
400  char cServer[24] = "";
401  int iSockMaster = -1; /* socket for connection to master */
402  int iSockMover = -1; /* socket for connection to mover */
403 
404  int iSeekMode = -1; /* default: no seek */
405  int iOffset = 0; /* default: no seek */
406  int iBufsizeAct = 0;
407  int iBufnoServ = 0; /* no. of buffers transfered from/to server */
408  int iDataServ = 0; /* no. of bytes transfered from/to server */
409 
410  int iMapFound = 0; /* =1: specified file already open */
411  int ii;
412  char *pcc, *pcc1;
413  char cTemp[STATUS_LEN] = "";
414  char cMsg[STATUS_LEN] = " ";
415  char cNamefs[MAX_OBJ_FS] = "", *pcNamefs; /* filespace name */
416  char cNamehl[MAX_OBJ_HL] = "", *pcNamehl; /* high level name */
417  char cNamell[MAX_OBJ_LL] = "", *pcNamell; /* low level name */
418  char cObject[MAX_FULL_FILE] = "";
419 
420  char cOwner[DSM_MAX_OWNER_LENGTH] = "";
421  char cliNode[MAX_NODE] = "";
422  char cAccess[16] = "";
423 
424  struct tm buf_time;
425 
426  srawDataMover sDataMoverSelect;
427  /* buffer with data mover attrs sent by server */
428  srawDataMoverAttr *pDataMoverSelect; /* selected data mover */
429 
430  srawStatus sStatus;
431  srawAPIFile *pcurAPIFile;
432  srawComm *pCommAPI; /* communication buffer in API control block */
433  srawComm *pCommServ; /* copy for servers in net format */
434  srawObjAttr *pQueryAPI; /* query information */
435  srawCopyCache *pCopyCacheServ;
436  /* infos in net format for copy of WC data */
437 
438  srawFileSystem sFileSystemServ;
439  /* if file in ArchivePool: FS infos for servers in net format */
440 
441  void *pBufQuery;
442  srawQueryResult sQuery;
443  srawObjAttr *pQAttr = NULL;
444 
445  if (fLogFile == NULL)
446  fLogFile = stdout;
447  if (fLogClient == NULL)
448  fLogClient = stdout;
449 
450  pDataMoverSelect = &(sDataMoverSelect.sDataMoverAttr);
451  pcNamefs = cNamefs;
452  pcNamehl = cNamehl;
453  pcNamell = cNamell;
454 
455  if (iFlags == O_RDONLY)
456  {
457  iAction = 1;
458  strcpy(cAccess, "read");
459  }
460  else
461  {
462  iAction = 2;
463  strcpy(cAccess, "write");
464  }
465 
466  ii = sizeof(long);
467  if (ii == 8)
468  iOS64 = 1;
469  else if (ii != 4) printf(
470  "-W- unexpected size of long integer: %d byte\n", ii);
471 
472  if (iDebug)
473  {
474  ii *= 8; /* size of 'long' in bit */
475  printf("\n-D- begin %s (%d bit OS)", cModule, ii);
476  if (iFileCount)
477  printf(", %d remote files currently open", iFileCount);
478  printf("\n");
479  }
480 
481  ii = 0;
482  if (iFileCount > 0)
483  while (ii < iFileMax)
484  {
485  if (pAPIFile[ii] != NULL)
486  {
487  pCommAPI = &(pAPIFile[ii]->sCommAPI);
488  strcpy(cObject, pCommAPI->cNamefs);
489  strcat(cObject, pCommAPI->cNamehl);
490  strcat(cObject, pCommAPI->cNamell);
491 
492  if (iDebug)
493  printf(" %d: %s already open\n", ii, cObject);
494 
495  pcc = strstr(pcFile, cObject);
496  if (pcc != NULL)
497  {
498  iMapFound = 1;
499  if (iDebug)
500  printf(" %d: %s maps\n", ii, cObject);
501  break;
502  }
503  }
504  else if (iDebug)
505  printf(" %d: no (more) open file found\n", ii);
506 
507  ii++;
508  }
509 
510  if (iMapFound)
511  {
512  fprintf(fLogClient,
513  "-E- %s: requested file %s is already open\n",
514  cModule, pcFile);
515 
516  iError = -1;
517  goto gError;
518  }
519 
520  if (ii == iFileMax)
521  {
522  fprintf(fLogClient,
523  "-E- %s: max %d remote files may be open simultaneously\n",
524  cModule, iFileMax);
525 
526  iError = -1;
527  goto gError;
528  }
529 
530  pAPIFile[ii] = (srawAPIFile *) malloc((unsigned) irawAPIFile);
531  if (pAPIFile[ii] == NULL)
532  {
533  fprintf(fLogClient,
534  "-E- %s: allocating file control block no. %d (%d byte)\n",
535  cModule, ii, irawAPIFile);
536  perror(" ");
537 
538  iError = -1;
539  goto gError;
540  }
541 
542  iFileId = ii;
543  iFileCount++;
544  if (iDebug) printf(
545  " file control block no. %d allocated (%d byte)\n",
546  ii, irawAPIFile);
547 
548  pcurAPIFile = pAPIFile[ii];
549  if (iOpenMode < 0) /* query only */
550  {
551  iOpenMode = 0;
552  iOnlyQuery = 1;
553  pcurAPIFile->iOpMode = 2;
554 
555  if (iDebug)
556  printf(" query only, iOpenMode %d reset to 0\n", iOpenMode);
557  }
558  else
559  pcurAPIFile->iOpMode = 0;
560 
561  pcurAPIFile->iFileId = iFileId;
562  pcurAPIFile->iFlags = iFlags;
563  pcurAPIFile->iMode = iOpenMode;
564  pcurAPIFile->iSockMaster = -1;
565  pcurAPIFile->iSockMover = -1;
566  pcurAPIFile->iSeekMode = iSeekMode;
567  pcurAPIFile->iOffset = iOffset;
568  pcurAPIFile->iBufsizeAct = iBufsizeAct;
569  pcurAPIFile->iBufnoServ = iBufnoServ;
570  pcurAPIFile->iDataServ = iDataServ;
571  pcurAPIFile->iAction = iAction;
572 
573  pCommAPI = &(pcurAPIFile->sCommAPI);
574  pCommAPI->iIdent = IDENT_COMM;
575  pCommAPI->iCommLen = irawComm - HEAD_LEN;
576  if (iOS64)
577  pCommAPI->iClient32 = 0;
578  else
579  pCommAPI->iClient32 = 1;
580 
581  pQueryAPI = &(pcurAPIFile->sQueryAPI);
582  pCommServ = &(pcurAPIFile->sCommServ);
583  pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
584 
585  /**************** analyze remote file specification **************/
586 
587  if ( (strchr(pcFile, *pcStar) != NULL) ||
588  (strchr(pcFile, *pcQM) != NULL) ||
589  (strchr(pcFile, *pcPerc) != NULL) )
590  {
591  fprintf(fLogClient,
592  "-E- %s: files with wildcard characters ('%s') not allowed using RFIO\n",
593  cModule, pcFile);
594 
595  iError = -1;
596  goto gError;
597  }
598 
599  /* handle prefixes to object name */
600  pcc = (char *) strchr(pcFile, *pcDevDelim);
601  if (pcc == NULL)
602  {
603  fprintf(fLogClient,
604  "-E- %s(1): invalid remote file name '%s': node name missing\n",
605  cModule, pcFile);
606 
607  iError = -1;
608  goto gError;
609  }
610 
611  /* convert prefix and/or node to lower case (in cTemp) */
612  strcpy(cTemp, pcFile);
613  pcc = (char *) strrchr(cTemp, *pcDevDelim);
614  pcc++;
615  strncpy(pcc, "\0", 1); /* terminates after prefix: or node: */
616  pcc1 = cTemp;
617  strcpy(cPrefix, pcc1); /* keep for case of name modifications */
618  while (*pcc1 != '\0')
619  {
620  *pcc1 = tolower(*pcc1);
621  pcc1++;
622  }
623 
624  /* cTemp contains now prefix: and/or node: in small letters */
625  if (iDebug)
626  printf(" URL in small letters: '%s'\n", cTemp);
627 
628  /* remove trailing '.gsi.de', if specified */
629  pcc = strstr(cTemp, ".gsi.de");
630  if (pcc)
631  {
632  strncpy(pcc++, ":", 1);
633  strncpy(pcc, "\0", 1);
634  if (iDebug)
635  printf(" remove trailing '.gsi.de': %s\n", cTemp);
636  }
637 
638  /* rfiocopy: or rfiodaq: or rfio: */
639  if (strncmp(cTemp, "rfio", 4) == 0)
640  {
641  pcc = (char *) strchr(cTemp, *pcDevDelim);
642  pcc++; /* skip device delimiter */
643  pcc1 = (char *) strrchr(pcc, *pcDevDelim);
644  if (pcc1 == NULL)
645  {
646  fprintf(fLogClient,
647  "-E- %s(2): invalid prefix '%s' of remote file name: node name missing\n",
648  cModule, pcFile);
649 
650  iError = -1;
651  goto gError;
652  }
653  strncpy(pcc1, "\0", 1); /* terminates after node name */
654 
655  /* now pcc points to node name */
656  if (strlen(pcc) == 0)
657  {
658  fprintf(fLogClient,
659  "-E- %s(3): invalid remote file name '%s': node name missing\n",
660  cModule, pcFile);
661 
662  iError = -1;
663  goto gError;
664  }
665 
666  strcpy(cNodePrefix, pcc);
667  if (iDebug)
668  printf(" node name after prefix 'rfio': '%s'\n", cNodePrefix);
669 
670  if (strncmp(cTemp, "rfiodaq:", 8) == 0)
671  {
672  if ( (iAction == 1) && (iOnlyQuery == 0) )
673  {
674  fprintf(fLogClient, "-E- %s: reading from DaqPool not allowed\n",
675  cModule);
676  fprintf(fLogClient, " correct object specification:\n");
677  fprintf(fLogClient, " [rfio:]node:/archive/path/file\n");
678 
679  iError = -1;
680  goto gError;
681  }
682 
683  iMassSto = 2; /* DAQPool */
684  strcpy(cServer, "gStore entry server");
685  iPoolId = 4;
686  }
687  else if (strncmp(cTemp, "rfio:", 5) == 0)
688  {
689  iMassSto = 1; /* ArchivePool */
690  strcpy(cServer, "gStore entry server");
691  if (iAction == 1)
692  {
693  if (iOnlyQuery == 0)
694  iPoolId = 2; /* StagePool */
695  }
696  else if (iAction == 2)
697  iPoolId = 3; /* ArchivePool */
698  }
699  else if (strncmp(cTemp, "rfiocopy:", 9) == 0)
700  {
701  iMassSto = 0;
702  strcpy(cServer, "RFIO server");
703  iPoolId = 0; /* not applicable */
706  }
707  else
708  {
709  fprintf(fLogClient,
710  "-E- %s: invalid remote file name '%s': unknown prefix\n",
711  cModule, pcFile);
712 
713  iError = -1;
714  goto gError;
715  }
716  } /* (strncmp(cTemp, "rfio", 4) == 0) */
717  else
718  {
719  /* node:/object */
720  pcc = (char *) strchr(cTemp, *pcDevDelim);
721  pcc1 = (char *) strrchr(pcc, *pcDevDelim);
722  if (pcc1 != pcc) /* more than one device delimiter */
723  {
724  fprintf(fLogClient,
725  "-E- %s: invalid remote file name '%s': invalid prefix\n",
726  cModule, pcFile);
727 
728  iError = -1;
729  goto gError;
730  }
731 
732  if (strlen(pcc) == 0)
733  {
734  fprintf(fLogClient,
735  "-E- %s(4): invalid remote file name '%s': node name missing\n",
736  cModule, pcFile);
737 
738  iError = -1;
739  goto gError;
740  }
741 
742  iMassSto = 1;
743  strcpy(cServer, "gStore entry server");
744  if (iAction == 1)
745  {
746  if (iOnlyQuery == 0)
747  iPoolId = 2; /* StagePool */
748  }
749  else if (iAction == 2)
750  iPoolId = 3; /* ArchivePool */
751 
752  strncpy(pcc, "\0", 1); /* terminates after node name */
753  strcpy(cNodePrefix, cTemp);
754  if (iDebug)
755  printf(" node name: '%s'\n", cNodePrefix);
756  }
757 
758  if ( (strcmp(cNodePrefix, "adsmexp") == 0) ||
759  (strcmp(cNodePrefix, "gsitsma") == 0) )
760  {
761  fprintf(fLogClient, "-E- %s: gStore server %s no longer supported\n",
762  cModule, cNodePrefix);
763 
764  iError = -1;
765  goto gError;
766  }
767 
768  pcurAPIFile->iMassSto = iMassSto;
769  if (iDebug)
770  {
771  if ( (iAction == 2) ||
772  ((iAction == 1) && (iOnlyQuery == 0)) )
773  printf(" %s, request poolId %d\n", cServer, iPoolId);
774  else
775  printf(" %s\n", cServer);
776  }
777 
778  /******************** now handle object name **********************/
779 
780  pcc = (char *) strrchr(pcFile, *pcDevDelim);
781  pcc++;
782 
783  if ( (strlen(pcc) == 0) || (strcmp(pcc, " ") == 0) )
784  {
785  if (iAction == 1)
786  {
787  fprintf(fLogClient,
788  "-E- %s: missing remote object for read access\n", cModule);
789 
790  iError = -1;
791  goto gError;
792  }
793 
794  pcurAPIFile->iOpMode = 1;
795  iObjInit = 0;
796  /* no open of remote file, requires following rfio_newfile */
797  if (iDebug)
798  {
799  if (iMassSto > 0)
800  printf(" remote object will be initialized later\n");
801  else
802  printf(" remote file will be initialized later\n");
803  }
804 
805  /* "" or "\0" are corrupted by TCP transfer, must be
806  initialized again in server */
807  strcpy(pcNamefs, "");
808  strcpy(pcNamehl, "");
809  strcpy(pcNamell, "");
810  strcpy(pCommAPI->cNamefs, "");
811  strcpy(pCommAPI->cNamehl, "");
812  strcpy(pCommAPI->cNamell, "");
813  }
814  else
815  {
816  iObjInit = 1;
817  strcpy(cTemp, pcc); /* cTemp contains now obj name */
818  pcc = (char *) strchr(cTemp, *pcObjDelim);
819  if (pcc == NULL)
820  {
821  fprintf(fLogClient,
822  "-E- %s: invalid remote file name %s\n", cModule, cTemp);
823 
824  iError = -1;
825  goto gError;
826  }
827 
828  pcc++;
829  pcc1 = (char *) strchr(pcc, *pcObjDelim);
830 
831  if (iMassSto > 0)
832  {
833  if (iDebug)
834  printf(" remote object %s\n", cTemp);
835 
836  if ( (pcc == NULL) || (pcc1 == NULL) )
837  {
838  fprintf(fLogClient,
839  "-E- %s: invalid remote object name '%s': archive name missing\n",
840  cModule, pcFile);
841 
842  iError = -1;
843  goto gError;
844  }
845 
846  pcc = pcc1;
847  strncpy(pcc1, "\0", 1); /* terminates archive name */
848  if (strlen(cTemp) > MAX_OBJ_FS-1)
849  {
850  ii = MAX_OBJ_FS-1;
851  fprintf(fLogClient, "-E- %s: archive name '%s' too long (max %d)\n",
852  cModule, cTemp, ii);
853 
854  iError = -1;
855  goto gError;
856  }
857 
858  if (strlen(cTemp) < 2)
859  {
860  fprintf(fLogClient, "-E- %s: invalid archive name '%s'\n",
861  cModule, cTemp);
862 
863  iError = -1;
864  goto gError;
865  }
866 
867  strcpy(pcNamefs, cTemp);
868  if (iDebug)
869  printf(" archive name %s\n", pcNamefs);
870 
871  strncpy(pcc, pcObjDelim, 1); /* recover obj delim */
872  pcc++;
873  pcc1 = (char *) strrchr(pcc, *pcObjDelim);
874  if (pcc1 == NULL)
875  {
876  fprintf(fLogClient,
877  "-E- %s: invalid remote object name '%s': path name missing\n",
878  cModule, pcFile);
879 
880  iError = -1;
881  goto gError;
882  }
883 
884  if (strlen(pcc1) > MAX_OBJ_LL-1)
885  {
886  ii = MAX_OBJ_LL-1;
887  fprintf(fLogClient, "-E- %s: file name '%s' too long (max %d)\n",
888  cModule, pcc1, ii);
889 
890  iError = -1;
891  goto gError;
892  }
893 
894  if (strlen(pcc1) < 2)
895  {
896  fprintf(fLogClient, "-E- %s: invalid file name '%s'\n", cModule, pcc1);
897 
898  iError = -1;
899  goto gError;
900  }
901 
902  strcpy(pcNamell, pcc1);
903  if (iDebug)
904  printf(" file name %s\n", pcNamell);
905 
906  pcc--;
907  strncpy(pcc1, "\0", 1); /* terminates after path name */
908  if (strlen(pcc) > MAX_OBJ_HL-1)
909  {
910  ii = MAX_OBJ_HL-1;
911  fprintf(fLogClient, "-E- %s: path name '%s' too long (max %d)\n",
912  cModule, pcc, ii);
913 
914  iError = -1;
915  goto gError;
916  }
917 
918  if (strlen(pcc) < 2)
919  {
920  fprintf(fLogClient, "-E- %s: invalid path name '%s'\n", cModule, pcc);
921 
922  iError = -1;
923  goto gError;
924  }
925 
926  strcpy(pcNamehl, pcc);
927  if (iDebug)
928  printf(" path name %s\n", pcNamehl);
929 
930  strcpy(pCommAPI->cNamefs, rawGetFSpName(pcNamefs));
931  iRC = rawGetLLName(pcNamell, pcObjDelim, pCommAPI->cNamell);
932  if (iRC)
933  {
934  fprintf(fLogClient, "-E- %s: invalid gStore file name: %s\n",
935  cModule, pCommAPI->cNamell);
936 
937  iError = -1;
938  goto gError;
939  }
940 
941  strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
942  if (strcmp(pcNamehl, pCommAPI->cNamehl))
943  {
944  strcpy(pcNamehl, pCommAPI->cNamehl);
945  printf(" gStore path name corrected to %s\n", pcNamehl);
946 
947  strcpy((char *) pcFile, cPrefix);
948  strcat((char *) pcFile, pCommAPI->cNamefs);
949  strcat((char *) pcFile, pCommAPI->cNamehl);
950  strcat((char *) pcFile, pCommAPI->cNamell);
951  if (iDebug) printf(
952  " new full file name: %s\n", pcFile);
953  }
954  } /* (iMassSto > 0) */
955  else
956  {
957  if (iDebug)
958  printf(" remote file %s\n", cTemp);
959 
960  strcpy(pcNamefs, "");
961  /* start with path, fs name has no meaning */
962 
963  pcc1 = (char *) strrchr(cTemp, *pcObjDelim);
964  if (pcc1 == NULL)
965  {
966  fprintf(fLogClient, "-E- %s: invalid remote file name '%s'\n",
967  cModule, cTemp);
968 
969  iError = -1;
970  goto gError;
971  }
972 
973  if (strlen(pcc1) > MAX_OBJ_LL-1)
974  {
975  ii = MAX_OBJ_LL-1;
976  fprintf(fLogClient, "-E- %s: file name '%s' too long (max %d)\n",
977  cModule, pcc1, ii);
978 
979  iError = -1;
980  goto gError;
981  }
982 
983  if (strlen(pcc1) < 2)
984  {
985  fprintf(fLogClient, "-E- %s: invalid file name '%s'\n", cModule, pcc1);
986 
987  iError = -1;
988  goto gError;
989  }
990 
991  strcpy(pcNamell, pcc1);
992  if (iDebug)
993  printf(" file name %s\n", pcNamell);
994 
995  strncpy(pcc1, "\0", 1); /* terminates after path name */
996  if (strlen(cTemp) > MAX_OBJ_HL-1)
997  {
998  ii = MAX_OBJ_HL-1;
999  fprintf(fLogClient, "-E- %s: path name '%s' too long (max %d)\n",
1000  cModule, cTemp, ii);
1001 
1002  iError = -1;
1003  goto gError;
1004  }
1005 
1006  if (strlen(cTemp) < 2)
1007  {
1008  fprintf(fLogClient, "-E- %s: invalid path name '%s'\n",
1009  cModule, cTemp);
1010 
1011  iError = -1;
1012  goto gError;
1013  }
1014 
1015  strcpy(pcNamehl, cTemp);
1016  if (iDebug)
1017  printf(" path name %s\n", pcNamehl);
1018 
1019  strcpy(pCommAPI->cNamefs, "\0");
1020  strcpy(pCommAPI->cNamehl, pcNamehl);
1021  strcpy(pCommAPI->cNamell, pcNamell);
1022 
1023  } /* (iMassSto == 0) */
1024  } /* (iObjInit) */
1025 
1026  /*********** check if copy from WC before tape migration *********/
1027 
1028  if (iCopyMode)
1029  {
1030  if (iAction != 2)
1031  {
1032  fprintf(fLogClient,
1033  "-E- copy from write cache only for write actions\n");
1034 
1035  iError = -1;
1036  goto gError;
1037  }
1038 
1039  if (iMassSto != 2)
1040  {
1041  fprintf(fLogClient,
1042  "-E- copy from write cache to lustre only when writing to DAQPool\n");
1043 
1044  iError = -1;
1045  goto gError;
1046  }
1047 
1048  if (iObjInit)
1049  {
1050  fprintf(fLogClient,
1051  "-E- copy from write cache only supported with rfio_[f]newfile\n");
1052 
1053  iError = -1;
1054  goto gError;
1055  }
1056 
1057  if ( (iCopyMode < 0) || (iCopyMode > 2) )
1058  {
1059  fprintf(fLogClient, "-E- invalid copy mode: %d\n", iCopyMode);
1060 
1061  iError = -1;
1062  goto gError;
1063  }
1064 
1065  if ( (strlen(pcCopyPath) == 0) || (pcCopyPath == NULL) )
1066  {
1067  fprintf(fLogClient, "-E- copy path missing\n");
1068 
1069  iError = -1;
1070  goto gError;
1071  }
1072 
1073  if (iCopyFraction < 0)
1074  {
1075  fprintf(fLogClient,
1076  "-E- invalid fraction of files to copied: %d (must be > 0)\n",
1077  iCopyFraction);
1078 
1079  iError = -1;
1080  goto gError;
1081  }
1082 
1083  if (iCopyFraction == 0)
1084  {
1085  fprintf(fLogClient,
1086  "-W- fraction of files to copied: 0 specified, assume 1 (copy all)\n");
1087 
1088  iCopyFraction = 1;
1089  }
1090 
1091  strcpy(cTemp, pcCopyPath);
1092  pcc = cTemp;
1093 
1094  /* for check, convert to lower case */
1095  while (*pcc != '\0')
1096  {
1097  *pcc = tolower(*pcc);
1098  pcc++; /* gcc 3.3.5: must be two steps, else string corrupted */
1099  }
1100  if (strcmp(cTemp, "rc") == 0)
1101  {
1102  fprintf(fLogClient,
1103  "-E- copy to read cache not yet implemented\n");
1104 
1105  iError = -1;
1106  goto gError;
1107  }
1108 
1109  strcpy(cTemp, pcCopyPath); /* use mixed case letters */
1110 
1111  /* check for trailing '/' */
1112  ii1 = 1;
1113  ii2 = 0; /* count no. of trailing '/' */
1114  pcc = cTemp;
1115  while (ii1)
1116  {
1117  pcc1 = strrchr(cTemp, '/');
1118  ii = pcc1 - pcc + 1;
1119  if (ii == strlen(pcc))
1120  {
1121  ii2++;
1122  strncpy(pcc1, "\0", 1);
1123  }
1124  else
1125  ii1 = 0;
1126  }
1127 
1128  if (ii2)
1129  {
1130  strcpy(pcCopyPath, cTemp);
1131  fprintf(fLogClient,
1132  " %d trailing '/' ignored, use copy destination '%s'\n",
1133  ii2, pcCopyPath);
1134  }
1135 
1136  /* check for valid lustre FS, at least one subdir */
1137  if ( (strncmp(pcCopyPath, cDataFSHigh1, strlen(cDataFSHigh1))) &&
1138  (strncmp(pcCopyPath, cDataFSHigh2, strlen(cDataFSHigh2))) )
1139  {
1140  fprintf(fLogClient,
1141  "-E- invalid copy destination %s\n", pcCopyPath);
1142 
1143  iError = -1;
1144  goto gError;
1145  }
1146 
1147  if (iMaxFile < 0)
1148  {
1149  fprintf(fLogClient,
1150  "-E- invalid max file no. for copy destination: %d\n",
1151  iMaxFile);
1152 
1153  iError = -1;
1154  goto gError;
1155  }
1156 
1157  if ( (iPathConvention < 0) || (iPathConvention > 1) )
1158  {
1159  fprintf(fLogClient,
1160  "-E- invalid convention no. for creation of new copy destination path: %d\n",
1161  iPathConvention);
1162 
1163  iError = -1;
1164  goto gError;
1165  }
1166 
1167  if (iCopyMode == 1)
1168  {
1169  if (iCopyFraction == 1) fprintf(fLogClient,
1170  "-I- copy each file to %s", pcCopyPath);
1171  else fprintf(fLogClient,
1172  "-I- copy each %d. file to %s", iCopyFraction, pcCopyPath);
1173  if (iPathConvention == 1)
1174  fprintf(fLogClient, "*");
1175  fprintf(fLogClient, " before tape migration\n");
1176  fprintf(fLogClient, " check success as asynchroneous copy process\n");
1177  }
1178  else
1179  {
1180  if (iCopyFraction == 1) fprintf(fLogClient,
1181  "-I- write data buffers of each file to gStore write cache and to %s",
1182  pcCopyPath);
1183  else fprintf(fLogClient,
1184  "-I- for each %d. file write data buffers additionally to %s",
1185  iCopyFraction, pcCopyPath);
1186  if (iPathConvention == 1)
1187  fprintf(fLogClient, "*\n");
1188  else
1189  fprintf(fLogClient, "\n");
1190  }
1191  if ( (iMaxFile) && (strcmp("rc", pcCopyPath)) ) fprintf(fLogClient,
1192  " if %d files are written, create new directory (convention no. %d)\n",
1193  iMaxFile, iPathConvention);
1194 
1195  /* store parameters */
1196  pCopyCacheServ->iIdent = htonl( (unsigned int) IDENT_COPY_CACHE);
1197  pCopyCacheServ->iCopyMode = htonl(iCopyMode);
1198  pCopyCacheServ->iCopyLen = htonl(0); /* indicates that copy
1199  buffer not yet sent to DM: set in rfio_newfile */
1200  strcpy(pCopyCacheServ->cCopyPath, pcCopyPath);
1201  pCopyCacheServ->iCopyFraction = htonl(iCopyFraction);
1202  pCopyCacheServ->iMaxFile = htonl(iMaxFile);
1203  pCopyCacheServ->iPathConvention = htonl(iPathConvention);
1204 
1205  if (iDebug) printf(
1206  " parameters for write cache copy stored\n");
1207 
1208  } /* (iCopyMode) */
1209 
1210  if (iMassSto > 0)
1211  {
1213  if (iCopyMode)
1215  else
1217 
1218  pcc = cNodePrefix + strlen(cNodePrefix) - 2; /* last 2 chars */
1219  if (strcmp(pcc, "_d") == 0)
1220  {
1221  strncpy(pcc, "\0", 1); /* terminates node name */
1222  if (iDebug)
1223  printf(" switch to test system\n");
1224 
1225  iPortMaster -= 10;
1226  iPortMover -= 10;
1227  }
1228 
1229  if ( (strcmp(cNodePrefix, "gstore") == 0) || /* in root, C */
1230  (strcmp(cNodePrefix, "//lxgstore") == 0) || /* in root */
1231  (strcmp(cNodePrefix, "///lxgstore") == 0) || /* in root */
1232  (strcmp(cNodePrefix, "///gstore") == 0) || /* in root */
1233  (strcmp(cNodePrefix, "//gstore") == 0) ) /* in root */
1234  strcpy(cNodeMaster, cNodeMaster0);
1235  else
1236  strcpy(cNodeMaster, cNodePrefix);
1237 
1238  if (iDebug) printf(
1239  " gStore entry server %s (node in URL %s)\n",
1241  fflush(stdout);
1242  }
1243  else
1244  strcpy(cNodeMaster, cNodePrefix);
1245 
1246  strcpy(pCommAPI->cNodeCacheMgr, cNodeMaster);
1247 
1248  pCommAPI->iSynchId = 0; /* =1: keep DM session after file close */
1249  pCommAPI->iExecStatus = 0; /* unused */
1250  pCommAPI->iWaitTime = 0; /* unused */
1251  strcpy(pCommAPI->cTapeLib, "0"); /* default tape library */
1252 
1253  if ( iAction == 1)
1254  {
1255  if (iOnlyQuery)
1256  pCommAPI->iAction = QUERY;
1257  else
1258  pCommAPI->iAction = QUERY_RETRIEVE_RECORD;/* at first query */
1259  }
1260  else
1261  {
1262  if (iMassSto)
1263  pCommAPI->iAction = QUERY_ARCHIVE_RECORD; /* at first query */
1264  else
1265  pCommAPI->iAction = ARCHIVE_RECORD;/* RFIO server: no query */
1266  }
1267 
1268  if (iDebug)
1269  {
1270  if (iMassSto == 0)
1271  {
1272  if (iObjInit) printf(
1273  " %s node %s:%d, file %s%s",
1274  cServer, cNodeMaster, iPortMaster, pcNamehl, pcNamell);
1275  else printf(
1276  " %s node %s:%d", cServer, cNodeMaster, iPortMaster);
1277  }
1278  else
1279  {
1280  if (iObjInit) printf(
1281  " %s %s:%d, TSM object %s%s%s",
1282  cServer, cNodeMaster, iPortMaster,
1283  pcNamefs, pcNamehl, pcNamell);
1284  else printf(
1285  " %s %s:%d", cServer, cNodeMaster, iPortMaster);
1286  }
1287  if (iPoolId)
1288  {
1289  if (iPoolId == 2)
1290  printf(", request StagePool\n");
1291  else if (iPoolId == 3)
1292  printf(", request ArchivePool\n");
1293  else if (iPoolId == 4)
1294  printf(", request DaqPool\n");
1295  }
1296  else
1297  printf("\n");
1298 
1299  if (iObjInit) printf(
1300  " FS name '%s', HL name '%s', LL name '%s', action %d\n",
1301  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell,
1302  pCommAPI->iAction);
1303  else printf(
1304  " action %d, object follows later\n", pCommAPI->iAction);
1305 
1306  } /* (iDebug) */
1307 
1308  /******************** get client information *********************/
1309 
1310  strcpy(cOwner, rawGetUserid());
1311  iRC = gethostname(cliNode, MAX_NODE);
1312  if (iRC)
1313  {
1314  fprintf(fLogClient, "-E- %s: getting client host name: %s\n",
1315  cModule, strerror(iRC));
1316 
1317  iError = -1;
1318  goto gError;
1319  }
1320 
1321  if (iDebug) printf(
1322  " user %s on node %s, platform %s\n",
1323  cOwner, cliNode, cOS); /* cOS from rawcli.h */
1324 
1325 #ifndef Lynx
1326  iLogFile = 0; /* client output to stdout */
1327  if ( (iMassSto) && /* not for rfiocopy: has server log */
1328  (fLogClient == stdout) && /* not yet to file */
1329  (iLogFile) ) /* local flag */
1330  {
1331  strcpy(cLogClient, "./RFIO");
1332  strcat(cLogClient, cOwner);
1333  tstr = time(NULL);
1334  sprintf(cstr, ".t%d", (int) tstr);
1335  strcat(cLogClient, cstr);
1336  pstr = getpid();
1337  sprintf(cstr, ".p%d", pstr);
1338  strcat(cLogClient, cstr);
1339  strcat(cLogClient, ".log");
1340 
1341  ii1 = strlen(cLogClient);
1342  ii2 = MAX_LOG_FILE;
1343  if (ii1 >= ii2)
1344  printf("-E- %s: log file name %s too long (%d, max %d)\n",
1345  cModule, cLogClient, ii1, --ii2);
1346 
1347  fLogClient = fopen(cLogClient, "w");
1348  if (fLogClient == NULL)
1349  {
1350  printf("-W- can not open log file %s, write to stdout\n",
1351  cLogClient);
1352  perror(" ");
1353  fLogClient = stdout;
1354  }
1355 
1356  printf("-I- log file %s\n", cLogClient);
1357  fprintf(fLogClient, "*** log file: %s, client node: %s\n",
1358  cLogClient, cliNode);
1359 
1360  /* get current date and time */
1361  tcur = time(NULL);
1362  ptloc = localtime_r(&tcur, &buf_time);
1363  (ptloc->tm_mon)++; /* else starts with zero */
1364  ptloc->tm_year += 1900;
1365 
1366  fprintf(fLogClient,
1367  " current date %d/%.2d/%.2d, time %.2d:%.2d:%.2d\n",
1368  ptloc->tm_year,
1369  ptloc->tm_mon,
1370  ptloc->tm_mday,
1371  ptloc->tm_hour,
1372  ptloc->tm_min,
1373  ptloc->tm_sec);
1374  fflush(fLogClient);
1375 
1376  } /* (iMassSto) */
1377 #endif
1378 
1379  strcpy(pCommAPI->cApplType, cApplType);
1380  strcpy(pCommAPI->cOwner, cOwner);
1381  strcpy(pCommAPI->cliNode, cliNode);
1382  strcpy(pCommAPI->cOS, cOS);
1383  strcpy(pCommAPI->cDataFS, ""); /* not supported in API client */
1384  pCommAPI->iDataFS = 0;
1385 
1386  if (iAction == 2)
1387  {
1388  pCommAPI->iPoolIdWC = iPoolId;
1389  pCommAPI->iPoolIdRC = 0;
1390  strcpy(pCommAPI->cNodeRC, "");
1391  pCommAPI->iStageFSid = 0;
1392 
1393  if (iPoolId == 4)
1394  pCommAPI->iArchDev = ARCH_DAQ_DISK;
1395  else
1396  pCommAPI->iArchDev = ARCH_DISK;
1397  }
1398  else
1399  {
1400  pCommAPI->iPoolIdRC = iPoolId;
1401  pCommAPI->iPoolIdWC = 0;
1402  pCommAPI->iArchDev = RETR_STAGE_TEMP;
1403  }
1404 
1405  if (iDebug)
1406  {
1407  if (iAction == 2)
1408  printf(" request WC poolId %d, device %d\n",
1409  pCommAPI->iPoolIdWC, pCommAPI->iArchDev);
1410  else if (iOnlyQuery == 0)
1411  printf(" request RC poolId %d, device %d\n",
1412  pCommAPI->iPoolIdRC, pCommAPI->iArchDev);
1413  }
1414 
1415  pCommServ->iIdent = htonl(pCommAPI->iIdent);
1416  pCommServ->iAction = htonl(pCommAPI->iAction);
1417  pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
1418  pCommServ->iBufsizeFile = htonl(0);
1419  pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
1420  pCommServ->iExecStatus = htonl(pCommAPI->iExecStatus);
1421  pCommServ->iWaitTime = htonl(pCommAPI->iWaitTime);
1422  strcpy(pCommServ->cNamefs, pCommAPI->cNamefs);
1423  strcpy(pCommServ->cNamehl, pCommAPI->cNamehl);
1424  strcpy(pCommServ->cNamell, pCommAPI->cNamell);
1425  strcpy(pCommServ->cOwner, pCommAPI->cOwner);
1426  strcpy(pCommServ->cOS, pCommAPI->cOS);
1427  strcpy(pCommServ->cApplType, pCommAPI->cApplType);
1428  strcpy(pCommServ->cliNode, pCommAPI->cliNode);
1429  strcpy(pCommServ->cTapeLib, pCommAPI->cTapeLib);
1430  strcpy(pCommServ->cDataFS, pCommAPI->cDataFS);
1431  strcpy(pCommServ->cNodeCacheMgr, pCommAPI->cNodeCacheMgr);
1432  pCommServ->iDataFS = htonl(pCommAPI->iDataFS);
1433  pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
1434  pCommServ->iPoolIdWC = htonl(pCommAPI->iPoolIdWC);
1435  pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
1436  pCommServ->iStageFSid = htonl(pCommAPI->iStageFSid);
1437  pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
1438  pCommServ->iClient32 = htonl(pCommAPI->iClient32);
1439 
1440  /******************* connect to entry server **********************/
1441 
1442  if (iDebug) printf(
1443  " connecting to %s %s:%d\n",
1444  cServer, cNodeMaster, iPortMaster);
1445 
1446  iRC = rconnect(cNodeMaster, iPortMaster, &iMaxConnect, &iSockMaster);
1447  if (iRC)
1448  {
1449  fprintf(fLogClient, "-E- %s: cannot connect to %s %s:%d\n",
1450  cModule, cServer, cNodeMaster, iPortMaster);
1451  iSendEOS = 0;
1452  iError = -1;
1453  goto gClose;
1454  }
1455 
1456  strcpy(pcurAPIFile->cNodeMaster, cNodeMaster);
1457  pcurAPIFile->iSockMaster = iSockMaster;
1458 
1459  if (iDebug)
1460  {
1461  printf("-I- successfully connected to %s %s:%d",
1462  cServer, cNodeMaster, iPortMaster);
1463  if (iMaxConnect)
1464  printf(" after %ds", iMaxConnect);
1465  printf(" (socket %d)\n", iSockMaster);
1466  }
1467 
1468  if (iMassSto == 0)
1469  {
1470  pCommServ->iFileType = htonl(STREAM);
1471  pCommServ->iBufsizeFile = htonl(0);
1472  pCommServ->iFileSize = htonl(0);
1473  pCommServ->iFileSize2 = htonl(0);
1474  pCommServ->iStageFSid = htonl(0);
1475 
1476  /* provide query infos to other API procedures */
1477  pCommAPI->iFileType = ntohl(pCommServ->iFileType);
1478  pCommAPI->iBufsizeFile = ntohl(pCommServ->iBufsizeFile);
1479  pCommAPI->iFileSize = ntohl(pCommServ->iFileSize);
1480  pCommAPI->iFileSize2 = ntohl(pCommServ->iFileSize2);
1481  pCommAPI->iStageFSid = ntohl(pCommServ->iStageFSid);
1482 
1483  /* rfiocopy: master and mover identical */
1484  strcpy(cNodeMover, cNodeMaster);
1485  strcpy(pcurAPIFile->cNodeMover, cNodeMaster);
1486  iSockMover = iSockMaster;
1487  pcurAPIFile->iSockMover = iSockMaster;
1488 
1489  iSockMaster = -1;
1490  pcurAPIFile->iSockMaster = -1;
1491 
1492  } /* (iMassSto == 0) */
1493  else
1494  {
1495  if (iAction == 2)
1497  else
1498  iATLServer = 0; /* query in both ATL servers */
1499 
1500  pCommAPI->iATLServer = iATLServer;
1501  pCommServ->iATLServer = htonl(iATLServer);
1502 
1503  if (iObjInit)
1504  {
1505  /********************* perform query ************************/
1506 
1507  pCommAPI->iSynchId = 0; /* reset */
1508  pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
1509 
1510  pBufQuery = &sQuery;
1511  pQAttr = &(sQuery.objAttr);
1512 
1513  if (iDebug)
1514  {
1515  printf(" query file %s in gStore\n", pcFile);
1516  ii = 1;
1517  }
1518  else
1519  ii = 0;
1520 
1521  iRC = rawQueryFile(iSockMaster, ii, pCommServ, &pBufQuery);
1522 
1523  if (iAction != 2) /* reset */
1524  {
1525  iATLServer = ntohl(pQAttr->iATLServer);
1526  pCommAPI->iATLServer = iATLServer;
1527  pCommServ->iATLServer = htonl(iATLServer);
1528  }
1529 
1530  if (iRC < 0)
1531  {
1532  if (iRC == -1001)
1533  {
1534  if (iATLServer == 0) sprintf(rfio_errmsg,
1535  "-E- no %s access to archive %s in all ATL servers\n",
1536  cAccess, pCommAPI->cNamefs);
1537  else sprintf(rfio_errmsg,
1538  "-E- no %s access to archive %s in ATL server %d\n",
1539  cAccess, pCommAPI->cNamefs, iATLServer);
1540  }
1541  else if (iRC == -1000) sprintf(rfio_errmsg,
1542  "-E- no archive %s in ATL server %d found\n",
1543  pCommAPI->cNamefs, iATLServer);
1544  else sprintf(rfio_errmsg,
1545  "-E- file %s: query in ATL server %d failed, rc = %d\n",
1546  pcFile, iATLServer, iRC);
1547  fprintf(fLogClient, "%s", rfio_errmsg);
1548 
1549  iSendEOS = 1;
1550  iError = -1;
1551  goto gClose;
1552  }
1553 
1554  if (iRC == 0)
1555  {
1556  if (iAction == 1) /* read */
1557  {
1558  if (iOnlyQuery)
1559  sprintf(rfio_errmsg,
1560  " file %s not available in gStore\n", pcFile);
1561  else
1562  sprintf(rfio_errmsg,
1563  "-E- %s: file %s not available in gStore\n",
1564  cModule, pcFile);
1565  fprintf(fLogClient, "%s", rfio_errmsg);
1566 
1567  iError = 1;
1568  iSendEOS = 1;
1569  goto gClose;
1570  }
1571 
1572  if (iDebug) printf(
1573  " file %s not yet available in gStore\n", pcFile);
1574  }
1575  else
1576  {
1577  if ( (iAction == 1) && /* read */
1578  (iOnlyQuery == 0) ) /* get data */
1579  {
1580  if ( (pQAttr->iFileSize2) && (iOS64 == 0) )
1581  {
1582  sprintf(rfio_errmsg,
1583  "-E- filesize of %s >= 4 GB, cannot be read with 32 bit client\n",
1584  pcFile);
1585  fprintf(fLogClient, "%s", rfio_errmsg);
1586 
1587  iSendEOS = 1;
1588  iError = 1;
1589  goto gClose;
1590  }
1591  }
1592  else if (iAction == 2) /* write */
1593  {
1594  sprintf(rfio_errmsg,
1595  "-E- file %s already available in gStore\n", pcFile);
1596  fprintf(fLogClient, "%s", rfio_errmsg);
1597 
1598  iSendEOS = 1;
1599  iError = 1;
1600  goto gClose;
1601  }
1602 
1603  memcpy(pQueryAPI, pQAttr, (unsigned) iObjAttr);
1604 
1605  if (iDebug)
1606  {
1607  printf(" file %s available in gStore (ATL server %d)\n",
1608  pcFile, iATLServer);
1609 
1610  if (iRC > 1) printf(
1611  "-W- %d versions of file %s exist\n", iRC, pcFile);
1612  ii = 1;
1613  }
1614  else
1615  ii = 0;
1616 
1617  rawQueryString(pQueryAPI, ii, sizeof(cMsg), cMsg);
1618  if ( (iDebug) || (iOnlyQuery) )
1619  printf(" %s", cMsg);
1620 
1621  iStage = ntohl(pQAttr->iFS);
1622  iCache = 0; /* reset/default */
1623  pCommAPI->iStageFSid = 0;
1624  pCommAPI->iFSidWC = 0;
1625  if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_STAGE) ||
1626  (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE) ||
1627  (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED) )
1628  {
1629  strcpy(cNodeMover, pQAttr->cNode);
1630  pCommAPI->iStageFSid = iStage;
1631  pCommAPI->iPoolIdRC = ntohl(pQAttr->iPoolId);
1632 
1633  if (iDebug)
1634  {
1635  printf(" file %s staged in FS %d of DM %s (poolId %d)",
1636  pcFile, iStage, cNodeMover, pCommAPI->iPoolIdRC);
1637  if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE)
1638  printf(", still incomplete)\n");
1639  else if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED)
1640  printf(", already locked)\n");
1641  else printf("\n");
1642  }
1643  }
1644  else if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_CACHE) ||
1645  (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE) ||
1646  (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED) )
1647  {
1648  iCache = 1;
1649 
1650  /* specify location of cache data */
1651  strcpy(sFileSystemServ.cOS, "Windows"); /* DDD */
1652  strcpy(sFileSystemServ.cNode, pQAttr->cNode);
1653  sFileSystemServ.iFileSystem = pQAttr->iFS;
1654  /* net format */
1655  sFileSystemServ.iFileSystem = pQAttr->iFS;
1656  /* net format */
1657  strcpy(sFileSystemServ.cArchiveDate, pQAttr->cDateCreate);
1658  /* archive date */
1659  strcpy(sFileSystemServ.cArchiveUser, pQAttr->cOwner);
1660  /* user who archived */
1661 
1662  strcpy(cNodeMover, pQAttr->cNode);
1663  strcpy(pCommAPI->cNodeWC, cNodeMover);
1664  pCommAPI->iFSidWC = iStage;
1665  pCommAPI->iPoolIdWC = ntohl(pQAttr->iPoolId);
1666 
1667  if (iDebug)
1668  {
1669  printf(" file %s cached in FS %d of DM %s (poolId %d)",
1670  pcFile, iStage, cNodeMover, pCommAPI->iPoolIdWC);
1671  if (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE)
1672  printf(", still incomplete)\n");
1673  else if (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED)
1674  printf(", already locked)\n");
1675  else printf("\n");
1676  }
1677  }
1678  else
1679  {
1680  iStage = 0;
1681  if (iDebug)
1682  printf(" file %s not yet staged\n", pcFile);
1683  }
1684  } /* iRC(rawQueryFile) > 0 */
1685  } /* (iObjInit) */
1686  else
1687  {
1688  /******** send request for data mover attr to master ********/
1689 
1690  /* prepare writing of records to server/data mover */
1691  pCommServ->iAction = htonl(SPM_REQUEST_MOVER);
1692 
1693  if (iDebug) printf(
1694  " send command buffer to %s: id: %d, action %d (ATL server %d), len %d\n",
1695  cServer, ntohl(pCommServ->iIdent),
1696  ntohl(pCommServ->iAction),
1697  ntohl(pCommServ->iATLServer),
1698  ntohl(pCommServ->iCommLen));
1699 
1700  if (iAction == 2)
1701  {
1702  pCommAPI->iSynchId = 1; /* keep DM session */
1703  pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
1704 
1705  if (iDebug) printf(
1706  " keep entry server session for next query\n");
1707  }
1708 
1709  pcc = (char *) pCommServ;
1710  iRC = send(iSockMaster, pcc, (unsigned) irawComm, 0);
1711  if (iRC < 0)
1712  {
1713  fprintf(fLogClient,
1714  "-E- %s: sending command buffer (action %d) to %s\n",
1715  cModule, ntohl(pCommServ->iAction), cServer);
1716  perror(" ");
1717 
1718  iSendEOS = 1;
1719  iError = 1;
1720  goto gClose;
1721  }
1722 
1723  if (irawComm != iRC)
1724  {
1725  fprintf(fLogClient,
1726  "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
1727  cModule, cServer, iRC, irawComm);
1728 
1729  iSendEOS = 1;
1730  iError = 1;
1731  goto gClose;
1732  }
1733 
1734  if (iDebug) printf(
1735  " command buffer (action %d) sent to %s (%d byte)\n",
1736  ntohl(pCommServ->iAction), cServer, irawComm);
1737 
1738  } /* (iObjInit == 0) */
1739 
1740  /********* get name of data mover selected by master ***********/
1741 
1742  if (iOnlyQuery)
1743  ;
1744  else
1745  if ( ( (iAction == 1) && ((iStage == 0) || (iCache == 1)) ) ||
1746  (iAction == 2) )
1747  {
1748  if (iDebug) printf(
1749  " receiving attributes of data mover selected by master\n");
1750 
1751  iDataMoverSelect = 0;
1752 
1753  while (iDataMoverSelect == 0)
1754  {
1755  pcc = (char *) &sDataMoverSelect;
1756  strcpy(cMsg, "");
1757 
1758  iRC = rawRecvHeadC(iSockMaster, pcc, 0, -1, cMsg);
1759  /* no check */
1760  iIdent = ntohl(sDataMoverSelect.iIdent);
1761  iStatus = ntohl(sDataMoverSelect.iStatus);
1762  iStatusLen = ntohl(sDataMoverSelect.iStatusLen);
1763 
1764  if (iDebug) printf(
1765  " ident %d, status %d, len %d\n",
1766  iIdent, iStatus, iStatusLen);
1767 
1768  if (iStatus != STA_SWITCH_SERVER)
1769  {
1770  if (iRC < 0) fprintf(fLogClient,
1771  "-E- %s: receiving data mover attr header\n%s",
1772  cModule, cMsg);
1773 
1774  if ( (iStatus == STA_CACHE_FULL) && (iAction == 2) )
1775  {
1776  iStatusLoop++;
1777  if ( (iStatusLoop < iStatusLoopMax) &&
1778  (iMassSto != 2) )
1779  fprintf(fLogClient,
1780  "-W- %s: write cache currently full (select) ... sleep %d s (%d of %d)\n",
1781  cModule, iSleepCacheFull, iStatusLoop,
1782  iStatusLoopMax);
1783  else
1784  {
1785  fprintf(fLogClient,
1786  "-W- %s: write cache currently full, archive to tape\n",
1787  cModule);
1788 
1789  if (iDebug) printf(
1790  " received DM name: %s\n", cMsg);
1791  iDataMoverSelect = 1;
1792  strcpy(cNodeMover, cMsg);
1793  strcpy(pDataMoverSelect->cNode, cMsg);
1794  pDataMoverSelect->iATLServer = htonl(0);
1795  pDataMoverSelect->iExecStatus = htonl(0);
1796  pDataMoverSelect->iWaitTime = htonl(0);
1797 
1798  pCommAPI->iArchDev = ARCH_TAPE;
1799  pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
1800 
1801  goto gReceivedDM;
1802  }
1803 
1804  /******* send request for DM attr to master ********/
1805 
1806  /* prepare writing of records to server */
1807  pCommServ->iAction = htonl(SPM_REQUEST_MOVER);
1808 
1809  if (iDebug) printf(
1810  " send command buffer to %s: id: %d, action %d, len %d\n",
1811  cServer, pCommAPI->iIdent,
1812  ntohl(pCommServ->iAction),
1813  ntohl(pCommServ->iCommLen));
1814 
1815  pcc = (char *) pCommServ;
1816  iRC = send(iSockMaster, pcc, (unsigned) irawComm, 0);
1817  if (iRC != irawComm)
1818  {
1819  if (iRC < 0)
1820  {
1821  fprintf(fLogClient,
1822  "-E- %s: sending command buffer (action %d) to %s\n",
1823  cModule, ntohl(pCommServ->iAction), cServer);
1824  perror(" ");
1825  }
1826  else fprintf(fLogClient,
1827  "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
1828  cModule, cServer, iRC, irawComm);
1829 
1830  iSendEOS = 1;
1831  iError = 1;
1832  goto gClose;
1833  }
1834 
1835  if (iDebug) printf(
1836  " command buffer (action %d) sent to %s (%d byte)\n",
1837  ntohl(pCommServ->iAction), cServer, irawComm);
1838 
1839  continue;
1840 
1841  } /* (iStatus == STA_CACHE_FULL && iAction == 2) */
1842 
1843  fprintf(fLogClient, "-E- %s: received error status from %s",
1844  cModule, cServer);
1845  if (iRC)
1846  printf("\n%s" , cMsg);
1847  else
1848  printf("\n");
1849 
1850  iSendEOS = 1;
1851  iError = 1;
1852  goto gClose;
1853 
1854  } /* (iStatus != STA_SWITCH_SERVER) */
1855 
1856  if (iDebug) printf(
1857  " header of data mover attr received (%d bytes)\n",
1858  iRC);
1859 
1860  /* get data part of data mover info */
1861  pcc = (char *) &(sDataMoverSelect.sDataMoverAttr);
1862  iBufl = sizeof(srawDataMover) - HEAD_LEN;
1863  iBuf = iBufl;
1864  while(iBuf > 0)
1865  {
1866  if ( (iRC = recv( iSockMaster, pcc, (unsigned) iBuf, 0 )) < 0 )
1867  {
1868  fprintf(fLogClient,
1869  "-E- %s: receiving data part of data mover info\n",
1870  cModule);
1871  perror("-E- receiving data part of data mover info");
1872 
1873  iSendEOS = 1; /* may also fail! */
1874  iError = 1;
1875  goto gClose;
1876  }
1877 
1878  if (iRC == 0)
1879  {
1880  ii = iBufl - iBuf;
1881  fprintf(fLogClient,
1882  "-E- %s: connection to sender broken, %d byte of data part of data mover info (%d byte) received\n",
1883  cModule, ii, iBufl);
1884 
1885  iError = 1;
1886  goto gClose;
1887  }
1888 
1889  iBuf -= iRC;
1890  pcc += iRC;
1891  }
1892 
1893  pDataMoverSelect = &(sDataMoverSelect.sDataMoverAttr);
1894  iDataMoverSelect = iBufl / sizeof(srawDataMoverAttr);
1895  /* no. of data movers sent: should be 1 */
1896  strcpy(cNodeMover, pDataMoverSelect->cNode);
1897 
1898  if (iATLServer != (int) ntohl(pDataMoverSelect->iATLServer))
1899  {
1900  if ( (iATLServer <= 0) || (iATLServer > MAX_ATLSERVER) )
1901  fprintf(fLogClient,
1902  "-E- %s: invalid ATL server no. %d received\n",
1903  cModule, iATLServer);
1904  else fprintf(fLogClient,
1905  "-W- %s: unexpected ATL server of selected DM: %d, expected %d\n",
1906  cModule,
1907  ntohl(pDataMoverSelect->iATLServer), iATLServer);
1908 
1909  iATLServer = ntohl(pDataMoverSelect->iATLServer);
1910  pCommAPI->iATLServer = iATLServer;
1911  pCommServ->iATLServer = htonl(iATLServer);
1912  }
1913 
1914  if (iDebug)
1915  {
1916  printf(" data part of data mover info received (%d byte)\n",
1917  iBufl);
1918  printf(" %d data mover selected: %s for ATL server %d\n",
1919  iDataMoverSelect, cNodeMover, iATLServer);
1920  }
1921  else if (iAction == 1) printf(
1922  "-I- staging file to data mover %s (ATL server %d) ...\n",
1924 
1925  } /* while (iDataMoverSelect == 0) */
1926 
1927  if (iDataMoverSelect != 1)
1928  {
1929  fprintf(fLogClient,
1930  "-W- expected 1 selected data mover, ignore remaining %d\n",
1931  --iDataMoverSelect);
1932  iDataMoverSelect = 1;
1933  }
1934  } /* ( ( (iAction == 1) && ((iStage == 0) || (iCache == 1)) ) ||
1935  (iAction == 2) */
1936 
1937 gReceivedDM:
1938  /* update communication buffer with query infos */
1939  pCommServ->iATLServer = htonl(iATLServer);
1940 
1941  if (iAction == 1)
1942  {
1943  pCommServ->iFileType = pQAttr->iFileType; /* is net format */
1944  pCommServ->iBufsizeFile = pQAttr->iBufsizeFile;
1945  pCommServ->iFileSize = pQAttr->iFileSize;
1946  pCommServ->iFileSize2 = pQAttr->iFileSize2;
1947  pCommServ->iObjHigh = pQAttr->iObjHigh;
1948  pCommServ->iObjLow = pQAttr->iObjLow;
1949 
1950  pCommServ->iStageFSid = htonl(0);
1951  pCommServ->iFSidWC = htonl(0);
1952  if (iDebug) printf(" iMediaClass %d, disk FS %d\n",
1953  ntohl(pQAttr->iMediaClass), iStage);
1954  if (iStage)
1955  {
1956  if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_STAGE) ||
1957  (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED) ||
1958  (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE) )
1959  pCommServ->iStageFSid = pQAttr->iFS;
1960  else if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_CACHE) ||
1961  (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED) ||
1962  (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE) )
1963  pCommServ->iFSidWC = pQAttr->iFS;
1964  }
1965  }
1966  else
1967  {
1968  pCommServ->iFileType = htonl(STREAM);
1969  pCommServ->iBufsizeFile = htonl(0);
1970  pCommServ->iFileSize = htonl(0);
1971  pCommServ->iFileSize2 = htonl(0);
1972  pCommServ->iObjHigh = htonl(0);
1973  pCommServ->iObjLow = htonl(0);
1974  pCommServ->iStageFSid = htonl(0);
1975  pCommServ->iFSidWC = htonl(0);
1976  }
1977 
1978  /* provide query infos to other API procedures */
1979  pCommAPI->iATLServer = iATLServer;
1980  pCommAPI->iFileType = ntohl(pCommServ->iFileType);
1981  pCommAPI->iBufsizeFile = ntohl(pCommServ->iBufsizeFile);
1982  pCommAPI->iFileSize = ntohl(pCommServ->iFileSize);
1983  pCommAPI->iFileSize2 = ntohl(pCommServ->iFileSize2);
1984  pCommAPI->iObjHigh = ntohl(pCommServ->iObjHigh);
1985  pCommAPI->iObjLow = ntohl(pCommServ->iObjLow);
1986  pCommAPI->iStageFSid = ntohl(pCommServ->iStageFSid);
1987  pCommAPI->iFSidWC = ntohl(pCommServ->iFSidWC);
1988 
1989  if (iStage)
1990  {
1991  pCommServ->iExecStatus = htonl(0);
1992  pCommAPI->iExecStatus = 0;
1993  }
1994  else
1995  {
1996  pCommServ->iExecStatus = pDataMoverSelect->iExecStatus;
1997  pCommAPI->iExecStatus = ntohl(pDataMoverSelect->iExecStatus);
1998 
1999  pCommServ->iWaitTime = pDataMoverSelect->iWaitTime;
2000  pCommAPI->iWaitTime = ntohl(pDataMoverSelect->iWaitTime);
2001  }
2002 
2003  /********************* connect to data mover *******************/
2004 
2005  if (iOnlyQuery == 0)
2006  {
2007  if (iDebug) printf(
2008  " connecting to data mover %s:%d\n",
2010 
2012  &iMaxConnect, &iSockMover);
2013  if (iRC)
2014  {
2015  fprintf(fLogClient,
2016  "-E- %s: cannot connect to data mover %s:%d (ATL server %d)\n",
2017  cModule, cNodeMover, iPortMover, iATLServer);
2018  iSendEOS = 1;
2019  iError = 1;
2020  goto gClose;
2021  }
2022 
2023  fprintf(fLogClient,
2024  "-I- successfully connected to data mover %s:%d (ATL server %d)",
2026  if (iDebug)
2027  {
2028  if (iMaxConnect)
2029  fprintf(fLogClient, " after %ds", iMaxConnect);
2030  fprintf(fLogClient, " (socket %d)\n", iSockMover);
2031  }
2032  else
2033  fprintf(fLogClient, "\n");
2034 
2035  strcpy(pcurAPIFile->cNodeMover, cNodeMover);
2036  pcurAPIFile->iSockMover = iSockMover;
2037  strcpy(cServer, "data mover");
2038  }
2039 
2040  /******************** close connection to master ***************/
2041 
2042  if (iOnlyQuery)
2043  {
2044  iSendEOS = 1;
2045  goto gClose;
2046  }
2047 
2048  /* as read from data mover in analysis may take a long time!
2049  but keep in case of DAQPool/ArchivePool for further queries */
2050  if ( (iSockMaster >= 0) && (iAction == 1) )
2051  {
2052  if (iDebug)
2053  printf("-D- close connection %d to master\n", iSockMaster);
2054  iRC = shutdown(iSockMaster, 2);
2055  if (iDebug)
2056  printf(" rc shutdown = %d\n", iRC);
2057  iRC = close(iSockMaster);
2058  if (iDebug)
2059  printf(" rc close = %d\n", iRC);
2060 
2061  iSockMaster = -1;
2062  pcurAPIFile->iSockMaster = -1;
2063 
2064  } /* (iSockMaster >= 0 && iAction == 1) */
2065 
2066  } /* (iMassSto) */
2067 
2068  if (iAction == 1)
2069  {
2070  pCommAPI->iAction = RETRIEVE_RECORD;
2071  strcpy(pCommAPI->cNodeRC, cNodeMover);
2072 
2073  if (iCache == 1)
2074  {
2075  /* request file copy from write cache to stage pool */
2076  pCommAPI->iCommLen += irawFileSystem;
2077  pCommAPI->iFSidWC = iStage;
2078  /* pCommAPI->cNodeWC already set */
2079  }
2080  } /* read */
2081  else
2082  {
2083  /* prepare writing of records to server/data mover */
2084  pCommAPI->iAction = ARCHIVE_RECORD;
2085  }
2086 
2087  pCommServ->iAction = htonl(pCommAPI->iAction);
2088  pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
2089 
2090  pCommServ->iPoolIdWC = htonl(pCommAPI->iPoolIdWC);
2091  strcpy(pCommServ->cNodeWC, pCommAPI->cNodeWC);
2092  pCommServ->iFSidWC = htonl(pCommAPI->iFSidWC);
2093 
2094  pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
2095  strcpy(pCommServ->cNodeRC, pCommAPI->cNodeRC);
2096  pCommServ->iStageFSid = htonl(pCommAPI->iStageFSid);
2097 
2098  if (iObjInit)
2099  {
2100 gNextCmdOpen:
2101  if (iDebug)
2102  {
2103  printf(
2104  " send command buffer to %s: id: %d, action %d, data len %d\n",
2105  cServer, pCommAPI->iIdent,
2106  ntohl(pCommServ->iAction),
2107  ntohl(pCommServ->iCommLen));
2108  if (iMassSto)
2109  {
2110  pCommServ->iFileSize = ntohl(pCommServ->iFileSize);
2111  pCommServ->iFileSize2 = ntohl(pCommServ->iFileSize2);
2112  plFileSizeC = (unsigned long *) &(pCommServ->iFileSize);
2113 
2114  printf(" filesize %lu bytes, record size %d",
2115  *plFileSizeC, ntohl(pCommServ->iBufsizeFile));
2116  if (iAction == 1) printf(
2117  ", poolIdRC %d, poolIdWC %d, obj id %d-%d\n",
2118  ntohl(pCommServ->iPoolIdRC), ntohl(pCommServ->iPoolIdWC),
2119  ntohl(pCommServ->iObjHigh), ntohl(pCommServ->iObjLow));
2120  else
2121  printf(", poolId %d\n", ntohl(pCommServ->iPoolIdWC));
2122 
2123  /* reconvert to net format */
2124  pCommServ->iFileSize = htonl(pCommServ->iFileSize);
2125  pCommServ->iFileSize2 = htonl(pCommServ->iFileSize2);
2126  }
2127  }
2128 
2129  pcc = (char *) pCommServ;
2130  if ( (iRC = send(iSockMover, pcc, (unsigned) irawComm, 0 )) < 0 )
2131  {
2132  fprintf(fLogClient, "-E- %s: sending command buffer to %s (rc = %d)\n",
2133  cModule, cServer, iRC);
2134  perror(" ");
2135 
2136  iSendEOS = 1;
2137  iError = 1;
2138  goto gClose;
2139  }
2140 
2141  if (irawComm != iRC)
2142  {
2143  fprintf(fLogClient,
2144  "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
2145  cModule, cServer, iRC, irawComm);
2146 
2147  iSendEOS = 1;
2148  iError = 1;
2149  goto gClose;
2150  }
2151 
2152  if (iDebug) printf(
2153  " command buffer sent to %s (%d byte)\n", cServer, irawComm);
2154 
2155  /* append filesystem buffer */
2156  if (iCache == 1)
2157  {
2158  pcc = (char *) &sFileSystemServ;
2159  iRC = send(iSockMover, pcc, (unsigned) irawFileSystem, 0);
2160  if (irawFileSystem != iRC)
2161  {
2162  if (iRC < 0)
2163  {
2164  fprintf(fLogClient,
2165  "-E- %s: sending filesystem buffer to data mover %s failed\n",
2166  cModule, cNodeMover);
2167  perror(" ");
2168  }
2169  else fprintf(fLogClient,
2170  "-E- %s: incomplete filesystem buffer sent to data mover %s\n",
2171  cModule, cNodeMover);
2172 
2173  iSendEOS = 1;
2174  iError = 1;
2175  goto gClose;
2176  }
2177 
2178  if (iDebug) printf(
2179  " write cache info (%d bytes) sent to data mover %s\n",
2180  irawFileSystem, cNodeMover);
2181 
2182  } /* (iCache == 1) */
2183 
2184  /************* look for reply from server/data mover ***********/
2185 
2186  pcc = (char *) &sStatus;
2187  iStatusOkay = 0;
2188  iStatusLoop = 0;
2189  while (iStatusOkay == 0)
2190  {
2191  iStatusLoop++;
2192 
2193  memset(&sStatus, 0X00, sizeof(srawStatus));
2194  iRC = rawRecvStatus(iSockMover, pcc);
2195  iStatus = sStatus.iStatus;
2196  if (iRC != HEAD_LEN)
2197  {
2198  if (iRC < HEAD_LEN)
2199  {
2200  fprintf(fLogClient, "-E- %s: receiving status buffer from %s",
2201  cModule, cServer);
2202  if (iRC > 0)
2203  fprintf(fLogClient, ": (%d byte)\n", iRC);
2204  else
2205  fprintf(fLogClient, "\n");
2206  }
2207  else /* received error message */
2208  {
2209  if ( (iStatus == STA_CACHE_FULL) && (iAction == 2) )
2210  {
2211  if ( (iStatusLoop < iStatusLoopMax) &&
2212  (iMassSto != 2) ) /* no delay for DAQPool */
2213  {
2214  fprintf(fLogClient,
2215  "-W- %s: write cache currently full (create) ... sleep %d s (%d of %d)\n",
2216  cModule, iSleepCacheFull,
2217  iStatusLoop, iStatusLoopMax);
2218  continue;
2219  }
2220  else
2221  {
2222  fprintf(fLogClient,
2223  "-W- %s: write cache currently full: archive to tape\n",
2224  cModule);
2225  pCommAPI->iAction = ARCHIVE_RECORD;
2226  pCommAPI->iArchDev = ARCH_TAPE;
2227  pCommServ->iAction = htonl(pCommAPI->iAction);
2228  pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
2229 
2230  goto gNextCmdOpen;
2231  }
2232  } /* (iStatus == STA_CACHE_FULL && iAction == 2) */
2233  else if ( (iStatus == STA_SWITCH_SERVER) &&
2234  (iAction == 2) )
2235  {
2236  strcpy(cNodeMover, sStatus.cStatus);
2237 
2238  fprintf(fLogClient,
2239  "-W- write cache on DM %s full, switch to %s\n",
2240  pcurAPIFile->cNodeMover, cNodeMover);
2241 
2242  if (iDebug) printf(
2243  " close connection %d to data mover %s\n",
2244  iSockMover, pcurAPIFile->cNodeMover);
2245  iRC = shutdown(iSockMover, 2);
2246  if (iDebug)
2247  printf(" rc shutdown = %d\n", iRC);
2248  iRC = close(iSockMover);
2249  if (iDebug)
2250  printf(" rc close = %d\n", iRC);
2251 
2252  /************* connect to new data mover ***********/
2253 
2254  if (iDebug) printf(
2255  " connecting to data mover %s:%d\n",
2257 
2259  &iMaxConnect, &iSockMover);
2260  if (iRC)
2261  {
2262  fprintf(fLogClient,
2263  "-E- %s: cannot connect to new data mover %s:%d (ATL server %d)\n",
2264  cModule, cNodeMover, iPortMover, iATLServer);
2265  iError = -2;
2266  }
2267 
2268  fprintf(fLogClient,
2269  "-I- successfully connected to new data mover %s:%d (ATL server %d)",
2271  if (iMaxConnect)
2272  fprintf(fLogClient, " after %ds", iMaxConnect);
2273  if (iDebug)
2274  printf(" (socket %d)\n", iSockMover);
2275  else
2276  fprintf(fLogClient, "\n");
2277 
2278  strcpy(pcurAPIFile->cNodeMover, cNodeMover);
2279  pcurAPIFile->iSockMover = iSockMover;
2280 
2281  goto gNextCmdOpen;
2282 
2283  } /* (iStatus == STA_SWITCH_SERVER && iAction == 2) */
2284  else
2285  {
2286  fprintf(fLogClient, "-E- %s: message received from %s:\n",
2287  cModule, cServer);
2288  fprintf(fLogClient, " %s\n", sStatus.cStatus);
2289  iError = 2;
2290  }
2291  } /* (iRC >= HEAD_LEN) */
2292 
2293  iSendEOS = 1;
2294  goto gClose;
2295  }
2296 
2297  iStatusOkay = 1;
2298 
2299  } /* while (iStatusOkay == 0) */
2300 
2301  if (iDebug)
2302  {
2303  printf(" status (%d) received from %s (%d bytes",
2304  iStatus, cServer, iRC);
2305  if (iStatusLoop > 1)
2306  printf(", iter %d)\n", iStatusLoop);
2307  else
2308  printf(")\n");
2309  }
2310  } /* (iObjInit) */
2311 
2312  iError = 0;
2313 
2314 gClose:
2315  if ( (iSockMaster >= 0) &&
2316  ((iAction == 1) || (iError)) )
2317  {
2318  /* stop master server process in case of read cache or error */
2319  if (iSendEOS)
2320  {
2321  iStatus = STA_END_OF_SESSION;
2322  iRC = rawSendStatus(iSockMaster, iStatus, NULL);
2323  if (iRC <= 0) fprintf(fLogClient,
2324  "-E- %s: sending status buffer to entry server (EOS)\n", cModule);
2325  else if (iDebug) printf(
2326  " status buffer (EOS) sent to entry server (%d bytes)\n", iRC);
2327  }
2328 
2329  if (iDebug)
2330  printf(" close connection %d to entry server\n", iSockMaster);
2331  iRC = shutdown(iSockMaster, 2);
2332  if (iDebug)
2333  printf(" irc shutdown = %d\n", iRC);
2334  iRC = close(iSockMaster);
2335  if (iDebug)
2336  printf(" irc close = %d\n", iRC);
2337 
2338  } /* (iSockMaster >= 0 && iAction == 1) */
2339 
2340  if (iError)
2341  {
2342 gError:
2343  if (iSockMover >= 0)
2344  {
2345  if (iSendEOS)
2346  {
2347  /* stop server/data mover process */
2348  iStatus = STA_END_OF_SESSION;
2349  iRC = rawSendStatus(iSockMover, iStatus, NULL);
2350  if (iRC <= 0) fprintf(fLogClient,
2351  "-E- %s: sending status buffer (EOS) to %s\n", cModule, cServer);
2352  else if (iDebug) printf(
2353  " status buffer (EOS) sent to %s (%d bytes)\n",
2354  cServer, iRC);
2355  }
2356 
2357  if (iDebug) printf(
2358  " close connection %d to %s\n", iSockMover, cServer);
2359  iRC = shutdown(iSockMover, 2);
2360  if (iDebug)
2361  printf(" rc shutdown = %d\n", iRC);
2362  iRC = close(iSockMover);
2363  if (iDebug)
2364  printf(" rc close = %d\n", iRC);
2365  }
2366 
2367  if (iFileId >= 0)
2368  {
2369  free(pAPIFile[iFileId]);
2370  pAPIFile[iFileId] = NULL;
2371  iFileCount--;
2372  }
2373 
2374  } /* (iError) */
2375 
2376  if (iDebug)
2377  printf("-D- end %s\n\n", cModule);
2378 
2379  if (iError)
2380  return -1;
2381  else
2382  return iFileId;
2383 
2384 } /* rfio_open_gsidaq */
2385 
2386 /********************************************************************
2387  * rfio_endfile:
2388  * close remote file in GSI mass storage,
2389  * but keep connection to mass storage data mover
2390  *
2391  * created 16. 7.2004, Horst Goeringer
2392  ********************************************************************
2393  */
2394 
2395 int rfio_endfile(int iFileId) /* file id */
2396 {
2397  char cModule[32] = "rfio_endfile";
2398  int iDebug = 0;
2399  int iRC = 0;
2400  int iSockMover; /* socket for connection to mover */
2401  int iStatus = STA_END_OF_SESSION;
2402  int ii = 0;
2403 
2404  char cServer[16] = "data mover";
2405  char *pcc;
2406 
2407  srawStatus sStatus;
2408  srawAPIFile *pcurAPIFile;
2409  srawComm *pCommAPI; /* communication buffer in API control block */
2410  srawComm *pCommServ; /* copy for servers in net format */
2411  srawCopyCache *pCopyCacheServ;
2412  /* infos in net format for copy of WC data */
2413 
2414  if (iDebug) printf(
2415  "\n-D- begin %s: close remote file %d\n", cModule, iFileId);
2416  fflush(stdout);
2417 
2418  if (iFileCount == 0)
2419  {
2420  fprintf(fLogClient,
2421  "-E- %s: no remote file available for close\n", cModule);
2422  return -1;
2423  }
2424 
2425  while (ii < iFileMax)
2426  {
2427  if (pAPIFile[ii])
2428  {
2429  if (pAPIFile[ii]->iFileId == iFileId)
2430  break;
2431  }
2432  ii++;
2433  }
2434 
2435  if (ii == iFileMax)
2436  {
2437  fprintf(fLogClient, "-E- %s: remote file %d cannot be closed: not found\n",
2438  cModule, iFileId);
2439  return -1;
2440  }
2441 
2442  pcurAPIFile = pAPIFile[iFileId];
2443  pCommAPI = &(pcurAPIFile->sCommAPI);
2444  pCommServ = &(pcurAPIFile->sCommServ);
2445  pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
2446 
2447  pcurAPIFile->iBufnoServ = 0; /* RESET */
2448  iSockMover = pcurAPIFile->iSockMover;
2449  if (iSockMover >= 0)
2450  {
2451  /* stop data mover process */
2452  iStatus = STA_END_OF_FILE;
2453  iRC = rawSendStatus(iSockMover, iStatus, NULL);
2454  if (iRC <= 0)
2455  fprintf(fLogClient, "-E- %s: sending status buffer (EOF) to %s\n",
2456  cModule, cServer);
2457  else if (iDebug) printf(
2458  " status buffer (EOF) sent to %s (%d bytes)\n",
2459  cServer, iRC);
2460 
2461  memset(&sStatus, 0X00, sizeof(srawStatus));
2462  pcc = (char *) &sStatus;
2463  iRC = rawRecvStatus(iSockMover, pcc);
2464  if (iRC < HEAD_LEN)
2465  {
2466  fprintf(fLogClient, "-E- %s: receiving status buffer\n", cModule);
2467  iRC = -1;
2468  goto gErrorEndFile;
2469  }
2470 
2471  iStatus = sStatus.iStatus;
2472  if (iDebug) printf(
2473  " status buffer (%d) received (%d byte)\n",
2474  iStatus, iRC);
2475 
2476  if (iRC > HEAD_LEN)
2477  {
2478  if (iStatus == STA_CACHE_COPY)
2479  fprintf(fLogClient, sStatus.cStatus);
2480  else
2481  {
2482  fprintf(fLogClient,
2483  "-W- %s: message received from server:\n", cModule);
2484  fprintf(fLogClient, sStatus.cStatus);
2485 
2486  if (iStatus != STA_CACHE_COPY_ERROR)
2487  {
2488  iRC = -1;
2489  goto gErrorEndFile;
2490  }
2491  }
2492  } /* (iRC > HEAD_LEN) */
2493 
2494  if (pcurAPIFile->iMassSto)
2495  {
2496  if ( (pcurAPIFile->iOpMode != 2) && /* no display mode */
2497  (iDebug) )
2498  fprintf(fLogClient,
2499  "-I- gStore file %s%s%s closed\n",
2500  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
2501  }
2502  else fprintf(fLogClient,
2503  "-I- remote output file %s%s%s closed\n",
2504  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
2505 
2506  } /* (iSockMover >= 0) */
2507 
2508  if (iDebug)
2509  {
2510  printf(
2511  " remote file control block %d still active (overall %d)\n",
2512  iFileId, iFileCount);
2513  printf("-D- end %s\n\n", cModule);
2514  }
2515 
2516  iRC = 0;
2517 
2518 gErrorEndFile:
2519  return iRC;
2520 
2521 } /* rfio_endfile */
2522 
2523 /*********************************************************************
2524  * rfio_read: read remote file in GSI mass storage
2525  *
2526  * created 4.12.2000, Horst Goeringer
2527  *********************************************************************
2528  */
2529 
2530 ssize_t rfio_read(int iFileId, /* file id */
2531  char *pcBuffer, /* data buffer */
2532  size_t iItems) /* number of data bytes */
2533 {
2534  char cModule[32] = "rfio_read";
2535  int iDebug = 0;
2536  int iRC;
2537 
2538  int iSockMover; /* socket for connection to mover */
2539  int iSeekMode;
2540  int iOffset;
2541  int iBufsizeRead;
2542  int iBufnoServ; /* no. of buffers transfered from/to server */
2543  int iDataServ; /* no. of bytes transfered from/to server */
2544 
2545  int iStatus;
2546  int iStatusLen;
2547  int iBufsizeRecv;
2548 
2549  char *pcc;
2550  int ii = 0;
2551  int iBuf, iBufl;
2552  int *pint;
2553 
2554  srawAPIFile *pcurAPIFile;
2555  srawComm *pCommAPI; /* communication buffer in API control block */
2556  srawComm *pCommServ; /* copy for servers in net format */
2557 
2558  if (iDebug)
2559  printf("\n-D- begin %s: fileId %d\n", cModule, iFileId);
2560 
2561  if (iFileCount == 0)
2562  {
2563  fprintf(fLogClient, "-E- %s: no remote file open for read\n", cModule);
2564  return -1;
2565  }
2566 
2567  while (ii < iFileMax)
2568  {
2569  if (pAPIFile[ii])
2570  {
2571  if (pAPIFile[ii]->iFileId == iFileId)
2572  break;
2573  }
2574  ii++;
2575  }
2576 
2577  if (ii == iFileMax)
2578  {
2579  fprintf(fLogClient, "-E- %s: remote file %d cannot be read: not opened\n",
2580  cModule, iFileId);
2581  return -1;
2582  }
2583 
2584  if (iDebug)
2585  printf(" open buffer %d, fileId %d\n", ii, iFileId);
2586 
2587  pcurAPIFile = pAPIFile[iFileId];
2588  pCommAPI = &(pcurAPIFile->sCommAPI);
2589  pCommServ = &(pcurAPIFile->sCommServ);
2590 
2591  iBufnoServ = pcurAPIFile->iBufnoServ;
2592  iDataServ = pcurAPIFile->iDataServ;
2593 
2594  iBufnoServ++;
2595  if (iDebug)
2596  {
2597  printf(" remote file control block %d selected\n", ii);
2598  printf(" file %d, buffer %d: read %d bytes\n",
2599  iFileId, iBufnoServ, iItems);
2600  }
2601 
2602  iBufsizeRead = pcurAPIFile->iBufsizeAct;
2603  if (iDebug)
2604  {
2605  if (iBufsizeRead != iItems)
2606  printf( " new buffer size %d\n", iItems);
2607  printf(" send request for new buffer\n");
2608  }
2609 
2610  iSockMover = pcurAPIFile->iSockMover;
2611  iSeekMode = pcurAPIFile->iSeekMode;
2612  iOffset = pcurAPIFile->iOffset;
2613  iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, (signed) iItems);
2614  if (iRC != 0)
2615  {
2616  fprintf(fLogClient, "-E- %s: sending request for next data buffer\n",
2617  cModule);
2618  return -1;
2619  }
2620 
2621  /* reset seek options to default (no seek) */
2622  if (iSeekMode != -1)
2623  {
2624  pcurAPIFile->iSeekMode = -1;
2625  pcurAPIFile->iOffset = 0;
2626  }
2627 
2628  pcurAPIFile->iBufsizeAct = (int) iItems; /* keep current value */
2629 
2630  /********************** retrieve next buffer **********************/
2631 
2632  /* get size retrieve buffer */
2633  pcc = (char *) &iBufsizeRecv;
2634  iBuf = iint;
2635  while(iBuf > 0)
2636  {
2637 gRetryLen:
2638  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2639  {
2640  fprintf(fLogClient,
2641  "-E- %s: receiving data length from server (buffer %d)",
2642  cModule, iBufnoServ);
2643  perror("");
2644  goto gRetryLen;
2645  }
2646 
2647  if (iRC == 0)
2648  {
2649  ii = iint - iBuf;
2650  fprintf(fLogClient,
2651  "-E- %s: connection to sender broken, %d byte of data length (%d byte) received (buffer %d)\n",
2652  cModule, ii, iint, iBufnoServ);
2653 
2654  return -1;
2655  }
2656 
2657  iBuf -= iRC;
2658  pcc += iRC;
2659 
2660  if (iDebug == 2)
2661  {
2662  printf("%d.", iRC);
2663  fflush(stdout);
2664  }
2665  } /* recv loop data length */
2666 
2667  iBufsizeRecv = ntohl(iBufsizeRecv);
2668  if (iDebug == 2)
2669  printf("%d_", iBufsizeRecv);
2670 
2671  if (iBufsizeRecv < 0)
2672  {
2673  if (iBufsizeRecv != IDENT_STATUS)
2674  {
2675  fprintf(fLogClient, "-E- %s: invalid status header received (%d)\n",
2676  cModule, iBufsizeRecv);
2677  return -1;
2678  }
2679  if (iDebug)
2680  printf("-D- status header found\n");
2681 
2682  /* receive remainder of status header */
2683  pcc = pcBuffer;
2684  iBuf = HEAD_LEN - 4; /* iIdent already read */
2685  iBufl = iBuf;
2686  while(iBuf > 0) /* get remainder of status header */
2687  {
2688  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2689  {
2690  fprintf(fLogClient,
2691  "-E- %s: receiving remainder of status header from server (buffer %d)",
2692  cModule, iBufnoServ);
2693  perror(" ");
2694 
2695  return -1;
2696  }
2697 
2698  if (iRC == 0)
2699  {
2700  ii = iBufl - iBuf;
2701  fprintf(fLogClient,
2702  "-W- %s: connection to sender broken, %d byte of remainder of status header (%d byte) received (buffer %d)\n",
2703  cModule, ii, iBufl, iBufnoServ);
2704 
2705  return -1;
2706  }
2707 
2708  if (iDebug == 2)
2709  printf("%d.", iRC);
2710 
2711  iBuf -= iRC;
2712  pcc += iRC;
2713  }
2714 
2715  pint = (int *) pcBuffer; /* points to status word */
2716  iStatus = ntohl(*pint); /* status received */
2717  if ( (iStatus != STA_END_OF_FILE) &&
2718  (iStatus != STA_END_OF_SESSION) &&
2719  (iStatus != STA_ERROR) &&
2720  (iStatus != STA_ERROR_EOF) )
2721  {
2722  fprintf(fLogClient, "-E- %s: unexpected status from server: %d\n",
2723  cModule, iStatus);
2724  return -1;
2725  }
2726 
2727  if ( (iStatus == STA_END_OF_FILE) ||
2728  (iStatus == STA_END_OF_SESSION) )
2729  {
2730  if (iDebug) printf(" EOF on input\n");
2731 
2732  if (iDataServ == 0) /* empty file */
2733  {
2734  fprintf(fLogClient, "-E- %s: %s%s%s empty\n",
2735  cModule, pCommServ->cNamefs,
2736  pCommServ->cNamehl, pCommServ->cNamell);
2737  return -1;
2738  }
2739  else return 0;
2740  }
2741  else
2742  {
2743  pint++; /* points to status size */
2744  iStatusLen = ntohl(*pint);
2745  if (iStatusLen > 0)
2746  {
2747  iRC = rawRecvError(iSockMover, iStatusLen, pcc);
2748  if (iRC < 0)
2749  {
2750  fprintf(fLogClient,
2751  "-E- %s: receiving status message from server, rc = %d\n",
2752  cModule, iRC);
2753  return -1;
2754  }
2755 
2756  if ( (iStatus == STA_ERROR) ||
2757  (iStatus == STA_ERROR_EOF) )
2758  {
2759  fprintf(fLogClient,
2760  "-E- %s: received error status from server:\n",
2761  cModule);
2762  fprintf(fLogClient, "%s\n", pcc);
2763  return -1;
2764  }
2765 
2766  /* warning from server */
2767  printf("%s\n", pcc);
2768 
2769  } /* (iStatusLen > 0) */
2770  } /* (iStatus != STA_END_OF_FILE) &&
2771  (iStatus != STA_END_OF_SESSION) */
2772  } /* (iBufsizeRecv < 0) */
2773  else if (iBufsizeRecv != iItems)
2774  {
2775  if (iDebug)
2776  {
2777  if (iBufsizeRecv) printf(
2778  "-W- requested %d bytes, received buffer length %d bytes\n",
2779  iItems, iBufsizeRecv);
2780  else printf("-W- EOF reached\n");
2781  }
2782  iItems = (size_t) iBufsizeRecv;
2783  }
2784 
2785  /* recv loop over buffers of size iBufsizeRecv */
2786  iBuf = iBufsizeRecv;
2787  pcc = pcBuffer;
2788  while(iBuf > 0)
2789  {
2790 gRetryData:
2791  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2792  {
2793  if (iDebug) fprintf(fLogClient,
2794  "-E- %s: receiving data from server (buffer %d)\n",
2795  cModule, iBufnoServ);
2796  perror("EEE ");
2797  goto gRetryData;
2798  }
2799 
2800  if (iRC == 0)
2801  {
2802  ii = iBufsizeRecv - iBuf;
2803  fprintf(fLogClient,
2804  "-W- %s: connection to sender broken, %d byte of data buffer (%d byte) received (buffer %d)\n",
2805  cModule, ii, iBufsizeRecv, iBufnoServ);
2806 
2807  return -1;
2808  }
2809 
2810  if (iDebug == 2)
2811  {
2812  printf("%d:", iRC);
2813  fflush(stdout);
2814  }
2815 
2816  iBuf -= iRC;
2817  pcc += iRC;
2818  pcurAPIFile->iDataServ += iRC;
2819 
2820  } /* while(iBuf > 0) */
2821 
2822  if (iBufsizeRecv)
2823  {
2824  pcurAPIFile->iBufnoServ++;
2825  if (iDebug == 2)
2826  printf(" buffer %d received\n", pcurAPIFile->iBufnoServ);
2827  }
2828 
2829  if (iDebug)
2830  printf("-D- end %s\n\n", cModule);
2831 
2832  return iBufsizeRecv;
2833 
2834 } /* rfio_read */
2835 
2836 /*********************************************************************
2837  * rfio_write: write remote file in GSI mass storage
2838  *
2839  * created 4.12.2000, Horst Goeringer
2840  *********************************************************************
2841  */
2842 
2843 ssize_t rfio_write(int iFileId, /* file id */
2844  const char *pcBuffer, /* data buffer */
2845  size_t iItems) /* number of data bytes */
2846 {
2847  char cModule[32] = "rfio_write";
2848  int iDebug = 0;
2849 
2850  int iRC;
2851  char *pcc;
2852  int ii = 0;
2853  int iBuf;
2854 
2855  int iSockMover; /* socket for connection to mover */
2856  int iBufsizeWrite;
2857  int iBufnoServ; /* no. of buffers transfered from/to server */
2858 
2859  srawAPIFile *pcurAPIFile;
2860 
2861  srawComm *pCommAPI;
2862  srawComm *pCommServ; /* copy for servers in net format */
2863 
2864  if (iDebug)
2865  {
2866  printf("\n-D- begin %s\n", cModule);
2867  fflush(stdout);
2868  }
2869 
2870  if (iItems <= 0)
2871  {
2872  fprintf(fLogClient,
2873  "-W- invalid no. of bytes to write: %d\n", iItems);
2874  return 0;
2875  }
2876 
2877  if (iFileCount == 0)
2878  {
2879  fprintf(fLogClient, "-E- %s: no remote file open for write\n", cModule);
2880  return -1;
2881  }
2882 
2883  ii = 0;
2884  while (ii < iFileMax)
2885  {
2886  if (pAPIFile[ii])
2887  {
2888  if (pAPIFile[ii]->iFileId == iFileId)
2889  break;
2890  }
2891  ii++;
2892  }
2893 
2894  if (ii == iFileMax)
2895  {
2896  fprintf(fLogClient,
2897  "-E- %s: remote file %d cannot be written: not opened\n",
2898  cModule, iFileId);
2899  return -1;
2900  }
2901 
2902  pcurAPIFile = pAPIFile[iFileId];
2903  pCommServ = &(pcurAPIFile->sCommServ);
2904  pCommAPI = &(pcurAPIFile->sCommAPI);
2905 
2906  iBufnoServ = pcurAPIFile->iBufnoServ;
2907  iBufnoServ++;
2908 
2909  if (iDebug)
2910  {
2911  printf(" remote file control block %d selected\n", ii);
2912  printf(" file %d, buffer %d: write %d bytes\n",
2913  iFileId, iBufnoServ, iItems);
2914  }
2915 
2916  if (iItems > pCommAPI->iBufsizeFile)
2917  {
2918  pCommAPI->iBufsizeFile = (int) iItems;
2919  pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
2920  }
2921 
2922  if (iDebug)
2923  {
2924  if (pcurAPIFile->iBufsizeAct != iItems)
2925  printf( " new buffer size %d\n", iItems);
2926  printf(" send new buffer\n");
2927  }
2928 
2929 
2930  /*********************** write next buffer ************************/
2931 
2932  iSockMover = pcurAPIFile->iSockMover;
2933  pcurAPIFile->iBufsizeAct = (int) iItems; /* keep current value */
2934  iBufsizeWrite = htonl( (int) iItems);
2935  iBuf = iint;
2936  pcc = (char *) &iBufsizeWrite;
2937  while (iBuf)
2938  {
2939  iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
2940  if (iRC <= 0)
2941  {
2942  if (iRC == 0) fprintf(fLogClient,
2943  "-E- %s: sending data length to server broken\n", cModule);
2944  else
2945  {
2946  fprintf(fLogClient,
2947  "-E- %s: sending data length to server (buffer %d)",
2948  cModule, iBufnoServ);
2949  perror(" ");
2950  }
2951  return -1;
2952  }
2953 
2954  iBuf -= iRC;
2955  pcc += iRC;
2956 
2957  if (iDebug == 2)
2958  {
2959  printf("%d(%d)_", iRC, iItems);
2960  fflush(stdout);
2961  }
2962 
2963  } /* while (iBuf) */
2964 
2965  iBuf = (int) iItems;
2966  pcc = (char *) pcBuffer;
2967  while (iBuf)
2968  {
2969  iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
2970  if (iRC <= 0)
2971  {
2972  if (iRC == 0) fprintf(fLogClient,
2973  "-E- %s: sending data to server broken\n", cModule);
2974  else
2975  {
2976  fprintf(fLogClient,
2977  "-E- %s: sending data to server (buffer %d, %d bytes)",
2978  cModule, iBufnoServ, iBuf);
2979  perror(" ");
2980  }
2981  return -1;
2982  }
2983 
2984  iBuf -= iRC;
2985  pcc += iRC;
2986  pcurAPIFile->iDataServ += iRC;
2987 
2988  if (iDebug == 2)
2989  {
2990  printf("%d.", iRC);
2991  fflush(stdout);
2992  }
2993 
2994  } /* while (iBuf) */
2995 
2996  if (iItems)
2997  {
2998  pcurAPIFile->iBufnoServ++;
2999  if (iDebug == 2)
3000  printf(" buffer %d sent\n", pcurAPIFile->iBufnoServ);
3001  }
3002 
3003  if (iDebug)
3004  printf("-D- end %s\n", cModule);
3005 
3006  return (ssize_t) iItems;
3007 
3008 } /* rfio_write */
3009 
3010 /*********************************************************************
3011  * rfio_newfile: continue with next remote file in GSI mass storage
3012  *
3013  * created 2. 8.2004, Horst Goeringer
3014  *********************************************************************
3015  */
3016 
3017 int rfio_newfile(int iFileId,
3018  char *pcFile) /* file name */
3019 {
3020  char cModule[32] = "rfio_newfile";
3021  int iDebug = 0;
3022  int iRC;
3023  int ii = 0;
3024  int iArchLen = 0;
3025  int iPathLen = 0;
3026  int iFileLen = 0;
3027  int iCopyMode = 0; /* >0: write data to WC and dataFS */
3028  int iCopyLen = 0; /* >0: copy parameters already sent to DM */
3029  int iCopyBuffer = 0; /* >0: send copy parameters now to DM */
3030 
3031  int iMassSto = -1;/* =1: connect to GSI mass storage (ArchivePool)
3032  =2: connect to GSI mass storage (DAQPool)
3033  =0: connect to RFIO read/write server */
3034  int iMaxConnect = 0; /* try connection to servers once */
3035  int iSockMover; /* socket for connection to mover */
3036  char cNodeMover[MAX_NODE] = "";
3037  int inewPath = 0;
3038  int iError = 0;
3039  int iStatus = 0;
3040  int iStatusOkay = 0;
3041  int iStatusLoop = 0;
3042 
3043  char *pcc, *pcc1, *pcc2;
3044  char cTemp[STATUS_LEN] = "";
3045 
3046  char cNamefs[MAX_OBJ_FS] = "", *pcNamefs; /* filespace name */
3047  char cNamehl[MAX_OBJ_HL] = "", *pcNamehl; /* high level name */
3048  char cNamell[MAX_OBJ_LL] = "", *pcNamell; /* low level name */
3049 
3050  srawStatus sStatus;
3051  void *pBufQuery;
3052  srawQueryResult sQuery;
3053  srawObjAttr *pQAttr;
3054 
3055  srawAPIFile *pcurAPIFile;
3056  srawComm *pCommAPI; /* communication buffer in API control block */
3057  srawComm *pCommServ; /* copy for servers in net format */
3058  srawCopyCache *pCopyCacheServ;
3059  /* infos in net format for copy of WC data */
3060 
3061  pcNamefs = cNamefs;
3062  pcNamehl = cNamehl;
3063  pcNamell = cNamell;
3064 
3065  if (iDebug)
3066  printf("\n-D- begin %s\n", cModule);
3067 
3068  if (iFileCount == 0)
3069  {
3070  fprintf(fLogClient,
3071  "-E- %s: no open connection to server existing\n", cModule);
3072  iError = -1;
3073  goto gEndNewFile;
3074  }
3075 
3076  ii = 0;
3077  while (ii < iFileMax)
3078  {
3079  if (pAPIFile[ii])
3080  {
3081  if (pAPIFile[ii]->iFileId == iFileId)
3082  break;
3083  }
3084  ii++;
3085  }
3086 
3087  if (ii == iFileMax)
3088  {
3089  fprintf(fLogClient, "-E- %s: no open connection to server\n", cModule);
3090  iError = -1;
3091  goto gEndNewFile;
3092  }
3093 
3094  if (iDebug)
3095  printf(" requested API control block %d\n", iFileId);
3096 
3097  pcurAPIFile = pAPIFile[iFileId];
3098  pCommAPI = &(pcurAPIFile->sCommAPI);
3099  pCommServ = &(pcurAPIFile->sCommServ);
3100  pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
3101 
3102  if ( (pcurAPIFile->iAction == 1) ||
3103  (pCommAPI->iAction == QUERY_RETRIEVE_RECORD) ||
3104  (pCommAPI->iAction == RETRIEVE_RECORD) )
3105  {
3106  fprintf(fLogClient, "-E- %s for read not supported\n", cModule);
3107  iError = -1;
3108  goto gEndNewFile;
3109  }
3110  else if (pcurAPIFile->iAction == 2)
3111  {
3112  if (iDebug)
3113  printf(" connection is open for write\n");
3114  }
3115  else
3116  {
3117  fprintf(fLogClient, "-E- %s: connection is open for unexpected action %d\n",
3118  cModule, pcurAPIFile->iAction);
3119  iError = -1;
3120  goto gEndNewFile;
3121  }
3122 
3123  if (iDebug)
3124  printf(" check name parts in %s\n", pcFile);
3125 
3126  pcc1 = (char *) strrchr(pcFile, *pcDevDelim);
3127  if (pcc1 == NULL)
3128  {
3129  fprintf(fLogClient,
3130  "-E- %s: invalid remote file name %s: node name missing\n",
3131  cModule, pcFile);
3132  iError = -1;
3133  goto gEndNewFile;
3134  }
3135 
3136  strcpy(cTemp, pcFile); /* local copy of new remote file name */
3137  pcc = (char *) strchr(pcFile, *pcObjDelim);
3138  if (pcc == NULL)
3139  {
3140  fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
3141  cModule, pcFile);
3142  iError = -1;
3143  goto gEndNewFile;
3144  }
3145 
3146  ii = pcc1 - pcc;
3147  if (ii < 0)
3148  ii = -ii;
3149  if (ii != 1)
3150  {
3151  fprintf(fLogClient,
3152  "-E- %s: invalid remote file name %s - possibly leading '/' in archive name missing\n",
3153  cModule, pcFile);
3154  iError = -1;
3155  goto gEndNewFile;
3156  }
3157 
3158  if (strncmp(cTemp, "rfiocopy:", 9) == 0)
3159  {
3160  iMassSto = 0;
3161  if (iDebug)
3162  printf(" copy via RFIO server\n");
3163  }
3164  else if (strncmp(cTemp, "rfiodaq:", 8) == 0)
3165  {
3166  iMassSto = 2;
3167  if (iDebug)
3168  printf(" copy to mass storage (DAQPool)\n");
3169  }
3170  else if (strncmp(cTemp, "rfio:", 5) == 0)
3171  {
3172  iMassSto = 1;
3173  if (iDebug)
3174  printf(" copy to mass storage (ArchivePool)\n");
3175  }
3176  else /* assume node:object */
3177  {
3178  iMassSto = 1;
3179  if (iDebug)
3180  printf(" copy to mass storage (ArchivePool)\n");
3181  }
3182 
3183  if (pcurAPIFile->iMassSto != iMassSto)
3184  {
3185  fprintf(fLogClient,
3186  "-E- %s: remote file %s incompatible with open server connection\n",
3187  cModule, pcFile);
3188  iError = -1;
3189  goto gEndNewFile;
3190  }
3191 
3192  if (iDebug) printf(
3193  " requested server consistent with open connection (%d)\n",
3194  iMassSto);
3195 
3196  /* pcc points now to 1st '/' */
3197  if (iMassSto)
3198  {
3199  if (strlen(pcc) > MAX_OBJ_FS - 1)
3200  strncpy(pcNamefs, pcc, MAX_OBJ_FS-1);
3201  else
3202  strcpy(pcNamefs, pcc);
3203 
3204  pcc = pcNamefs;
3205  pcc++;
3206  pcc1 = (char *) strchr(pcc, *pcObjDelim);
3207  if (pcc1 == NULL)
3208  {
3209  ii = MAX_OBJ_FS-1;
3210  if (iDebug) printf(
3211  "-E- archive name starting with %s too long, max allowed %d chars\n",
3212  pcNamefs, ii);
3213  fprintf(fLogClient,
3214  "-E- %s: archive name starting with %s too long, max allowed %d chars\n",
3215  cModule, pcNamefs, ii);
3216  iError = -1;
3217  goto gEndNewFile;
3218  }
3219 
3220  strncpy(pcc1, "\0", 1); /* terminates archive name */
3221  if (strlen(pCommServ->cNamefs))
3222  {
3223  if (strcmp(pCommServ->cNamefs, pcNamefs))
3224  {
3225  fprintf(fLogClient,
3226  "-E- %s: invalid archive name %s, expected %s\n",
3227  cModule, pcNamefs, pCommServ->cNamefs);
3228  iError = -1;
3229  goto gEndNewFile;
3230  }
3231  }
3232 
3233  strcpy(pCommServ->cNamefs, pcNamefs);
3234  iArchLen = strlen(pcNamefs);
3235 
3236  if (iDebug) printf(
3237  " archive name: %s (len %d chars)\n", pcNamefs, iArchLen);
3238 
3239  if (iArchLen <= 3)
3240  {
3241  fprintf(fLogClient,
3242  "-E- %s: invalid archive name '%s'\n", cModule, pcNamefs);
3243  iError = -1;
3244  goto gEndNewFile;
3245  }
3246 
3247  pcc = (char *) strchr(cTemp, *pcObjDelim); /* full name */
3248  pcc++; /* skip '/' in archive name */
3249  pcc2 = (char *) strchr(pcc, *pcObjDelim);
3250  if (pcc2 == NULL)
3251  {
3252  fprintf(fLogClient,
3253  "-E- %s: invalid remote file name %s: missing path name\n",
3254  cModule, pcFile);
3255  iError = -1;
3256  goto gEndNewFile;
3257  }
3258 
3259  if (iDebug)
3260  printf(" path + file name: %s\n", pcc2);
3261 
3262  pcc = pcc2;
3263  pcc++; /* skip 1st '/' in path name */
3264  pcc1 = (char *) strrchr(pcc, *pcObjDelim);
3265  if (pcc1 == NULL)
3266  {
3267  fprintf(fLogClient,
3268  "-E- %s: invalid remote file name %s: missing file name\n",
3269  cModule, pcFile);
3270  iError = -1;
3271  goto gEndNewFile;
3272  }
3273 
3274  if (iDebug)
3275  printf(" file name: %s\n", pcc1);
3276 
3277  iPathLen = pcc2-pcc1;
3278  if (iPathLen < 0)
3279  iPathLen = -iPathLen;
3280  if (iDebug)
3281  printf(" length path name: %d\n", iPathLen);
3282 
3283  if (iPathLen >= MAX_OBJ_HL)
3284  {
3285  ii = MAX_OBJ_HL - 1;
3286  if (iDebug)
3287  printf("-E- path name too long, max allowed %d chars\n", ii);
3288  fprintf(fLogClient,
3289  "-E- %s: remote path name (%d chars) too long, max allowed %d\n",
3290  cModule, iPathLen, ii);
3291  iError = -1;
3292  goto gEndNewFile;
3293  }
3294 
3295  strncpy(pcNamehl, pcc2, (unsigned) iPathLen);
3296  if (iDebug)
3297  printf(" path name: %s\n", pcNamehl);
3298 
3299  strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
3300  if (strcmp(pcNamehl, pCommAPI->cNamehl))
3301  {
3302  strcpy(pcNamehl, pCommAPI->cNamehl);
3303  printf(" gStore path name corrected to %s\n", pcNamehl);
3304 
3305  strcpy(pcFile, cPrefix);
3306  strcat(pcFile, cNamefs);
3307  strcat(pcFile, cNamehl);
3308  strcat(pcFile, pcc1);
3309  if (iDebug) printf(
3310  " new full file name: %s\n", pcFile);
3311  }
3312 
3313  iFileLen = strlen(pcc1);
3314  if (iDebug)
3315  printf(" length file name: %d\n", iFileLen);
3316 
3317  ii = MAX_OBJ_LL-1;
3318  if ((int) strlen(pcc1) > ii)
3319  {
3320  if (iDebug)
3321  printf("-E- file name too long, max allowed %d chars\n", ii);
3322  fprintf(fLogClient,
3323  "-E- %s: file name %s (%d chars) too long, max allowed %d\n",
3324  cModule, pcc1, iFileLen, ii);
3325  iError = -1;
3326  goto gEndNewFile;
3327  }
3328 
3329  strcpy(pcNamell, pcc1);
3330  if (iDebug)
3331  printf(" file name: %s\n", pcNamell);
3332 
3333  } /* (iMassSto) */
3334  else
3335  {
3336  strcpy(pCommServ->cNamefs, "");
3337 
3338  strcpy(cTemp, pcc); /* starts now with remote path name */
3339  pcc = cTemp;
3340  pcc++; /* skip leading '/' */
3341  pcc1 = (char *) strrchr(pcc, *pcObjDelim);
3342  if (pcc1 == NULL)
3343  {
3344  fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
3345  cModule, pcFile);
3346  iError = -1;
3347  goto gEndNewFile;
3348  }
3349 
3350  if (strlen(pcc1) > MAX_OBJ_LL-1)
3351  {
3352  ii = MAX_OBJ_LL-1;
3353  fprintf(fLogClient,
3354  "-E- %s: remote file name %s too long (max %d chars)\n",
3355  cModule, pcc1, ii);
3356  iError = -1;
3357  goto gEndNewFile;
3358  }
3359 
3360  strcpy(pcNamell, pcc1);
3361  if (iDebug) printf(
3362  " remote file name on RFIO server: %s\n", pcNamell);
3363 
3364  strncpy(pcc1, "\0", 1); /* terminates path name */
3365  if (strlen(cTemp) > MAX_OBJ_HL-1)
3366  {
3367  ii = MAX_OBJ_HL-1;
3368  fprintf(fLogClient,
3369  "-E- %s: remote path name %s too long (max %d chars)\n",
3370  cModule, cTemp, ii);
3371  iError = -1;
3372  goto gEndNewFile;
3373  }
3374 
3375  strcpy(pcNamehl, cTemp);
3376  if (iDebug) printf(
3377  " remote path name on RFIO server: %s\n", pcNamehl);
3378 
3379  } /* (iMassSto = 0) */
3380 
3381  if (strlen(pCommServ->cNamehl))
3382  {
3383  if (strcmp(pCommServ->cNamehl, pcNamehl))
3384  {
3385  fprintf(fLogClient, "-W- new path name %s, previous %s\n",
3386  pcNamehl, pCommServ->cNamehl);
3387  inewPath = 1;
3388  }
3389  else
3390  inewPath = 0;
3391  }
3392  else
3393  {
3394  strcpy(pCommServ->cNamehl, pcNamehl);
3395  strcpy(pCommAPI->cNamehl, pcNamehl);
3396  }
3397 
3398  if (strlen(pCommAPI->cNamefs) < 3)
3399  strcpy(pCommAPI->cNamefs, pCommServ->cNamefs);
3400 
3401  strcpy(pCommAPI->cNamell, pcNamell);
3402  strcpy(pCommServ->cNamell, pcNamell);
3403  if (inewPath)
3404  {
3405  strcpy(pCommServ->cNamehl, pcNamehl);
3406  strcpy(pCommAPI->cNamehl, pcNamehl);
3407  }
3408 
3409  if (iDebug)
3410  printf(" file name: %s\n", pcNamell);
3411 
3412  pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
3413 
3414  /********************** perform queries ***************************/
3415 
3416  if (iMassSto)
3417  {
3418  iATLServer = pCommAPI->iATLServer;
3419  if (iDebug) printf(
3420  " query file %s in ATL server %d\n", pcFile, iATLServer);
3421 
3422  pBufQuery = &sQuery;
3423  pQAttr = &(sQuery.objAttr);
3424 
3425  pCommServ->iAction = htonl(QUERY_ARCHIVE_RECORD); /* temp */
3426 
3427  iRC = rawQueryFile(pcurAPIFile->iSockMaster, 0,
3428  pCommServ, &pBufQuery);
3429 
3430  pCommServ->iAction = htonl(ARCHIVE_RECORD); /* reset */
3431 
3432  if (iRC)
3433  {
3434  if (iRC < 0)
3435  {
3436  if (iRC == -1001) sprintf(rfio_errmsg,
3437  "-E- no write access to archive %s in mass storage\n",
3438  pCommAPI->cNamefs);
3439  else if (iRC == -1000) sprintf(rfio_errmsg,
3440  "-E- no archive %s in mass storage found\n",
3441  pCommAPI->cNamefs);
3442  else sprintf(rfio_errmsg,
3443  "-E- file %s: query in mass storage failed, rc = %d\n",
3444  pcFile, iRC);
3445  }
3446  else sprintf(rfio_errmsg,
3447  "-E- file %s already available in mass storage\n",
3448  pcFile);
3449  fprintf(fLogClient, "%s", rfio_errmsg);
3450 
3451  if ( (iRC == -1001) || (iRC == -1000) )
3452  iError = -1;
3453  else
3454  iError = 1;
3455 
3456  goto gEndNewFile;
3457  }
3458 
3459  if (iDebug) printf(
3460  " file %s not yet available in mass storage\n", pcFile);
3461 
3462  } /* (iMassSto) */
3463 
3464 gNextCmdNewFile:
3465  iCopyMode = ntohl(pCopyCacheServ->iCopyMode);
3466  if (iCopyMode)
3467  {
3468  iCopyLen = ntohl(pCopyCacheServ->iCopyLen);
3469  if (iCopyLen == 0)
3470  {
3471  iCopyBuffer = 1;
3472  ii = irawCopyCache - HEAD_LEN;
3473  pCopyCacheServ->iCopyLen = htonl(ii);
3474  if (iDebug)
3475  printf(" send copy parameters to DM\n");
3476  }
3477  else if (iDebug)
3478  printf(" copy parameters already sent to DM\n");
3479  }
3480  else if (iDebug)
3481  printf(" data are only written to WC\n");
3482 
3483  if (iDebug)
3484  {
3485  printf(" send command buffer to server %s: id: %d, action %d, bufsize %d",
3486  pcurAPIFile->cNodeMover,
3487  pCommAPI->iIdent,
3488  pCommAPI->iAction,
3489  pCommAPI->iBufsizeFile);
3490  if (iCopyBuffer)
3491  printf(", data len %d\n",
3492  pCommAPI->iCommLen + irawCopyCache);
3493  else
3494  printf(", data len %d\n", pCommAPI->iCommLen);
3495  }
3496 
3497  iSockMover = pcurAPIFile->iSockMover;
3498  pcc = (char *) pCommServ;
3499  if (iCopyBuffer)
3500  pCommServ->iCommLen = htonl(pCommAPI->iCommLen + irawCopyCache);
3501  /* temp for data mover */
3502 
3503  if ( (iRC = send(iSockMover, pcc, (unsigned) irawComm, 0 )) < 0 )
3504  {
3505  fprintf(fLogClient,
3506  "-E- %s: sending command buffer to server %s (rc = %d)\n",
3507  cModule, pcurAPIFile->cNodeMover, iRC);
3508  perror(" ");
3509  iError = -1;
3510  goto gEndNewFile;
3511  }
3512 
3513  if (irawComm != iRC)
3514  {
3515  fprintf(fLogClient,
3516  "-E- %s: incomplete command buffer sent to server %s (%d of %d bytes)\n",
3517  cModule, pcurAPIFile->cNodeMover, iRC, irawComm);
3518 
3519  iError = -1;
3520  goto gEndNewFile;
3521  }
3522 
3523  if (iDebug) printf(
3524  " command buffer sent to server %s (%d byte)\n",
3525  pcurAPIFile->cNodeMover, irawComm);
3526 
3527  if (iCopyBuffer)
3528  {
3529  pcc = (char *) pCopyCacheServ;
3530  if ( (iRC = send(iSockMover, pcc, (unsigned) irawCopyCache, 0 )) < 0 )
3531  {
3532  fprintf(fLogClient,
3533  "-E- %s: sending copy buffer to server %s (rc = %d)\n",
3534  cModule, pcurAPIFile->cNodeMover, iRC);
3535  perror(" ");
3536  iError = -1;
3537  goto gEndNewFile;
3538  }
3539 
3540  if (irawCopyCache != iRC)
3541  {
3542  fprintf(fLogClient,
3543  "-E- %s: incomplete copy buffer sent to server %s (%d of %d bytes)\n",
3544  cModule, pcurAPIFile->cNodeMover, iRC, irawCopyCache);
3545 
3546  iError = -1;
3547  goto gEndNewFile;
3548  }
3549 
3550  if (iDebug) printf(
3551  " copy buffer sent to server %s (%d byte)\n",
3552  pcurAPIFile->cNodeMover, irawCopyCache);
3553 
3554  pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
3555  /* reset temp length for data mover again */
3556  }
3557 
3558  /******************* look for reply from server *******************/
3559 
3560  pcc = (char *) &sStatus;
3561  iStatusOkay = 0;
3562  iStatusLoop = 0;
3563  while (iStatusOkay == 0)
3564  {
3565  iStatusLoop++;
3566 
3567  memset(&sStatus, 0X00, sizeof(srawStatus));
3568  iRC = rawRecvStatus(iSockMover, pcc);
3569  iStatus = sStatus.iStatus;
3570  if (iDebug) printf(
3571  " status %d received (%d byte)\n", iStatus, iRC);
3572  if (iRC != HEAD_LEN)
3573  {
3574  if (iRC < HEAD_LEN) fprintf(fLogClient,
3575  "-E- %s: receiving status buffer from server\n",
3576  cModule);
3577  else /* received error message */
3578  {
3579  if (iStatus == STA_CACHE_FULL)
3580  {
3581  if ( (iStatusLoop < iStatusLoopMax) &&
3582  (iMassSto != 2) ) /* no delay for DAQPool */
3583  {
3584  fprintf(fLogClient,
3585  "-W- %s: write cache currently full ... sleep %d s (%d of %d)\n",
3586  cModule, iSleepCacheFull,
3587  iStatusLoop, iStatusLoopMax);
3588  continue;
3589  }
3590  else
3591  {
3592  fprintf(fLogClient,
3593  "-W- %s: write cache currently full, archive to tape\n",
3594  cModule);
3595  pCommServ->iAction = htonl(ARCHIVE_RECORD);
3596  pCommServ->iArchDev = htonl(ARCH_TAPE);
3597  pCommAPI->iAction = ARCHIVE_RECORD;
3598  pCommAPI->iArchDev = ARCH_TAPE;
3599 
3600  /* copy from WC no longer possible */
3601  iCopyMode = 0;
3602  pCopyCacheServ->iCopyMode = htonl(0);
3603 
3604  goto gNextCmdNewFile;
3605  }
3606  } /* (iStatus == STA_CACHE_FULL) */
3607  else if (iStatus == STA_SWITCH_SERVER)
3608  {
3609  strcpy(cNodeMover, sStatus.cStatus);
3610 
3611  fprintf(fLogClient,
3612  "-W- write cache on DM %s full or too much load, switch to %s\n",
3613  pcurAPIFile->cNodeMover, cNodeMover);
3614 
3615  if (iDebug) printf(
3616  " close connection %d to data mover %s\n",
3617  iSockMover, pcurAPIFile->cNodeMover);
3618  iRC = shutdown(iSockMover, 2);
3619  if (iDebug)
3620  printf(" rc shutdown = %d\n", iRC);
3621 
3622  iRC = close(iSockMover);
3623  if (iDebug)
3624  printf(" rc close = %d\n", iRC);
3625  else if (iRC == 0)
3626  fprintf(fLogClient,
3627  "-I- connection to data mover %s closed\n",
3628  pcurAPIFile->cNodeMover);
3629 
3630  /*************** connect to new data mover ************/
3631 
3632  if (iDebug) printf(
3633  " connecting to data mover %s:%d\n",
3634  cNodeMover, iPortMover);
3635 
3636  iRC = rconnect(cNodeMover, iPortMover,
3637  &iMaxConnect, &iSockMover);
3638  if (iRC)
3639  {
3640  fprintf(fLogClient,
3641  "-E- %s: cannot connect to new data mover %s:%d (ATL server %d)\n",
3642  cModule, cNodeMover, iPortMover, iATLServer);
3643  iError = -2;
3644  }
3645 
3646  fprintf(fLogClient,
3647  "-I- successfully connected to new data mover %s:%d (ATL server %d)",
3648  cNodeMover, iPortMover, iATLServer);
3649  if (iMaxConnect)
3650  fprintf(fLogClient, " after %ds", iMaxConnect);
3651  if (iDebug)
3652  printf(" (socket %d)\n", iSockMover);
3653  else
3654  fprintf(fLogClient, "\n");
3655 
3656  strcpy(pcurAPIFile->cNodeMover, cNodeMover);
3657  pcurAPIFile->iSockMover = iSockMover;
3658 
3659  pCopyCacheServ->iCopyLen = htonl(0);
3660  /* copy buffer must be sent again to DM */
3661  goto gNextCmdNewFile;
3662 
3663  } /* (iStatus == STA_SWITCH_SERVER) */
3664  else
3665  {
3666  fprintf(fLogClient, "-E- message received from server:\n");
3667  fprintf(fLogClient, " %s\n", sStatus.cStatus);
3668 
3669  if (iStatus == STA_ERROR_EOF)
3670  iError = 1;
3671  else
3672  iError = -2;
3673  }
3674 
3675  } /* (iRC >= HEAD_LEN) */
3676 
3677  goto gEndNewFile;
3678 
3679  } /* (iRC != HEAD_LEN) */
3680  iStatusOkay = 1;
3681 
3682  } /* while (iStatusOkay == 0) */
3683 
3684  if (iDebug)
3685  {
3686  printf(" status (%d) received from server (%d bytes",
3687  iStatus, iRC);
3688  if (iStatusLoop > 1)
3689  printf(", iter %d)\n", iStatusLoop);
3690  else
3691  printf(")\n");
3692  }
3693 
3694  iError = 0;
3695  /* = 1: file already in mass storage: try new name
3696  = -2: write cache of current data mover full: close, new open
3697  = -3: write cache of all data movers full: close, retry
3698  */
3699 
3700 gEndNewFile:
3701  if (iDebug)
3702  printf("-D- end %s\n\n", cModule);
3703 
3704  return iError;
3705 
3706 } /* rfio_newfile */
3707 
3708 /********************************************************************
3709  * rfio_close:
3710  * close remote file in GSI mass storage and
3711  * connection to GSI mass storage
3712  *
3713  * created 4.12.2000, Horst Goeringer
3714  ********************************************************************
3715  */
3716 
3717 int rfio_close(int iFileId) /* file id */
3718 {
3719  char cModule[32] = "rfio_close";
3720  int iDebug = 0;
3721  int iRC;
3722  int iSockMaster; /* socket for connection to master */
3723  int iSockMover; /* socket for connection to mover */
3724  int iStatus = STA_END_OF_SESSION;
3725  int ii = 0;
3726  char *pcc;
3727 
3728  srawStatus sStatusRecv;
3729  srawComm *pCommAPI;
3730  srawAPIFile *pcurAPIFile;
3731 
3732  if (iDebug) printf(
3733  "\n-D- begin %s: close remote file %d\n", cModule, iFileId);
3734 
3735  if (iFileCount == 0)
3736  {
3737  fprintf(fLogClient,
3738  "-E- %s: no remote file available for close\n", cModule);
3739  return -1;
3740  }
3741 
3742  while (ii < iFileMax)
3743  {
3744  if (pAPIFile[ii])
3745  {
3746  if (pAPIFile[ii]->iFileId == iFileId)
3747  break;
3748  }
3749  ii++;
3750  }
3751 
3752  if (ii == iFileMax)
3753  {
3754  fprintf(fLogClient, "-E- %s: remote file %d cannot be closed: not found\n",
3755  cModule, iFileId);
3756  return -1;
3757  }
3758 
3759  pcurAPIFile = pAPIFile[iFileId];
3760  pCommAPI = &(pcurAPIFile->sCommAPI);
3761  iStatus = STA_END_OF_SESSION;
3762  iSockMaster = pcurAPIFile->iSockMaster;
3763 
3764  if ( (pcurAPIFile->iMassSto) &&
3765  (pcurAPIFile->iOpMode == 0) ) /* 'normal' RFIO */
3766  fprintf(fLogClient, "-I- gStore file %s%s%s closed\n",
3767  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
3768 
3769  if (iSockMaster >= 0)
3770  {
3771  /* stop master server process */
3772  iRC = rawSendStatus(iSockMaster, iStatus, NULL);
3773  if (iRC <= 0) fprintf(fLogClient,
3774  "-E- %s: sending status buffer (EOS) to master\n", cModule);
3775  else if (iDebug) printf(
3776  " status buffer (EOS) sent to master (%d bytes)\n", iRC);
3777 
3778  if (iDebug)
3779  printf(" close connection %d to master\n", iSockMaster);
3780  iRC = shutdown(iSockMaster, 2);
3781  if (iDebug)
3782  printf(" rc shutdown = %d\n", iRC);
3783  iRC = close(iSockMaster);
3784  if (iDebug)
3785  printf(" rc close = %d\n", iRC);
3786 
3787  } /* (iSockMaster >= 0) */
3788 
3789  iSockMover = pcurAPIFile->iSockMover;
3790  if (iSockMover >= 0)
3791  {
3792  /* stop data mover process */
3793  iRC = rawSendStatus(iSockMover, iStatus, NULL);
3794  if (iRC <= 0) fprintf(fLogClient,
3795  "-E- %s: sending status buffer (EOS) to data mover\n", cModule);
3796  else if (iDebug) printf(
3797  " status buffer (EOS) sent to data mover (%d bytes)\n", iRC);
3798 
3799  /* receive confirmation if written to tape */
3800  if ( (pCommAPI->iAction == ARCHIVE_RECORD) &&
3801  (pCommAPI->iArchDev == ARCH_TAPE) &&
3802  (pcurAPIFile->iOpMode == 0) ) /* in rfio_endfile alr. done */
3803  {
3804  memset(&sStatusRecv, 0X00, sizeof(srawStatus));
3805  pcc = (char *) &sStatusRecv;
3806  iRC = rawRecvStatus(iSockMover, pcc);
3807 
3808  if (iRC < HEAD_LEN) fprintf(fLogClient,
3809  "-E- %s: receiving confirmation of status buffer (EOS)\n",
3810  cModule);
3811  else if (iDebug) printf(
3812  " status (%d) confirmed by server (%d bytes)\n",
3813  sStatusRecv.iStatus, iRC);
3814  }
3815 
3816  if (iDebug)
3817  printf(" close connection %d to data mover\n", iSockMover);
3818  iRC = shutdown(iSockMover, 2);
3819  if (iDebug)
3820  printf(" rc shutdown = %d\n", iRC);
3821  iRC = close(iSockMover);
3822  if (iDebug)
3823  printf(" rc close = %d\n", iRC);
3824  else fprintf(fLogClient,
3825  "-I- connection to data mover %s closed\n",
3826  pcurAPIFile->cNodeMover);
3827 
3828  } /* (iSockMover >= 0) */
3829 
3830  free(pAPIFile[iFileId]);
3831  pAPIFile[iFileId] = NULL;
3832  iFileCount--;
3833 
3834  if (iDebug)
3835  {
3836  printf(
3837  " remote file control block %d deleted (%d still active)\n",
3838  iFileId, iFileCount);
3839  printf("-D- end %s\n\n", cModule);
3840  }
3841 
3842  return 0;
3843 
3844 } /* rfio_close */
3845 
3846 #ifdef __USE_LARGEFILE64
3847 
3848 /********************************************************************
3849  * rfio_preseek64: in remote file in GSI mass storage
3850  * move read/write file mark
3851  *
3852  * created 29. 5.2007, Horst Goeringer
3853  ********************************************************************
3854  */
3855 
3856 int rfio_preseek64(
3857  int iFileId,
3858  const struct iovec64 *piov,
3859  int iBufferNumber)
3860 {
3861  char cModule[32] = "rfio_preseek64";
3862  int iDebug = 0;
3863  int iRC = 0;
3864 
3865  if (iDebug) fprintf(fLogClient,
3866  "\n-D- begin %s: iFileId %d\n", cModule, iFileId);
3867 
3868  ii = sizeof(long);
3869  if (ii < 8)
3870  {
3871  fprintf(fLogClient,
3872  "-E- 32 bit client: %s not supported\n", cModule);
3873 
3874  return -1;
3875  }
3876 
3877  fprintf(fLogClient,
3878  "-W- %s not yet implemented for gStore\n", cModule);
3879 
3880  if (iDebug)
3881  fprintf(fLogClient, "-D- end %s\n\n", cModule);
3882 
3883  return iRC;
3884 
3885 } /* rfio_preseek64 */
3886 
3887 /********************************************************************
3888  * rfio_lseek64: in remote file in GSI mass storage
3889  * move read/write file mark
3890  *
3891  * created 29. 5.2007, Horst Goeringer
3892  ********************************************************************
3893  */
3894 
3895 int64_t rfio_lseek64(
3896  int iFileId,
3897  int64_t i64locOffset,
3898  int ilocSeekMode)
3899 {
3900  char cModule[32] = "rfio_lseek64";
3901  int iDebug = 0;
3902  int iRC;
3903  int ilocOffset;
3904  int ii;
3905 
3906  ii = sizeof(long);
3907  if (ii < 8)
3908  {
3909  fprintf(fLogClient,
3910  "-E- 32 bit client: %s not supported\n", cModule);
3911 
3912  return -1;
3913  }
3914 
3915  if (iDebug) fprintf(fLogClient,
3916  "\n-D- begin %s: iFileId %d, Offset %lld, SeekMode %d\n",
3917  cModule, iFileId, (unsigned long) i64locOffset, ilocSeekMode);
3918 
3919  ilocOffset = (int) i64locOffset;
3920 
3921  iRC = rfio_lseek(iFileId, ilocOffset, ilocSeekMode);
3922 
3923  if (iDebug) fprintf(fLogClient,
3924  "-D- end %s: rc(rfio_lseek) = %d \n\n", cModule, iRC);
3925 
3926  return (int64_t) iRC;
3927 
3928 } /* rfio_lseek64 */
3929 
3930 #endif /* __USE_LARGEFILE64 */
3931 
3932 /********************************************************************
3933  * rfio_lseek: in remote file in GSI mass storage
3934  * move read/write file mark
3935  *
3936  * created 4.12.2000, Horst Goeringer
3937  ********************************************************************
3938  */
3939 
3940 int rfio_lseek(int iFileId, /* file id */
3941  int ilocOffset,
3942  int ilocSeekMode)
3943 {
3944  char cModule[32] = "rfio_lseek";
3945  int iDebug = 0;
3946  int iRC;
3947  int iSockMover; /* socket for connection to mover */
3948  int iSeekMode;
3949  int iOffset;
3950 
3951  srawAPIFile *pcurAPIFile;
3952 
3953  if (iDebug)
3954  {
3955  printf("\n-D- begin %s: file %d\n", cModule, iFileId);
3956  if (ilocSeekMode == SEEK_SET)
3957  printf(" position to %d bytes, \n", ilocOffset);
3958  else if (ilocSeekMode == SEEK_CUR)
3959  printf(" position to current + %d bytes, \n", ilocOffset);
3960  else if (ilocSeekMode == SEEK_END)
3961  printf(" position to file size + %d bytes, \n", ilocOffset);
3962  else
3963  {
3964  fprintf(fLogClient, "-E- %s: unexpected offset (%d)\n",
3965  cModule, ilocSeekMode);
3966  return -1;
3967  }
3968  }
3969 
3970  pcurAPIFile = pAPIFile[iFileId];
3971  iSeekMode = pcurAPIFile->iSeekMode;
3972 
3973  /* check if still seek request pending */
3974  if (iSeekMode != -1)
3975  {
3976  iSockMover = pcurAPIFile->iSockMover;
3977  iOffset = pcurAPIFile->iOffset;
3978  iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, 0);
3979  if (iRC != 0)
3980  {
3981  fprintf(fLogClient, "-E- %s: sending request for seek\n", cModule);
3982  return -1;
3983  }
3984  }
3985 
3986  pcurAPIFile->iSeekMode = ilocSeekMode;
3987  pcurAPIFile->iOffset = ilocOffset;
3988 
3989  if (iDebug)
3990  printf("-D- end %s\n\n", cModule);
3991 
3992  return 0;
3993 
3994 } /* rfio_lseek */
3995 
3996 /********************************************************************
3997  * rfio_fopen: open connection to gStore server and file
3998  *
3999  * created 4.12.2000, Horst Goeringer
4000  ********************************************************************
4001  */
4002 
4003 RFILE *rfio_fopen(char *pcFile, /* file name */
4004  char *pcOptions) /* options */
4005 {
4006  char cModule[32] = "rfio_fopen";
4007  int iDebug = 0;
4008  RFILE *fRemoteFile = NULL;
4009  int iCopyMode = 0; /* ignore parameters for data stream copy */
4010  char *pcCopyPath = NULL;
4011  int iCopyFraction = 0;
4012  int iMaxFile = 0;
4013  int iPathConvention = 0;
4014 
4015  if (iDebug)
4016  printf("\n-D- begin %s: calling rfio_fopen_gsidaq\n", cModule);
4017 
4018  fRemoteFile = rfio_fopen_gsidaq(
4019  pcFile,
4020  pcOptions,
4021  iCopyMode,
4022  pcCopyPath,
4023  iCopyFraction,
4024  iMaxFile,
4025  iPathConvention);
4026 
4027  if (iDebug)
4028  printf("-D- end %s\n\n", cModule);
4029 
4030  return fRemoteFile;
4031 
4032 } /* rfio_fopen */
4033 
4034 /********************************************************************
4035  * rfio_fopen_gsidaq_dm: open connection to gStore server and file and
4036  * prepare copy to lustre or read cache before migration to tape
4037  * provide DM name and running number
4038  *
4039  * created 23. 4.2010, Horst Goeringer
4040  ********************************************************************
4041  */
4042 
4044  char *pcFile, /* file name */
4045  char *pcOptions, /* options */
4046  char *pcDataMover,
4047  int *piDataMover,
4048  int iCopyMode,
4049  /* = 0: standard RFIO, ignore following arguments
4050  = 1: copy to pcCopyPath after file written to WC
4051  (for high data rates,
4052  don't interfere writing to cache)
4053  = 2: for lustre only:
4054  write each data buffer in parallel to
4055  write cache and to pcCopyPath
4056  (for low data rates, anyhow first buffers
4057  quickly available in lustre)
4058  */
4059  char *pcCopyPath,
4060  /* destination where to be copied
4061  = "/lustre..." => fully qualified path name
4062  if not existing: will be created according
4063  to user conventions:
4064  ".../d" => Hades, create .../dyydddhhmm
4065  = "RC" => read cache
4066  */
4067  int iCopyFraction,
4068  /* = i>0: copy each ith file to pcCopyPath
4069  if tape migration fails:
4070  ignore iCopyFraction, copy each file
4071  */
4072  int iMaxFile,
4073  /* for dataFS only:
4074  = 0: no file limit
4075  > 0: max no. of files to be written to directory
4076  max no. of files to be written to directory
4077  files already existing are ignored
4078  if iMaxFile reached, new dir will be created
4079  (same level as previous one)
4080  */
4081  int iPathConvention)
4082  /* rules for creation of initial/new path
4083  = 0: default convention
4084  initially specified .../xxx => .../xxx
4085  last .../xxx => create ...xxx1
4086  last .../xxxi => create ...xxxj j=i+1
4087  = 1: Hades convention: path name contains time stamp
4088  initially specified .../xxx => .../xxxyydddhhmm
4089  new => .../xxxyydddhhmm
4090  */
4091 {
4092  char cModule[32] = "rfio_fopen_gsidaq_dm";
4093  int iDebug = 0;
4094  int iFileId = -1; /* file identifier for server connection */
4095  int iDataMover = 0;
4096  int ilen;
4097  char *pcc;
4098 
4099  if (iDebug)
4100  printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
4101 
4102  if (*pcOptions == 'r')
4103  {
4104  iFileId = rfio_open_gsidaq(
4105  pcFile, O_RDONLY, 0,
4106  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4107  iPathConvention);
4108  }
4109  if (*pcOptions == 'w')
4110  {
4111  iFileId = rfio_open_gsidaq(
4112  pcFile, O_WRONLY | O_CREAT, 0,
4113  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4114  iPathConvention);
4115  }
4116 
4117  if (iFileId >= 0)
4118  {
4119  ilen = strlen(pAPIFile[iFileId]->cNodeMover);
4120  strcpy(pcDataMover, pAPIFile[iFileId]->cNodeMover);
4121  if (iDebug) printf(
4122  " connected with data mover %s\n", pcDataMover);
4123 
4124  pcc = pcDataMover;
4125  pcc += ilen - 2; /* last 2 digits are the running number */
4126  iDataMover = atoi(pcc);
4127  *piDataMover = iDataMover;
4128 
4129  if (iDebug) printf(
4130  " running number data mover: %d\n", iDataMover);
4131  }
4132 
4133  if (iDebug) printf(
4134  "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
4135  cModule, iFileId);
4136 
4137  if (iFileId < 0)
4138  return NULL;
4139 
4140  return pAPIFile[iFileId]; /* global, filled in rfio_open */
4141 
4142 } /* rfio_fopen_gsidaq_dm */
4143 
4144 /********************************************************************
4145  * rfio_fopen_gsidaq: open connection to gStore server and file and
4146  * prepare copy to lustre or read cache before migration to tape
4147  *
4148  * created 4.12.2000, Horst Goeringer
4149  ********************************************************************
4150  */
4151 
4153  char *pcFile, /* file name */
4154  char *pcOptions, /* options */
4155  int iCopyMode,
4156  /* = 0: standard RFIO, ignore following arguments
4157  = 1: copy to pcCopyPath after file written to WC
4158  (for high data rates,
4159  don't interfere writing to cache)
4160  = 2: for lustre only:
4161  write each data buffer in parallel to
4162  write cache and to pcCopyPath
4163  (for low data rates, anyhow first buffers
4164  quickly available in lustre)
4165  */
4166  char *pcCopyPath,
4167  /* destination where to be copied
4168  = "/lustre..." => fully qualified path name
4169  if not existing: will be created according
4170  to user conventions:
4171  ".../d" => Hades, create .../dyydddhhmm
4172  = "RC" => read cache
4173  */
4174  int iCopyFraction,
4175  /* = i>0: copy each ith file to pcCopyPath
4176  if tape migration fails:
4177  ignore iCopyFraction, copy each file
4178  */
4179  int iMaxFile,
4180  /* for dataFS only:
4181  = 0: no file limit
4182  > 0: max no. of files to be written to directory
4183  max no. of files to be written to directory
4184  files already existing are ignored
4185  if iMaxFile reached, new dir will be created
4186  (same level as previous one)
4187  */
4188  int iPathConvention)
4189  /* rules for creation of initial/new path
4190  = 0: default convention
4191  initially specified .../xxx => .../xxx
4192  last .../xxx => create ...xxx1
4193  last .../xxxi => create ...xxxj j=i+1
4194  = 1: Hades convention: path name contains time stamp
4195  initially specified .../xxx => .../xxxyydddhhmm
4196  new => .../xxxyydddhhmm
4197  */
4198 {
4199  char cModule[32] = "rfio_fopen_gsidaq";
4200  int iDebug = 0;
4201  int iFileId = -1; /* file identifier for server connection */
4202 
4203  if (iDebug)
4204  printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
4205 
4206  if (*pcOptions == 'r')
4207  {
4208  iFileId = rfio_open_gsidaq(
4209  pcFile, O_RDONLY, 0,
4210  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4211  iPathConvention);
4212  }
4213  if (*pcOptions == 'w')
4214  {
4215  iFileId = rfio_open_gsidaq(
4216  pcFile, O_WRONLY | O_CREAT, 0,
4217  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4218  iPathConvention);
4219  }
4220 
4221  if (iDebug) printf(
4222  "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
4223  cModule, iFileId);
4224 
4225  if (iFileId < 0)
4226  return NULL;
4227 
4228  return pAPIFile[iFileId]; /* global, filled in rfio_open */
4229 
4230 } /* rfio_fopen_gsidaq */
4231 
4232 /*********************************************************************
4233  * rfio_fnewfile: continue with next remote file in GSI mass storage
4234  *
4235  * created 2. 8.2004, Horst Goeringer
4236  *********************************************************************
4237  */
4238 
4239 int rfio_fnewfile(RFILE *pRemFile, /* remote file control block */
4240  char *pcFile) /* file name */
4241 {
4242  char cModule[32] = "rfio_fnewfile";
4243  int iDebug = 0;
4244  int iRC;
4245  int ii;
4246  int iFileId; /* file identifier for server connection */
4247 
4248  if (iDebug)
4249  {
4250  printf("\n-D- begin %s\n", cModule);
4251  fflush(stdout);
4252  }
4253 
4254  if (iFileCount <= 0)
4255  {
4256  fprintf(fLogClient, "-E- %s: still no connection to server opened\n",
4257  cModule);
4258  return -1;
4259  }
4260 
4261  if (pRemFile == NULL)
4262  {
4263  fprintf(fLogClient, "-E- %s: invalid file ptr (NULL) specified\n", cModule);
4264  return -1;
4265  }
4266 
4267  if ( (pcFile == NULL) || (strlen(pcFile) < 5) )
4268  {
4269  fprintf(fLogClient, "-E- %s: invalid file '%s' specified\n",
4270  cModule, pcFile);
4271  return -1;
4272  }
4273 
4274  ii = 0;
4275  while (ii < iFileMax)
4276  {
4277  if (pAPIFile[ii] == pRemFile) /* global, filled in rfio_open */
4278  break;
4279  ii++;
4280  }
4281 
4282  if (ii == iFileMax)
4283  {
4284  fprintf(fLogClient, "-E- %s: invalid file ptr specified\n", cModule);
4285  return -1;
4286  }
4287 
4288  iFileId = pRemFile->iFileId;
4289  iRC = rfio_newfile(iFileId, pcFile);
4290 
4291  if (iDebug)
4292  printf("-D- end %s\n\n", cModule);
4293 
4294  if (iFileId < 0)
4295  return -1;
4296 
4297  return iRC;
4298 
4299 } /* end rfio_fnewfile */
4300 
4301 /*********************************************************************
4302  * rfio_fread: read remote file in GSI mass storage
4303  *
4304  * created 4.12.2000, Horst Goeringer
4305  *********************************************************************
4306  */
4307 
4308 size_t rfio_fread(char *pcBuffer, /* data buffer */
4309  size_t iSize, /* size of data item */
4310  size_t iItems, /* number of data items */
4311  RFILE *pRemFile) /* remote file control block */
4312 {
4313  char cModule[32]="rfio_fread";
4314  int iDebug = 0;
4315  int iRC;
4316  int iFileId; /* file identifier for server connection */
4317  size_t iBytes;
4318 
4319  if (iDebug)
4320  printf("\n-D- begin %s\n", cModule);
4321 
4322  if (pRemFile == NULL)
4323  {
4324  fprintf(fLogClient, "-E- %s: remote file not open for read\n", cModule);
4325  return 0;
4326  }
4327 
4328  iFileId = pRemFile->iFileId;
4329  iBytes = iSize*iItems;
4330  iRC = (int) rfio_read(iFileId, pcBuffer, iBytes);
4331 
4332  if (iDebug)
4333  printf("-D- end %s\n", cModule);
4334 
4335  return (unsigned) iRC;
4336 
4337 } /* rfio_fread */
4338 
4339 /*********************************************************************
4340  * rfio_fwrite: write remote file to GSI mass storage
4341  *
4342  * created 4.12.2000, Horst Goeringer
4343  *********************************************************************
4344  */
4345 
4346 size_t rfio_fwrite(const char *pcBuffer, /* data buffer */
4347  size_t iSize, /* size of data item */
4348  size_t iItems, /* number of data items */
4349  RFILE *pRemFile) /* remote file control block */
4350 {
4351  char cModule[32]="rfio_fwrite";
4352  int iDebug = 0;
4353  int iFileId; /* file identifier for server connection */
4354  size_t iBytes;
4355  int iRC;
4356 
4357  if (iDebug)
4358  printf("\n-D- begin %s\n", cModule);
4359 
4360  if (pRemFile == NULL)
4361  {
4362  fprintf(fLogClient, "-E- %s: remote file not open for write\n", cModule);
4363  return 0;
4364  }
4365 
4366  iFileId = pRemFile->iFileId;
4367  iBytes = iSize*iItems;
4368  iRC = (int) rfio_write(iFileId, pcBuffer, iBytes);
4369 
4370  if (iDebug)
4371  printf("-D- end %s\n", cModule);
4372 
4373  return (unsigned) iRC;
4374 
4375 } /* rfio_fwrite */
4376 
4377 /********************************************************************
4378  * rfio_fendfile:
4379  * close remote file in GSI mass storage,
4380  * but keep connection to mass storage data mover
4381  *
4382  * created 16. 7.2004, Horst Goeringer
4383  ********************************************************************
4384  */
4385 
4386 int rfio_fendfile(RFILE *pRemFile) /* remote file control block */
4387 {
4388  char cModule[32] = "rfio_fendfile";
4389  int iDebug = 0;
4390  int iFileId; /* file identifier for server connection */
4391  int iRC;
4392 
4393  if (iDebug)
4394  printf("\n-D- begin %s\n", cModule);
4395 
4396  iFileId = pRemFile->iFileId;
4397  iRC = rfio_endfile(iFileId);
4398 
4399  if (iDebug)
4400  printf("-D- end %s\n", cModule);
4401 
4402  return iRC;
4403 
4404 } /* rfio_fendfile */
4405 
4406 /********************************************************************
4407  * rfio_fclose:
4408  * close remote file in GSI mass storage and
4409  * connection to GSI mass storage
4410  *
4411  * created 4.12.2000, Horst Goeringer
4412  ********************************************************************
4413  */
4414 
4415 int rfio_fclose(RFILE *pRemFile) /* remote file control block */
4416 {
4417  char cModule[32] = "rfio_fclose";
4418  int iDebug = 0;
4419  int iFileId; /* file identifier for server connection */
4420  int iRC;
4421 
4422  if (iDebug)
4423  printf("\n-D- begin %s\n", cModule);
4424 
4425  iFileId = pRemFile->iFileId;
4426  iRC = rfio_close(iFileId);
4427 
4428  if (iDebug)
4429  printf("-D- end %s\n", cModule);
4430 
4431  return iRC;
4432 
4433 } /* rfio_fclose */
4434 
4435 /********************************************************************
4436  * rfio_access: for remote file in GSI mass storage
4437  * get access status
4438  *
4439  * created 4.12.2000, Horst Goeringer
4440  ********************************************************************
4441  */
4442 
4443 int rfio_access(const char *pcFile, /* file name */
4444  int iMode)
4445 {
4446  char cModule[32] = "rfio_access";
4447  int iDebug = 0;
4448  int iRC = 0;
4449 
4450  int iFileId = -1;
4451 
4452  if (iDebug)
4453  printf("\n-D- begin %s\n", cModule);
4454 
4455  /* directories not (yet) supported */
4456  if (iMode == X_OK)
4457  {
4458  if (iDebug)
4459  printf(" check if executable - not supported\n");
4460  iRC = 1;
4461  goto gEndAccess;
4462  }
4463 
4464  if (iMode == F_OK)
4465  {
4466  if (iDebug)
4467  printf(" check for existence\n");
4468 
4469  iFileId = rfio_open(pcFile, O_RDONLY, -1);
4470  if (iFileId >= 0)
4471  {
4472  iRC = rfio_close(iFileId);
4473  if (iRC)
4474  {
4475  printf("-E- closing remote file %s\n", pcFile);
4476  perror(" ");
4477  }
4478  else if (iDebug)
4479  printf("-D- remote file %s closed\n", pcFile);
4480 
4481  /* file exists, access rights already checked */
4482 
4483  /* overwrite not allowed */
4484  if (iMode == W_OK)
4485  {
4486  if (iDebug)
4487  printf(" file %s must not be overwritten\n",
4488  pcFile);
4489  iRC = 1;
4490  }
4491  else if (iMode == R_OK)
4492  {
4493  if (iDebug)
4494  printf(" file %s is readable\n", pcFile);
4495  iRC = 0;
4496  }
4497  else
4498  {
4499  if (iDebug)
4500  printf(" file %s exists\n", pcFile);
4501  iRC = 0;
4502  }
4503  }
4504  else
4505  {
4506  /* file not existing */
4507  if (iMode == W_OK)
4508  {
4509  if (iDebug)
4510  printf(" file %s may be written\n", pcFile);
4511  iRC = 0;
4512  }
4513  else
4514  {
4515  if (iDebug)
4516  printf(" file %s not existing\n", pcFile);
4517  iRC = 1;
4518  }
4519  } /* file not existing */
4520  } /* check if file existing */
4521 
4522  /* assume correct handling of caller (root) after check for existence */
4523  if (iMode == R_OK)
4524  {
4525  if (iDebug)
4526  printf(" file %s is readable\n", pcFile);
4527  iRC = 0;
4528  }
4529  if (iMode == W_OK)
4530  {
4531  if (iDebug)
4532  printf(" file %s may be written\n", pcFile);
4533  iRC = 0;
4534  }
4535 
4536 gEndAccess:
4537  if (iDebug)
4538  printf("-D- end %s\n", cModule);
4539 
4540  return iRC;
4541 
4542 } /* rfio_access */
4543 
4544 #ifdef __USE_LARGEFILE64
4545 
4546 /*********************************************************************
4547  * rfio_fstat64: for remote file in GSI mass storage
4548  * get file status
4549  *
4550  * created 29. 5.2007, Horst Goeringer
4551  *********************************************************************
4552  */
4553 
4554 int rfio_fstat64(int iFileId,
4555  struct stat64 *pStatBuf64)/* file statistics buffer */
4556 {
4557  char cModule[32] = "rfio_fstat64";
4558  int iDebug = 0;
4559  int iRC = 0;
4560  int ii;
4561 
4562  unsigned long *plFileSizeC; /* ptr to file size in sComm */
4563  srawComm *pComm;
4564 
4565  if (iDebug)
4566  {
4567  fprintf(fLogClient, "\n-D- begin %s: file %d\n", cModule, iFileId);
4568  if (iFileCount)
4569  fprintf(fLogClient, ", %d remote files currently open\n", iFileCount);
4570  else
4571  fprintf(fLogClient, "\n");
4572  }
4573 
4574  ii = sizeof(long);
4575  if (ii < 8)
4576  {
4577  fprintf(fLogClient,
4578  "-E- 32 bit client: %s not supported\n", cModule);
4579 
4580  return -1;
4581  }
4582 
4583  ii = 0;
4584  if (iFileCount > 0) while (ii <= iFileMax)
4585  {
4586  if (pAPIFile[ii] != NULL)
4587  {
4588  if (pAPIFile[ii]->iFileId == iFileId)
4589  break;
4590  }
4591 
4592  ii++;
4593  }
4594 
4595  if ( (ii > iFileMax) || (iFileCount == 0) )
4596  {
4597  fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
4598  cModule, iFileId);
4599  if (iDebug)
4600  fprintf(fLogClient, "-D- end %s\n\n", cModule);
4601 
4602  return -1;
4603  }
4604 
4605  pComm = &(pAPIFile[ii]->sCommAPI);
4606  plFileSizeC = (unsigned long *) &(pComm->iFileSize);
4607 
4608  if (iDebug)
4609  {
4610  fprintf(fLogClient, " specified remote fileId %d found:\n", iFileId);
4611  fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
4612  pComm->cNamefs, pComm->cNamehl, pComm->cNamell, *plFileSizeC);
4613  }
4614 
4615  /* initialize stat structure with parameters of local stream stdin */
4616  iRC = fstat64(0, pStatBuf64);
4617  if (iRC)
4618  {
4619  fprintf(fLogClient, "-E- %s: fstat64() failed, rc = %d\n", cModule, iRC);
4620  if (iDebug)
4621  printf("-D- end %s\n\n", cModule);
4622 
4623  return -1;
4624  }
4625 
4626  /* now set correct file size */
4627  pStatBuf64->st_size = *plFileSizeC;
4628 
4629  if (iDebug) fprintf(fLogClient,
4630  "-D- end %s: irc(fstat64) = %d\n", cModule, iRC);
4631 
4632  return iRC;
4633 
4634 } /* rfio_fstat64 */
4635 
4636 #endif /* __USE_LARGEFILE64 */
4637 
4638 /*********************************************************************
4639  * rfio_fstat: for remote file in GSI mass storage
4640  * get file status
4641  *
4642  * created 26. 2.2001, Horst Goeringer
4643  *********************************************************************
4644  */
4645 
4646 int rfio_fstat(int iFileId, /* file id */
4647  struct stat *pStatBuf) /* buffer with file statistics */
4648 {
4649  char cModule[32] = "rfio_fstat";
4650  int iDebug = 0;
4651  int iRC = 0;
4652  int ii = 0;
4653 
4654  srawComm *pComm;
4655 
4656  if (iDebug)
4657  {
4658  printf("\n-D- begin %s", cModule);
4659  if (iFileCount)
4660  printf(", %d remote files currently open\n", iFileCount);
4661  else
4662  printf("\n");
4663  }
4664 
4665  ii = 0;
4666  if (iFileCount > 0) while (ii <= iFileMax)
4667  {
4668  if (pAPIFile[ii] != NULL)
4669  {
4670  if (pAPIFile[ii]->iFileId == iFileId)
4671  break;
4672  }
4673 
4674  ii++;
4675  }
4676 
4677  if ( (ii > iFileMax) || (iFileCount == 0) )
4678  {
4679  fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
4680  cModule, iFileId);
4681  if (iDebug)
4682  printf("-D- end %s\n\n", cModule);
4683 
4684  return -1;
4685  }
4686 
4687  pComm = &(pAPIFile[ii]->sCommAPI);
4688  if (iDebug)
4689  {
4690  printf(" specified remote fileId %d found:\n", iFileId);
4691  printf(" object %s%s%s, filesize %u byte\n",
4692  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
4693  pComm->iFileSize);
4694  }
4695 
4696  /* bzero(pStatBuf, sizeof(pStatBuf)); funktioniert nicht als init */
4697 
4698  /* initialize stat structure with parameters of local stream stdin */
4699  iRC = fstat(0, pStatBuf);
4700  if (iRC)
4701  {
4702  fprintf(fLogClient, "-E- %s: fstat() failed, rc = %d\n", cModule, iRC);
4703  if (iDebug)
4704  printf("-D- end %s\n\n", cModule);
4705 
4706  return -1;
4707  }
4708 
4709  /* now set correct file size */
4710  pStatBuf->st_size = pComm->iFileSize;
4711 
4712  if (iDebug)
4713  printf("-D- end %s\n\n", cModule);
4714 
4715  return 0;
4716 
4717 } /* rfio_fstat */
4718 
4719 /********************************************************************
4720  * rfio_parse: for remote file in GSI mass storage
4721  * parse name to host and path
4722  *
4723  * created 4.12.2000, Horst Goeringer
4724  ********************************************************************
4725  */
4726 
4727 int rfio_parse(char *pcFile, /* file name */
4728  char **pcNode,
4729  char **pcPath)
4730 {
4731  char cModule[32] = "rfio_parse";
4732  int iDebug = 0;
4733 
4734  if (iDebug)
4735  printf("\n-D- begin %s\n", cModule);
4736 
4737  if (iDebug)
4738  printf("-D- end %s\n", cModule);
4739 
4740  return 0;
4741 
4742 } /* rfio_parse */
4743 
4744 /********************************************************************
4745  * rfio_perror: for remote file in GSI mass storage
4746  * print error message to stderr
4747  *
4748  * created 26. 2.2001, Horst Goeringer
4749  ********************************************************************
4750  */
4751 
4752 void rfio_perror(const char *pUMsg) /* user prefix to error message */
4753 {
4754  char cModule[32] = "rfio_perror";
4755  int iDebug = 0;
4756 
4757  if (iDebug)
4758  printf("\n-D- begin %s\n", cModule);
4759 
4760  if (strlen(rfio_errmsg) == 0)
4761  fprintf(stderr, "%s : No error message\n", pUMsg);
4762  else
4763  fprintf(stderr, "%s : %s\n", pUMsg, rfio_errmsg);
4764 
4765  if (iDebug)
4766  printf("-D- end %s\n", cModule);
4767 
4768  return;
4769 
4770 } /* rfio_perror */
4771 
4772 /********************************************************************
4773  * rfio_serror: for remote file in GSI mass storage
4774  * print last RFIO related error message to string
4775  *
4776  * created 26. 2.2001, Horst Goeringer
4777  ********************************************************************
4778  */
4779 
4780 char * rfio_serror()
4781 {
4782  char cModule[32] = "rfio_serror";
4783  int iDebug = 0;
4784 
4785  if (iDebug) printf(
4786  "\n-D- begin %s: error (len %d byte):\n",
4787  cModule, (int) strlen(rfio_errmsg));
4788 
4789  printf(rfio_errmsg);
4790  fprintf(fLogClient, rfio_errmsg);
4791 
4792  if (iDebug)
4793  printf("-D- end %s\n", cModule);
4794 
4795  if (strlen(rfio_errmsg) == 0)
4796  return NULL;
4797 
4798  return rfio_errmsg;
4799 
4800 } /* rfio_serror */
4801 
4802 /********************************************************************
4803  * rfio_unlink: for remote file in GSI mass storage
4804  *
4805  * created 4.12.2000, Horst Goeringer
4806  ********************************************************************
4807  */
4808 
4809 int rfio_unlink(const char *pcFile) /* file name */
4810 {
4811  char cModule[32] = "rfio_unlink";
4812  int iDebug = 0;
4813 
4814  if (iDebug)
4815  printf("\n-D- begin %s\n", cModule);
4816 
4817  fprintf(fLogClient,
4818  "-W- %s not yet implemented for gStore\n", cModule);
4819 
4820  if (iDebug)
4821  printf("-D- end %s\n", cModule);
4822 
4823  return 1;
4824 
4825 } /* rfio_unlink */
4826 
4827 /********************************************************************
4828  * rfiosetopt: for remote file in GSI mass storage
4829  *
4830  * created 9. 9.2002, Horst Goeringer
4831  ********************************************************************
4832  */
4833 
4834 int rfiosetopt(int iopt, int *pival, int ilen)
4835 {
4836  char cModule[32] = "rfiosetopt";
4837  int iDebug = 0;
4838 
4839  if (iDebug)
4840  printf("\n-D- begin %s\n", cModule);
4841 
4842  if (iDebug)
4843  printf("-D- end %s\n", cModule);
4844 
4845  return 0;
4846 
4847 } /* rfiosetopt */
4848 
4849 /********************************************************************
4850  * rfio_mkdir: for remote file in GSI mass storage
4851  *
4852  * created 28. 8.2003, Horst Goeringer
4853  ********************************************************************
4854  */
4855 
4856 int rfio_mkdir(const char *path, int mode)
4857 {
4858  char cModule[32] = "rfio_mkdir";
4859  int iDebug = 0;
4860 
4861  if (iDebug)
4862  printf("\n-D- begin %s\n", cModule);
4863 
4864  fprintf(fLogClient,
4865  "-W- %s not yet implemented for gStore\n", cModule);
4866 
4867  if (iDebug)
4868  printf("-D- end %s\n", cModule);
4869 
4870  return 0;
4871 
4872 } /* rfio_mkdir */
4873 
4874 /********************************************************************
4875  * rfio_opendir: for remote file in GSI mass storage
4876  *
4877  * created 28. 8.2003, Horst Goeringer
4878  ********************************************************************
4879  */
4880 
4881 void *rfio_opendir(const char *dirpath)
4882 {
4883  char cModule[32] = "rfio_opendir";
4884  int iDebug = 0;
4885 
4886  if (iDebug)
4887  printf("\n-D- begin %s\n", cModule);
4888 
4889  fprintf(fLogClient,
4890  "-W- %s not yet implemented for gStore\n", cModule);
4891 
4892  if (iDebug)
4893  printf("-D- end %s\n", cModule);
4894 
4895  return 0;
4896 
4897 } /* rfio_opendir */
4898 
4899 /********************************************************************
4900  * rfio_readdir: for remote file in GSI mass storage
4901  *
4902  * created 28. 8.2003, Horst Goeringer
4903  ********************************************************************
4904  */
4905 
4906 void *rfio_readdir(void *dirp)
4907 {
4908  char cModule[32] = "rfio_readdir";
4909  int iDebug = 0;
4910 
4911  if (iDebug)
4912  printf("\n-D- begin %s\n", cModule);
4913 
4914  fprintf(fLogClient,
4915  "-W- %s not yet implemented for gStore\n", cModule);
4916 
4917  if (iDebug)
4918  printf("-D- end %s\n", cModule);
4919 
4920  return 0;
4921 
4922 } /* rfio_readdir */
4923 
4924 /********************************************************************
4925  * rfio_closedir: for remote file in GSI mass storage
4926  *
4927  * created 28. 8.2003, Horst Goeringer
4928  ********************************************************************
4929  */
4930 
4931 int rfio_closedir(void *dirp)
4932 {
4933  char cModule[32] = "rfio_closedir";
4934  int iDebug = 0;
4935 
4936  if (iDebug)
4937  printf("\n-D- begin %s\n", cModule);
4938 
4939  fprintf(fLogClient,
4940  "-W- %s not yet implemented for gStore\n", cModule);
4941 
4942  if (iDebug)
4943  printf("-D- end %s\n", cModule);
4944 
4945  return 0;
4946 
4947 } /* rfio_closedir */
4948 
4949 #ifdef __USE_LARGEFILE64
4950 
4951 /********************************************************************
4952  * rfio_stat64: for remote file in GSI mass storage
4953  * get file status
4954  *
4955  * created 29. 5.2007, Horst Goeringer
4956  ********************************************************************
4957  */
4958 
4959 int rfio_stat64(const char *pcFile, struct stat64 *pStatBuf64)
4960 {
4961  char cModule[32] = "rfio_stat64";
4962  int iDebug = 0;
4963  int iRC;
4964 
4965  int iMapFound = 0; /* =1: specified file already open */
4966  int iFileId = -1;
4967  int iRC;
4968  int ii;
4969  char *pcc;
4970  char cObject[MAX_FULL_FILE] = "";
4971 
4972  srawComm *pComm;
4973  unsigned long *plFileSizeC; /* ptr to file size in sComm */
4974 
4975  if (iDebug)
4976  fprintf(fLogClient, "\n-D- begin %s: file %s\n", cModule, pcFile);
4977 
4978  ii = sizeof(long);
4979  if (ii < 8)
4980  {
4981  fprintf(fLogClient,
4982  "-E- 32 bit client: %s not supported\n", cModule);
4983 
4984  return -1;
4985  }
4986 
4987  iOnlyQuery = 1; /* no DM selection */
4988  ii = 0;
4989  if (iFileCount > 0)
4990  while (ii <= iFileMax)
4991  {
4992  if (pAPIFile[ii] != NULL)
4993  {
4994  pComm = &(pAPIFile[ii]->sCommAPI);
4995  strcpy(cObject, pComm->cNamefs);
4996  strcat(cObject, pComm->cNamehl);
4997  strcat(cObject, pComm->cNamell);
4998 
4999  if (iDebug) fprintf(fLogClient,
5000  " %d: %s already open\n", ii, cObject);
5001 
5002  pcc = strstr(pcFile, cObject);
5003  if (pcc != NULL)
5004  {
5005  iMapFound = 1;
5006  if (iDebug)
5007  fprintf(fLogClient, " %d: %s maps\n", ii, cObject);
5008  break;
5009  }
5010  }
5011  else if (iDebug) fprintf(fLogClient,
5012  " %d: no (more) open file found\n", ii);
5013 
5014  ii++;
5015  }
5016 
5017  if (iMapFound == 0)
5018  {
5019  if (iDebug) fprintf(fLogClient,
5020  " remote file %s not yet open\n", pcFile);
5021 
5022  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5023  if (iFileId < 0) fprintf(fLogClient,
5024  "-E- %s: open for remote file %s failed\n", cModule, pcFile);
5025  }
5026  else
5027  {
5028  iFileId = pAPIFile[ii]->iFileId;
5029  if (iFileId < 0) fprintf(fLogClient,
5030  "-E- %s: invalid handle (%d) for remote file %s found\n",
5031  cModule, iFileId, pcFile);
5032  }
5033 
5034  /* info still available, must be freed here */
5035  if (iFileId >= 0)
5036  {
5037  pComm = &(pAPIFile[ii]->sCommAPI);
5038  plFileSizeC = (unsigned long *) &(pComm->iFileSize);
5039 
5040  if (iDebug)
5041  {
5042  fprintf(fLogClient, " remote fileId %d:\n", iFileId);
5043  fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
5044  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5045  *plFileSizeC);
5046  }
5047 
5048  /* for caller */
5049  pStatBuf64->st_size = *plFileSizeC;
5050 
5051  free(pAPIFile[iFileId]);
5052  pAPIFile[iFileId] = NULL;
5053  iFileCount--;
5054  }
5055 
5056 
5057  if (iDebug)
5058  fprintf(fLogClient, "-D- end %s\n\n", cModule);
5059 
5060  return iRC;
5061 
5062 } /* rfio_stat64 */
5063 
5064 #endif /* __USE_LARGEFILE64 */
5065 
5066 /********************************************************************
5067  * rfio_stat: for remote file in GSI mass storage
5068  * get file status
5069  *
5070  * created 28. 8.2003, Horst Goeringer
5071  ********************************************************************
5072  */
5073 
5074 int rfio_stat(const char *pcFile, struct stat *pStatBuf)
5075 {
5076  char cModule[32] = "rfio_stat";
5077  int iDebug = 0;
5078 
5079  int iMapFound = 0; /* =1: specified file already open */
5080  int iFileId = -1;
5081  int iRC;
5082  int ii;
5083  char *pcc;
5084  char cObject[MAX_FULL_FILE] = "";
5085 
5086  srawComm *pComm;
5087 
5088  if (iDebug)
5089  printf("\n-D- begin %s\n", cModule);
5090 
5091  iOnlyQuery = 1; /* no DM selection */
5092  ii = 0;
5093  if (iFileCount > 0)
5094  while (ii <= iFileMax)
5095  {
5096  if (pAPIFile[ii] != NULL)
5097  {
5098  pComm = &(pAPIFile[ii]->sCommAPI);
5099  strcpy(cObject, pComm->cNamefs);
5100  strcat(cObject, pComm->cNamehl);
5101  strcat(cObject, pComm->cNamell);
5102 
5103  if (iDebug)
5104  printf(" %d: %s already open\n", ii, cObject);
5105 
5106  pcc = strstr(pcFile, cObject);
5107  if (pcc != NULL)
5108  {
5109  iMapFound = 1;
5110  if (iDebug)
5111  printf(" %d: %s maps\n", ii, cObject);
5112  break;
5113  }
5114  }
5115  else if (iDebug)
5116  printf(" %d: no (more) open file found\n", ii);
5117 
5118  ii++;
5119  }
5120 
5121  if (iMapFound == 0)
5122  {
5123  if (iDebug) printf(
5124  " remote file %s not yet open\n", pcFile);
5125 
5126  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5127  if (iFileId < 0) fprintf(fLogClient,
5128  "-E- %s: open for remote file %s failed\n", cModule, pcFile);
5129  }
5130  else
5131  {
5132  iFileId = pAPIFile[ii]->iFileId;
5133  if (iFileId < 0) fprintf(fLogClient,
5134  "-E- %s: invalid handle (%d) for remote file %s found\n",
5135  cModule, iFileId, pcFile);
5136  }
5137 
5138  /* info still available, must be freed here */
5139  if (iFileId >= 0)
5140  {
5141  pComm = &(pAPIFile[ii]->sCommAPI);
5142  if (iDebug)
5143  {
5144  printf(" remote fileId %d:\n", iFileId);
5145  printf(" object %s%s%s, filesize %ld byte\n",
5146  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5147  pComm->iFileSize);
5148  }
5149 
5150  /* for caller */
5151  pStatBuf->st_size = pComm->iFileSize;
5152 
5153  free(pAPIFile[iFileId]);
5154  pAPIFile[iFileId] = NULL;
5155  iFileCount--;
5156  }
5157 
5158  if (iDebug)
5159  printf("-D- end %s\n\n", cModule);
5160 
5161  if (iFileId >= 0)
5162  return 0;
5163  else
5164  return iFileId;
5165 
5166 } /* rfio_stat */
5167 
5168 /********************************************************************
5169  * rfio_cache_stat: for remote file in GSI mass storage
5170  * returns cache status of file:
5171  * < 0: not in gStore or error
5172  * = 0: in offline storage, staging before access strongly recommended
5173  * > 0: available for fast access
5174  * = 1: in read cache (staged)
5175  * = 2: in write cache, staging before access recommended
5176  * (users do not know when migration to offline storage
5177  * takes place)
5178  *
5179  * created 12.11.2008, Horst Goeringer
5180  ********************************************************************
5181  */
5182 
5183 int rfio_cache_stat(const char *pcFile)
5184 {
5185  char cModule[32] = "rfio_cache_stat";
5186  int iDebug = 0;
5187 
5188  int iMapFound = 0; /* =1: specified file already open */
5189  int iFileId = -1;
5190  int iRC;
5191  int iCache = 0; /* to be returned */
5192  int ii;
5193  char *pcc;
5194  char cObject[MAX_FULL_FILE] = "";
5195 
5196  srawComm *pComm;
5197 
5198  if (iDebug)
5199  {
5200  printf("\n-D- begin %s: %d files open\n", cModule, iFileCount);
5201  printf(" get cache status of file %s\n", pcFile);
5202  }
5203 
5204  iOnlyQuery = 1; /* no DM selection */
5205  ii = 0;
5206  if (iFileCount > 0)
5207  while (ii <= iFileMax)
5208  {
5209  if (pAPIFile[ii] != NULL)
5210  {
5211  pComm = &(pAPIFile[ii]->sCommAPI);
5212  strcpy(cObject, pComm->cNamefs);
5213  strcat(cObject, pComm->cNamehl);
5214  strcat(cObject, pComm->cNamell);
5215 
5216  if (iDebug)
5217  printf(" %d: %s already open\n", ii, cObject);
5218 
5219  pcc = strstr(pcFile, cObject);
5220  if (pcc != NULL)
5221  {
5222  iMapFound = 1;
5223  if (iDebug)
5224  printf(" %d: %s maps\n", ii, cObject);
5225  break;
5226  }
5227  }
5228  else if (iDebug)
5229  printf(" %d: no (more) open file found\n", ii);
5230 
5231  ii++;
5232  }
5233 
5234  if (iMapFound == 0)
5235  {
5236  if (iDebug) printf(
5237  " remote file %s not yet open\n", pcFile);
5238 
5239  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5240  if (iFileId < 0)
5241  {
5242  fprintf(fLogClient,
5243  "-E- remote file %s not in gStore or unavailable\n",
5244  pcFile);
5245 
5246  iCache = -1;
5247  goto gEndCacheStat;
5248  }
5249 
5250  if (iDebug) printf(
5251  " remote file %s successfully opened for query and closed\n", pcFile);
5252  }
5253  else
5254  {
5255  iFileId = pAPIFile[ii]->iFileId;
5256  if (iFileId < 0)
5257  {
5258  fprintf(fLogClient,
5259  "-E- %s: invalid handle (%d) for remote file %s found\n",
5260  cModule, iFileId, pcFile);
5261 
5262  iCache = -1;
5263  goto gEndCacheStat;
5264  }
5265  }
5266 
5267  /* info still available, must be freed here */
5268  if (iFileId >= 0)
5269  {
5270  pComm = &(pAPIFile[ii]->sCommAPI);
5271  if (pComm->iStageFSid > 0)
5272  iCache = 1; /* file in read cache */
5273  else if (pComm->iFSidWC > 0)
5274  iCache = 2; /* file in write cache */
5275  else
5276  iCache = 0; /* file not in cache */
5277 
5278  if (iDebug)
5279  {
5280  printf(" remote fileId %d:\n", iFileId);
5281  printf(" object %s%s%s, size %ld byte, cache status %d\n",
5282  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5283  pComm->iFileSize, iCache);
5284  if (pComm->iStageFSid > 0)
5285  printf(" read cache FS %d\n", pComm->iStageFSid);
5286  else if (pComm->iFSidWC > 0)
5287  printf(" write cache FS %d\n", pComm->iFSidWC);
5288  }
5289 
5290  free(pAPIFile[iFileId]);
5291  pAPIFile[iFileId] = NULL;
5292  iFileCount--;
5293  }
5294 
5295 gEndCacheStat:
5296  iOnlyQuery = 0;
5297  if (iDebug)
5298  printf("-D- end %s\n\n", cModule);
5299 
5300  return iCache;
5301 
5302 } /* rfio_cache_stat */
5303 
5304 /********************************************************************
5305  * rfio_gsi_query: query file information of opened remote file
5306  *
5307  * created 7. 2.2001, Horst Goeringer
5308  ********************************************************************
5309  */
5310 
5311 int rfio_gsi_query(int iFileId, /* file id */
5312  int iFull, /* verbosity */
5313  int iOut, /* max length output string */
5314  char *pInfo) /* info string */
5315 {
5316  char cModule[32] = "rfio_gsi_query";
5317  int iDebug = 0;
5318  int iRC = 0;
5319  int ii = 0;
5320 
5321  srawAPIFile *pcurAPIFile;
5322  srawObjAttr *pQueryAPI; /* query information */
5323 
5324  if (iDebug)
5325  printf("\n-D- begin %s\n", cModule);
5326 
5327  if (iFileCount == 0)
5328  {
5329  printf("-E- %s: no remote file available\n", cModule);
5330  iRC = -1;
5331  goto gEndQuery;
5332  }
5333 
5334  while (ii < iFileMax)
5335  {
5336  if (pAPIFile[ii])
5337  {
5338  if (pAPIFile[ii]->iFileId == iFileId)
5339  break;
5340  }
5341  ii++;
5342  }
5343 
5344  if (ii == iFileMax)
5345  {
5346  printf("-E- %s: remote file %d not found\n", cModule, iFileId);
5347  iRC = -1;
5348  goto gEndQuery;
5349  }
5350 
5351  pcurAPIFile = pAPIFile[iFileId];
5352  pQueryAPI = &(pcurAPIFile->sQueryAPI);
5353  iRC = rawQueryString(pQueryAPI, iFull, iOut, pInfo);
5354  if (iDebug)
5355  {
5356  printf(" %s\n", pInfo);
5357  if (iRC != iOut) printf(
5358  " (used %d byte, avail %d byte)\n", iRC, iOut);
5359  }
5360 
5361 gEndQuery:
5362  if (iDebug)
5363  printf("-D- end %s\n\n", cModule);
5364 
5365  return iRC;
5366 
5367 } /* rfio_gsi_query */
5368 
int iAction
Definition: rawcommn.h:399
int iIdent
Definition: rawcommn.h:398
unsigned int iObjHigh
Definition: rawcommn.h:534
ssize_t rfio_read(int iFileId, char *pcBuffer, size_t iItems)
Definition: rawapin.c:2530
char cNodeWC[MAX_NODE]
Definition: rawcommn.h:428
#define MAXLOOP_CACHE_FULL
Definition: rawcommn.h:215
int rfio_endfile(int iFileId)
Definition: rawapin.c:2395
#define PORT_MASTER
Definition: rawcommn.h:195
int iBufsizeFile
Definition: rawcommn.h:526
int rfio_open(const char *pcFile, int iFlags, int iOpenMode)
Definition: rawapin.c:275
char cApplType[MAX_APPLTYPE]
Definition: rawcommn.h:406
int iSockMover
Definition: rawclin.h:148
char cOS[MAX_OS]
Definition: rawcommn.h:656
char cNodeCacheMgr[MAX_NODE]
Definition: rawcommn.h:421
#define MAX_OBJ_LL
Definition: rawcommn.h:266
int rawGetLLName(char *, const char *, char *)
Definition: rawProcn.c:735
int iOpMode
Definition: rawclin.h:152
#define MAX_OBJ_FS
Definition: rawcommn.h:263
char cDateCreate[MAX_DATE]
Definition: rawcommn.h:529
int iBufsizeFile
Definition: rawcommn.h:408
int tSvcClassKey
Definition: rawapin.c:192
int rawSendRequest(int, int, int, int)
Definition: rawProcn.c:2042
#define GSI_MEDIA_LOCKED
Definition: rawapitd-gsin.h:24
#define SLEEP_CACHE_FULL
Definition: rawcommn.h:214
int rfio_unlink(const char *pcFile)
Definition: rawapin.c:4809
static int irawComm
Definition: rawapin.c:201
unsigned int iObjHigh
Definition: rawcommn.h:412
static const char * pcStar
Definition: rawdefn.h:64
static int iSleepCacheFull
Definition: rawapin.c:219
char cOwner[MAX_OWNER]
Definition: rawcommn.h:530
int rfio_fstat(int iFileId, struct stat *pStatBuf)
Definition: rawapin.c:4646
static int irawAPIFile
Definition: rawapin.c:205
int iStatus
Definition: rawcommn.h:471
unsigned int iObjLow
Definition: rawcommn.h:535
int rfio_parse(char *pcFile, char **pcNode, char **pcPath)
Definition: rawapin.c:4727
static char rfio_errmsg[STATUS_LEN]
Definition: rawapin.c:197
#define DSM_MAX_OWNER_LENGTH
Definition: rawapitd.h:15
int rfio_mkdir(const char *path, int mode)
Definition: rawapin.c:4856
#define MAX_ATLSERVER
Definition: rawcommn.h:202
void rfio_perror(const char *pUMsg)
Definition: rawapin.c:4752
#define IDENT_COPY_CACHE
Definition: rawcommn.h:309
int rfio_open_gsidaq(const char *pcFile, int iFlags, int iOpenMode, int iCopyMode, char *pcCopyPath, int iCopyFraction, int iMaxFile, int iPathConvention)
Definition: rawapin.c:314
int iATLServer
Definition: rawcommn.h:541
#define MAX_LOG_FILE
Definition: rawapin.c:160
int iWaitTime
Definition: rawcommn.h:417
char cNodeMover[MAX_NODE]
Definition: rawclin.h:147
int rfio_newfile(int iFileId, char *pcFile)
Definition: rawapin.c:3017
char cNamefs[MAX_OBJ_FS]
Definition: rawcommn.h:401
srawComm sCommAPI
Definition: rawclin.h:162
#define GSI_CACHE_LOCKED
Definition: rawapitd-gsin.h:28
int iPoolIdRC
Definition: rawcommn.h:424
unsigned int iFileSize
Definition: rawcommn.h:409
ssize_t rfio_write(int iFileId, const char *pcBuffer, size_t iItems)
Definition: rawapin.c:2843
char cCopyPath[MAX_FULL_FILE]
Definition: rawcommn.h:676
static char cNodeMover[MAX_NODE]
Definition: rawapin.c:211
static int iStatusLoopMax
Definition: rawapin.c:217
int rfio_cache_stat(const char *pcFile)
Definition: rawapin.c:5183
int iBufnoServ
Definition: rawclin.h:160
static char cPrefix[MAX_FULL_FILE]
Definition: rawapin.c:208
RFILE * rfio_fopen(char *pcFile, char *pcOptions)
Definition: rawapin.c:4003
#define RFILE
Definition: rawapigsi.h:17
int rawSendStatus(int, int, char *)
Definition: rawProcn.c:2112
int iPoolId
Definition: rawcommn.h:543
unsigned int iFileSize
Definition: rawcommn.h:527
static char cNodeMaster[MAX_NODE]
Definition: rawapin.c:210
static int iPortMaster
Definition: rawapin.c:212
static const char * pcQM
Definition: rawdefn.h:65
#define GSI_MEDIA_CACHE
Definition: rawapitd-gsin.h:27
FILE * fLogClient
Definition: rawapin.c:159
int rfio_lseek(int iFileId, int ilocOffset, int ilocSeekMode)
Definition: rawapin.c:3940
static int iOS64
Definition: rawapin.c:163
int tCastorVersionKey
Definition: rawapin.c:193
int rawQueryString(srawObjAttr *pQAttr, int ipMode, int iOut, char *pcOut)
Definition: rawCliProcn.c:3458
int iPoolIdWC
Definition: rawcommn.h:427
int tStagePortKey
Definition: rawapin.c:191
int iSeekMode
Definition: rawclin.h:149
int rfiosetopt(int iopt, int *pival, int ilen)
Definition: rawapin.c:4834
int iSockMaster
Definition: rawclin.h:146
size_t rfio_fwrite(const char *pcBuffer, size_t iSize, size_t iItems, RFILE *pRemFile)
Definition: rawapin.c:4346
srawCopyCache sCopyCacheServ
Definition: rawclin.h:165
char * rawGetHLName(char *)
Definition: rawProcn.c:656
int iStageFSid
Definition: rawcommn.h:426
int rawQueryFile(int, int, srawComm *, void **)
Definition: rawProcn.c:945
int rfio_fendfile(RFILE *pRemFile)
Definition: rawapin.c:4386
int iATLServer
Definition: rawcommn.h:422
static int iint
Definition: rawapin.c:200
char cDataFS[MAX_FULL_FILE]
Definition: rawcommn.h:433
char cNodeRC[MAX_NODE]
Definition: rawcommn.h:425
static const char * pcPerc
Definition: rawdefn.h:66
static int iOnlyQuery
Definition: rawapin.c:207
static char cLogClient[MAX_LOG_FILE]
Definition: rawapin.c:161
unsigned int iObjLow
Definition: rawcommn.h:413
unsigned int iFileSize2
Definition: rawcommn.h:410
static char cDataFSHigh2[16]
Definition: rawcommn.h:233
#define MAX_NODE
Definition: rawcommn.h:225
#define MAX_FULL_FILE
Definition: rawcommn.h:255
static char cApplType[MAX_APPLTYPE]
Definition: rawapplcli.h:16
static char cNodePrefix[MAX_NODE]
Definition: rawapin.c:209
static char cNamefs[MAX_OBJ_FS]
Definition: rawProcn.c:164
int * piEntryList
Definition: rawapin.c:183
char cliNode[MAX_NODE]
Definition: rawcommn.h:414
#define STATUS_LEN
Definition: rawcommn.h:284
int imySigS
Definition: rawapin.c:184
char cNodeMaster[MAX_NODE]
Definition: rawclin.h:145
char cOS[MAX_OS]
Definition: rawcommn.h:405
int rfio_errno
Definition: rawapin.c:189
int rconnect(char *, int, int *, int *)
Definition: rconnect.c:58
static int iObjAttr
Definition: rawapin.c:202
#define GSI_MEDIA_STAGE
Definition: rawapitd-gsin.h:23
int iPathConvention
Definition: rawcommn.h:695
char * rawGetFSpName(char *)
Definition: rawProcn.c:599
int iCommLen
Definition: rawcommn.h:400
size_t rfio_fread(char *pcBuffer, size_t iSize, size_t iItems, RFILE *pRemFile)
Definition: rawapin.c:4308
static char cNamehl[MAX_OBJ_HL]
Definition: rawProcn.c:165
char cNode[MAX_NODE]
Definition: rawcommn.h:554
static int iPortMover
Definition: rawapin.c:213
#define IDENT_COMM
Definition: rawcommn.h:289
int iAction
Definition: rawclin.h:156
char cNode[MAX_NODE]
Definition: rawcommn.h:637
static int irawCopyCache
Definition: rawapin.c:204
int rawRecvError(int, int, char *)
Definition: rawProcn.c:1285
static char cDataFSHigh1[16]
Definition: rawcommn.h:232
static char cNodeMaster0[MAX_NODE]
Definition: rawcommn.h:226
static int iFileMax
Definition: rawapin.c:222
#define ATLSERVER_ARCHIVE
Definition: rawcommn.h:201
char * rawGetUserid()
Definition: rawProcUn.c:1827
int iCopyFraction
Definition: rawcommn.h:682
int iFileType
Definition: rawcommn.h:525
int iFSidWC
Definition: rawcommn.h:429
int iDataFS
Definition: rawcommn.h:432
int iClient32
Definition: rawcommn.h:434
int rfio_access(const char *pcFile, int iMode)
Definition: rawapin.c:4443
char * rfio_serror()
Definition: rawapin.c:4780
char cTapeLib[16]
Definition: rawcommn.h:420
static int iLogFile
Definition: rawapin.c:162
int iMediaClass
Definition: rawcommn.h:533
int iOffset
Definition: rawclin.h:150
#define HEAD_LEN
Definition: rawcommn.h:283
int iSynchId
Definition: rawcommn.h:418
RFILE * rfio_fopen_gsidaq_dm(char *pcFile, char *pcOptions, char *pcDataMover, int *piDataMover, int iCopyMode, char *pcCopyPath, int iCopyFraction, int iMaxFile, int iPathConvention)
Definition: rawapin.c:4043
char cArchiveDate[MAX_DATE]
Definition: rawcommn.h:659
void * rfio_readdir(void *dirp)
Definition: rawapin.c:4906
srawObjAttr sQueryAPI
Definition: rawclin.h:164
int iFileId
Definition: rawclin.h:142
char cNamell[MAX_OBJ_LL]
Definition: rawcommn.h:403
unsigned int iFileSize2
Definition: rawcommn.h:528
srawObjAttr objAttr
Definition: rawcommn.h:567
int rfio_close(int iFileId)
Definition: rawapin.c:3717
int tStageHostKey
Definition: rawapin.c:190
#define GSI_MEDIA_INCOMPLETE
Definition: rawapitd-gsin.h:25
int rfio_stat(const char *pcFile, struct stat *pStatBuf)
Definition: rawapin.c:5074
int rawRecvStatus(int, char *)
Definition: rawProcn.c:1903
#define PORT_MOVER_DATAFS
Definition: rawcommn.h:197
#define PORT_MOVER
Definition: rawcommn.h:196
static RFILE * pAPIFile[10]
Definition: rawapin.c:223
int rfio_closedir(void *dirp)
Definition: rawapin.c:4931
static int irawFileSystem
Definition: rawapin.c:203
char cArchiveUser[MAX_OWNER]
Definition: rawcommn.h:660
int rfio_gsi_query(int iFileId, int iFull, int iOut, char *pInfo)
Definition: rawapin.c:5311
int iExecStatus
Definition: rawcommn.h:415
static int iFileCount
Definition: rawapin.c:221
int iFileType
Definition: rawcommn.h:407
int iBufsizeAct
Definition: rawclin.h:151
void * rfio_opendir(const char *dirpath)
Definition: rawapin.c:4881
int rawRecvHeadC(int, char *, int, int, char *)
Definition: rawProcn.c:1494
char cNode[MAX_NODE]
Definition: rawcommn.h:657
#define GSI_CACHE_INCOMPLETE
Definition: rawapitd-gsin.h:29
int iMassSto
Definition: rawclin.h:157
#define PORT_RFIO_SERV
Definition: rawcommn.h:199
int iMode
Definition: rawclin.h:144
#define IDENT_STATUS
Definition: rawcommn.h:290
int serrno
Definition: rawapin.c:188
int iDataServ
Definition: rawclin.h:161
int iFlags
Definition: rawclin.h:143
char cStatus[STATUS_LEN]
Definition: rawcommn.h:473
#define MAX_OBJ_HL
Definition: rawcommn.h:265
int iArchDev
Definition: rawcommn.h:411
static const char * pcDevDelim
Definition: rawdefn.h:31
static int iATLServer
Definition: rawapin.c:214
int rfio_fclose(RFILE *pRemFile)
Definition: rawapin.c:4415
char cOwner[MAX_OWNER]
Definition: rawcommn.h:404
RFILE * rfio_fopen_gsidaq(char *pcFile, char *pcOptions, int iCopyMode, char *pcCopyPath, int iCopyFraction, int iMaxFile, int iPathConvention)
Definition: rawapin.c:4152
FILE * fLogFile
Definition: rawapin.c:185
srawComm sCommServ
Definition: rawclin.h:163
char cNamehl[MAX_OBJ_HL]
Definition: rawcommn.h:402
int rfio_fnewfile(RFILE *pRemFile, char *pcFile)
Definition: rawapin.c:4239