GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 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, "%s", sStatus.cStatus);
2480  } else {
2481  fprintf(fLogClient,
2482  "-W- %s: message received from server:\n", cModule);
2483  fprintf(fLogClient, "%s", sStatus.cStatus);
2484 
2485  if (iStatus != STA_CACHE_COPY_ERROR)
2486  {
2487  iRC = -1;
2488  goto gErrorEndFile;
2489  }
2490  }
2491  } /* (iRC > HEAD_LEN) */
2492 
2493  if (pcurAPIFile->iMassSto)
2494  {
2495  if ( (pcurAPIFile->iOpMode != 2) && /* no display mode */
2496  (iDebug) )
2497  fprintf(fLogClient,
2498  "-I- gStore file %s%s%s closed\n",
2499  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
2500  }
2501  else fprintf(fLogClient,
2502  "-I- remote output file %s%s%s closed\n",
2503  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
2504 
2505  } /* (iSockMover >= 0) */
2506 
2507  if (iDebug)
2508  {
2509  printf(
2510  " remote file control block %d still active (overall %d)\n",
2511  iFileId, iFileCount);
2512  printf("-D- end %s\n\n", cModule);
2513  }
2514 
2515  iRC = 0;
2516 
2517 gErrorEndFile:
2518  return iRC;
2519 
2520 } /* rfio_endfile */
2521 
2522 /*********************************************************************
2523  * rfio_read: read remote file in GSI mass storage
2524  *
2525  * created 4.12.2000, Horst Goeringer
2526  *********************************************************************
2527  */
2528 
2529 ssize_t rfio_read(int iFileId, /* file id */
2530  char *pcBuffer, /* data buffer */
2531  size_t iItems) /* number of data bytes */
2532 {
2533  char cModule[32] = "rfio_read";
2534  int iDebug = 0;
2535  int iRC;
2536 
2537  int iSockMover; /* socket for connection to mover */
2538  int iSeekMode;
2539  int iOffset;
2540  int iBufsizeRead;
2541  int iBufnoServ; /* no. of buffers transfered from/to server */
2542  int iDataServ; /* no. of bytes transfered from/to server */
2543 
2544  int iStatus;
2545  int iStatusLen;
2546  int iBufsizeRecv;
2547 
2548  char *pcc;
2549  int ii = 0;
2550  int iBuf, iBufl;
2551  int *pint;
2552 
2553  srawAPIFile *pcurAPIFile;
2554  srawComm *pCommAPI; /* communication buffer in API control block */
2555  srawComm *pCommServ; /* copy for servers in net format */
2556 
2557  if (iDebug)
2558  printf("\n-D- begin %s: fileId %d\n", cModule, iFileId);
2559 
2560  if (iFileCount == 0)
2561  {
2562  fprintf(fLogClient, "-E- %s: no remote file open for read\n", cModule);
2563  return -1;
2564  }
2565 
2566  while (ii < iFileMax)
2567  {
2568  if (pAPIFile[ii])
2569  {
2570  if (pAPIFile[ii]->iFileId == iFileId)
2571  break;
2572  }
2573  ii++;
2574  }
2575 
2576  if (ii == iFileMax)
2577  {
2578  fprintf(fLogClient, "-E- %s: remote file %d cannot be read: not opened\n",
2579  cModule, iFileId);
2580  return -1;
2581  }
2582 
2583  if (iDebug)
2584  printf(" open buffer %d, fileId %d\n", ii, iFileId);
2585 
2586  pcurAPIFile = pAPIFile[iFileId];
2587  pCommAPI = &(pcurAPIFile->sCommAPI);
2588  pCommServ = &(pcurAPIFile->sCommServ);
2589 
2590  iBufnoServ = pcurAPIFile->iBufnoServ;
2591  iDataServ = pcurAPIFile->iDataServ;
2592 
2593  iBufnoServ++;
2594  if (iDebug)
2595  {
2596  printf(" remote file control block %d selected\n", ii);
2597  printf(" file %d, buffer %d: read %d bytes\n",
2598  iFileId, iBufnoServ, (int) iItems);
2599  }
2600 
2601  iBufsizeRead = pcurAPIFile->iBufsizeAct;
2602  if (iDebug)
2603  {
2604  if (iBufsizeRead != iItems)
2605  printf( " new buffer size %d\n", (int) iItems);
2606  printf(" send request for new buffer\n");
2607  }
2608 
2609  iSockMover = pcurAPIFile->iSockMover;
2610  iSeekMode = pcurAPIFile->iSeekMode;
2611  iOffset = pcurAPIFile->iOffset;
2612  iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, (int) iItems);
2613  if (iRC != 0)
2614  {
2615  fprintf(fLogClient, "-E- %s: sending request for next data buffer\n",
2616  cModule);
2617  return -1;
2618  }
2619 
2620  /* reset seek options to default (no seek) */
2621  if (iSeekMode != -1)
2622  {
2623  pcurAPIFile->iSeekMode = -1;
2624  pcurAPIFile->iOffset = 0;
2625  }
2626 
2627  pcurAPIFile->iBufsizeAct = (int) iItems; /* keep current value */
2628 
2629  /********************** retrieve next buffer **********************/
2630 
2631  /* get size retrieve buffer */
2632  pcc = (char *) &iBufsizeRecv;
2633  iBuf = iint;
2634  while(iBuf > 0)
2635  {
2636 gRetryLen:
2637  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2638  {
2639  fprintf(fLogClient,
2640  "-E- %s: receiving data length from server (buffer %d)",
2641  cModule, iBufnoServ);
2642  perror("");
2643  goto gRetryLen;
2644  }
2645 
2646  if (iRC == 0)
2647  {
2648  ii = iint - iBuf;
2649  fprintf(fLogClient,
2650  "-E- %s: connection to sender broken, %d byte of data length (%d byte) received (buffer %d)\n",
2651  cModule, ii, iint, iBufnoServ);
2652 
2653  return -1;
2654  }
2655 
2656  iBuf -= iRC;
2657  pcc += iRC;
2658 
2659  if (iDebug == 2)
2660  {
2661  printf("%d.", iRC);
2662  fflush(stdout);
2663  }
2664  } /* recv loop data length */
2665 
2666  iBufsizeRecv = ntohl(iBufsizeRecv);
2667  if (iDebug == 2)
2668  printf("%d_", iBufsizeRecv);
2669 
2670  if (iBufsizeRecv < 0)
2671  {
2672  if (iBufsizeRecv != IDENT_STATUS)
2673  {
2674  fprintf(fLogClient, "-E- %s: invalid status header received (%d)\n",
2675  cModule, iBufsizeRecv);
2676  return -1;
2677  }
2678  if (iDebug)
2679  printf("-D- status header found\n");
2680 
2681  /* receive remainder of status header */
2682  pcc = pcBuffer;
2683  iBuf = HEAD_LEN - 4; /* iIdent already read */
2684  iBufl = iBuf;
2685  while(iBuf > 0) /* get remainder of status header */
2686  {
2687  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2688  {
2689  fprintf(fLogClient,
2690  "-E- %s: receiving remainder of status header from server (buffer %d)",
2691  cModule, iBufnoServ);
2692  perror(" ");
2693 
2694  return -1;
2695  }
2696 
2697  if (iRC == 0)
2698  {
2699  ii = iBufl - iBuf;
2700  fprintf(fLogClient,
2701  "-W- %s: connection to sender broken, %d byte of remainder of status header (%d byte) received (buffer %d)\n",
2702  cModule, ii, iBufl, iBufnoServ);
2703 
2704  return -1;
2705  }
2706 
2707  if (iDebug == 2)
2708  printf("%d.", iRC);
2709 
2710  iBuf -= iRC;
2711  pcc += iRC;
2712  }
2713 
2714  pint = (int *) pcBuffer; /* points to status word */
2715  iStatus = ntohl(*pint); /* status received */
2716  if ( (iStatus != STA_END_OF_FILE) &&
2717  (iStatus != STA_END_OF_SESSION) &&
2718  (iStatus != STA_ERROR) &&
2719  (iStatus != STA_ERROR_EOF) )
2720  {
2721  fprintf(fLogClient, "-E- %s: unexpected status from server: %d\n",
2722  cModule, iStatus);
2723  return -1;
2724  }
2725 
2726  if ( (iStatus == STA_END_OF_FILE) ||
2727  (iStatus == STA_END_OF_SESSION) )
2728  {
2729  if (iDebug) printf(" EOF on input\n");
2730 
2731  if (iDataServ == 0) /* empty file */
2732  {
2733  fprintf(fLogClient, "-E- %s: %s%s%s empty\n",
2734  cModule, pCommServ->cNamefs,
2735  pCommServ->cNamehl, pCommServ->cNamell);
2736  return -1;
2737  }
2738  else return 0;
2739  }
2740  else
2741  {
2742  pint++; /* points to status size */
2743  iStatusLen = ntohl(*pint);
2744  if (iStatusLen > 0)
2745  {
2746  iRC = rawRecvError(iSockMover, iStatusLen, pcc);
2747  if (iRC < 0)
2748  {
2749  fprintf(fLogClient,
2750  "-E- %s: receiving status message from server, rc = %d\n",
2751  cModule, iRC);
2752  return -1;
2753  }
2754 
2755  if ( (iStatus == STA_ERROR) ||
2756  (iStatus == STA_ERROR_EOF) )
2757  {
2758  fprintf(fLogClient,
2759  "-E- %s: received error status from server:\n",
2760  cModule);
2761  fprintf(fLogClient, "%s\n", pcc);
2762  return -1;
2763  }
2764 
2765  /* warning from server */
2766  printf("%s\n", pcc);
2767 
2768  } /* (iStatusLen > 0) */
2769  } /* (iStatus != STA_END_OF_FILE) &&
2770  (iStatus != STA_END_OF_SESSION) */
2771  } /* (iBufsizeRecv < 0) */
2772  else if (iBufsizeRecv != iItems)
2773  {
2774  if (iDebug)
2775  {
2776  if (iBufsizeRecv)
2777  printf("-W- requested %d bytes, received buffer length %d bytes\n", (int)iItems, iBufsizeRecv);
2778  else
2779  printf("-W- EOF reached\n");
2780  }
2781  iItems = (size_t) iBufsizeRecv;
2782  }
2783 
2784  /* recv loop over buffers of size iBufsizeRecv */
2785  iBuf = iBufsizeRecv;
2786  pcc = pcBuffer;
2787  while(iBuf > 0)
2788  {
2789 gRetryData:
2790  if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
2791  {
2792  if (iDebug) fprintf(fLogClient,
2793  "-E- %s: receiving data from server (buffer %d)\n",
2794  cModule, iBufnoServ);
2795  perror("EEE ");
2796  goto gRetryData;
2797  }
2798 
2799  if (iRC == 0)
2800  {
2801  ii = iBufsizeRecv - iBuf;
2802  fprintf(fLogClient,
2803  "-W- %s: connection to sender broken, %d byte of data buffer (%d byte) received (buffer %d)\n",
2804  cModule, ii, iBufsizeRecv, iBufnoServ);
2805 
2806  return -1;
2807  }
2808 
2809  if (iDebug == 2)
2810  {
2811  printf("%d:", iRC);
2812  fflush(stdout);
2813  }
2814 
2815  iBuf -= iRC;
2816  pcc += iRC;
2817  pcurAPIFile->iDataServ += iRC;
2818 
2819  } /* while(iBuf > 0) */
2820 
2821  if (iBufsizeRecv)
2822  {
2823  pcurAPIFile->iBufnoServ++;
2824  if (iDebug == 2)
2825  printf(" buffer %d received\n", pcurAPIFile->iBufnoServ);
2826  }
2827 
2828  if (iDebug)
2829  printf("-D- end %s\n\n", cModule);
2830 
2831  return iBufsizeRecv;
2832 
2833 } /* rfio_read */
2834 
2835 /*********************************************************************
2836  * rfio_write: write remote file in GSI mass storage
2837  *
2838  * created 4.12.2000, Horst Goeringer
2839  *********************************************************************
2840  */
2841 
2842 ssize_t rfio_write(int iFileId, /* file id */
2843  const char *pcBuffer, /* data buffer */
2844  size_t iItems) /* number of data bytes */
2845 {
2846  char cModule[32] = "rfio_write";
2847  int iDebug = 0;
2848 
2849  int iRC;
2850  char *pcc;
2851  int ii = 0;
2852  int iBuf;
2853 
2854  int iSockMover; /* socket for connection to mover */
2855  int iBufsizeWrite;
2856  int iBufnoServ; /* no. of buffers transfered from/to server */
2857 
2858  srawAPIFile *pcurAPIFile;
2859 
2860  srawComm *pCommAPI;
2861  srawComm *pCommServ; /* copy for servers in net format */
2862 
2863  if (iDebug)
2864  {
2865  printf("\n-D- begin %s\n", cModule);
2866  fflush(stdout);
2867  }
2868 
2869  if (iItems <= 0)
2870  {
2871  fprintf(fLogClient,
2872  "-W- invalid no. of bytes to write: %d\n", (int) iItems);
2873  return 0;
2874  }
2875 
2876  if (iFileCount == 0)
2877  {
2878  fprintf(fLogClient, "-E- %s: no remote file open for write\n", cModule);
2879  return -1;
2880  }
2881 
2882  ii = 0;
2883  while (ii < iFileMax)
2884  {
2885  if (pAPIFile[ii])
2886  {
2887  if (pAPIFile[ii]->iFileId == iFileId)
2888  break;
2889  }
2890  ii++;
2891  }
2892 
2893  if (ii == iFileMax)
2894  {
2895  fprintf(fLogClient,
2896  "-E- %s: remote file %d cannot be written: not opened\n",
2897  cModule, iFileId);
2898  return -1;
2899  }
2900 
2901  pcurAPIFile = pAPIFile[iFileId];
2902  pCommServ = &(pcurAPIFile->sCommServ);
2903  pCommAPI = &(pcurAPIFile->sCommAPI);
2904 
2905  iBufnoServ = pcurAPIFile->iBufnoServ;
2906  iBufnoServ++;
2907 
2908  if (iDebug)
2909  {
2910  printf(" remote file control block %d selected\n", ii);
2911  printf(" file %d, buffer %d: write %d bytes\n",
2912  iFileId, iBufnoServ, (int) iItems);
2913  }
2914 
2915  if (iItems > pCommAPI->iBufsizeFile)
2916  {
2917  pCommAPI->iBufsizeFile = (int) iItems;
2918  pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
2919  }
2920 
2921  if (iDebug)
2922  {
2923  if (pcurAPIFile->iBufsizeAct != iItems)
2924  printf( " new buffer size %d\n", (int) iItems);
2925  printf(" send new buffer\n");
2926  }
2927 
2928 
2929  /*********************** write next buffer ************************/
2930 
2931  iSockMover = pcurAPIFile->iSockMover;
2932  pcurAPIFile->iBufsizeAct = (int) iItems; /* keep current value */
2933  iBufsizeWrite = htonl( (int) iItems);
2934  iBuf = iint;
2935  pcc = (char *) &iBufsizeWrite;
2936  while (iBuf)
2937  {
2938  iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
2939  if (iRC <= 0)
2940  {
2941  if (iRC == 0) fprintf(fLogClient,
2942  "-E- %s: sending data length to server broken\n", cModule);
2943  else
2944  {
2945  fprintf(fLogClient,
2946  "-E- %s: sending data length to server (buffer %d)",
2947  cModule, iBufnoServ);
2948  perror(" ");
2949  }
2950  return -1;
2951  }
2952 
2953  iBuf -= iRC;
2954  pcc += iRC;
2955 
2956  if (iDebug == 2)
2957  {
2958  printf("%d(%d)_", iRC, (int) iItems);
2959  fflush(stdout);
2960  }
2961 
2962  } /* while (iBuf) */
2963 
2964  iBuf = (int) iItems;
2965  pcc = (char *) pcBuffer;
2966  while (iBuf)
2967  {
2968  iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
2969  if (iRC <= 0)
2970  {
2971  if (iRC == 0) fprintf(fLogClient,
2972  "-E- %s: sending data to server broken\n", cModule);
2973  else
2974  {
2975  fprintf(fLogClient,
2976  "-E- %s: sending data to server (buffer %d, %d bytes)",
2977  cModule, iBufnoServ, iBuf);
2978  perror(" ");
2979  }
2980  return -1;
2981  }
2982 
2983  iBuf -= iRC;
2984  pcc += iRC;
2985  pcurAPIFile->iDataServ += iRC;
2986 
2987  if (iDebug == 2)
2988  {
2989  printf("%d.", iRC);
2990  fflush(stdout);
2991  }
2992 
2993  } /* while (iBuf) */
2994 
2995  if (iItems)
2996  {
2997  pcurAPIFile->iBufnoServ++;
2998  if (iDebug == 2)
2999  printf(" buffer %d sent\n", pcurAPIFile->iBufnoServ);
3000  }
3001 
3002  if (iDebug)
3003  printf("-D- end %s\n", cModule);
3004 
3005  return (ssize_t) iItems;
3006 
3007 } /* rfio_write */
3008 
3009 /*********************************************************************
3010  * rfio_newfile: continue with next remote file in GSI mass storage
3011  *
3012  * created 2. 8.2004, Horst Goeringer
3013  *********************************************************************
3014  */
3015 
3016 int rfio_newfile(int iFileId,
3017  char *pcFile) /* file name */
3018 {
3019  char cModule[32] = "rfio_newfile";
3020  int iDebug = 0;
3021  int iRC;
3022  int ii = 0;
3023  int iArchLen = 0;
3024  int iPathLen = 0;
3025  int iFileLen = 0;
3026  int iCopyMode = 0; /* >0: write data to WC and dataFS */
3027  int iCopyLen = 0; /* >0: copy parameters already sent to DM */
3028  int iCopyBuffer = 0; /* >0: send copy parameters now to DM */
3029 
3030  int iMassSto = -1;/* =1: connect to GSI mass storage (ArchivePool)
3031  =2: connect to GSI mass storage (DAQPool)
3032  =0: connect to RFIO read/write server */
3033  int iMaxConnect = 0; /* try connection to servers once */
3034  int iSockMover; /* socket for connection to mover */
3035  char cNodeMover[MAX_NODE] = "";
3036  int inewPath = 0;
3037  int iError = 0;
3038  int iStatus = 0;
3039  int iStatusOkay = 0;
3040  int iStatusLoop = 0;
3041 
3042  char *pcc, *pcc1, *pcc2;
3043  char cTemp[STATUS_LEN] = "";
3044 
3045  char cNamefs[MAX_OBJ_FS] = "", *pcNamefs; /* filespace name */
3046  char cNamehl[MAX_OBJ_HL] = "", *pcNamehl; /* high level name */
3047  char cNamell[MAX_OBJ_LL] = "", *pcNamell; /* low level name */
3048 
3049  srawStatus sStatus;
3050  void *pBufQuery;
3051  srawQueryResult sQuery;
3052  srawObjAttr *pQAttr;
3053 
3054  srawAPIFile *pcurAPIFile;
3055  srawComm *pCommAPI; /* communication buffer in API control block */
3056  srawComm *pCommServ; /* copy for servers in net format */
3057  srawCopyCache *pCopyCacheServ;
3058  /* infos in net format for copy of WC data */
3059 
3060  pcNamefs = cNamefs;
3061  pcNamehl = cNamehl;
3062  pcNamell = cNamell;
3063 
3064  if (iDebug)
3065  printf("\n-D- begin %s\n", cModule);
3066 
3067  if (iFileCount == 0)
3068  {
3069  fprintf(fLogClient,
3070  "-E- %s: no open connection to server existing\n", cModule);
3071  iError = -1;
3072  goto gEndNewFile;
3073  }
3074 
3075  ii = 0;
3076  while (ii < iFileMax)
3077  {
3078  if (pAPIFile[ii])
3079  {
3080  if (pAPIFile[ii]->iFileId == iFileId)
3081  break;
3082  }
3083  ii++;
3084  }
3085 
3086  if (ii == iFileMax)
3087  {
3088  fprintf(fLogClient, "-E- %s: no open connection to server\n", cModule);
3089  iError = -1;
3090  goto gEndNewFile;
3091  }
3092 
3093  if (iDebug)
3094  printf(" requested API control block %d\n", iFileId);
3095 
3096  pcurAPIFile = pAPIFile[iFileId];
3097  pCommAPI = &(pcurAPIFile->sCommAPI);
3098  pCommServ = &(pcurAPIFile->sCommServ);
3099  pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
3100 
3101  if ( (pcurAPIFile->iAction == 1) ||
3102  (pCommAPI->iAction == QUERY_RETRIEVE_RECORD) ||
3103  (pCommAPI->iAction == RETRIEVE_RECORD) )
3104  {
3105  fprintf(fLogClient, "-E- %s for read not supported\n", cModule);
3106  iError = -1;
3107  goto gEndNewFile;
3108  }
3109  else if (pcurAPIFile->iAction == 2)
3110  {
3111  if (iDebug)
3112  printf(" connection is open for write\n");
3113  }
3114  else
3115  {
3116  fprintf(fLogClient, "-E- %s: connection is open for unexpected action %d\n",
3117  cModule, pcurAPIFile->iAction);
3118  iError = -1;
3119  goto gEndNewFile;
3120  }
3121 
3122  if (iDebug)
3123  printf(" check name parts in %s\n", pcFile);
3124 
3125  pcc1 = (char *) strrchr(pcFile, *pcDevDelim);
3126  if (pcc1 == NULL)
3127  {
3128  fprintf(fLogClient,
3129  "-E- %s: invalid remote file name %s: node name missing\n",
3130  cModule, pcFile);
3131  iError = -1;
3132  goto gEndNewFile;
3133  }
3134 
3135  strcpy(cTemp, pcFile); /* local copy of new remote file name */
3136  pcc = (char *) strchr(pcFile, *pcObjDelim);
3137  if (pcc == NULL)
3138  {
3139  fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
3140  cModule, pcFile);
3141  iError = -1;
3142  goto gEndNewFile;
3143  }
3144 
3145  ii = pcc1 - pcc;
3146  if (ii < 0)
3147  ii = -ii;
3148  if (ii != 1)
3149  {
3150  fprintf(fLogClient,
3151  "-E- %s: invalid remote file name %s - possibly leading '/' in archive name missing\n",
3152  cModule, pcFile);
3153  iError = -1;
3154  goto gEndNewFile;
3155  }
3156 
3157  if (strncmp(cTemp, "rfiocopy:", 9) == 0)
3158  {
3159  iMassSto = 0;
3160  if (iDebug)
3161  printf(" copy via RFIO server\n");
3162  }
3163  else if (strncmp(cTemp, "rfiodaq:", 8) == 0)
3164  {
3165  iMassSto = 2;
3166  if (iDebug)
3167  printf(" copy to mass storage (DAQPool)\n");
3168  }
3169  else if (strncmp(cTemp, "rfio:", 5) == 0)
3170  {
3171  iMassSto = 1;
3172  if (iDebug)
3173  printf(" copy to mass storage (ArchivePool)\n");
3174  }
3175  else /* assume node:object */
3176  {
3177  iMassSto = 1;
3178  if (iDebug)
3179  printf(" copy to mass storage (ArchivePool)\n");
3180  }
3181 
3182  if (pcurAPIFile->iMassSto != iMassSto)
3183  {
3184  fprintf(fLogClient,
3185  "-E- %s: remote file %s incompatible with open server connection\n",
3186  cModule, pcFile);
3187  iError = -1;
3188  goto gEndNewFile;
3189  }
3190 
3191  if (iDebug) printf(
3192  " requested server consistent with open connection (%d)\n",
3193  iMassSto);
3194 
3195  /* pcc points now to 1st '/' */
3196  if (iMassSto)
3197  {
3198  if (strlen(pcc) > MAX_OBJ_FS - 1)
3199  strncpy(pcNamefs, pcc, MAX_OBJ_FS-1);
3200  else
3201  strcpy(pcNamefs, pcc);
3202 
3203  pcc = pcNamefs;
3204  pcc++;
3205  pcc1 = (char *) strchr(pcc, *pcObjDelim);
3206  if (pcc1 == NULL)
3207  {
3208  ii = MAX_OBJ_FS-1;
3209  if (iDebug) printf(
3210  "-E- archive name starting with %s too long, max allowed %d chars\n",
3211  pcNamefs, ii);
3212  fprintf(fLogClient,
3213  "-E- %s: archive name starting with %s too long, max allowed %d chars\n",
3214  cModule, pcNamefs, ii);
3215  iError = -1;
3216  goto gEndNewFile;
3217  }
3218 
3219  strncpy(pcc1, "\0", 1); /* terminates archive name */
3220  if (strlen(pCommServ->cNamefs))
3221  {
3222  if (strcmp(pCommServ->cNamefs, pcNamefs))
3223  {
3224  fprintf(fLogClient,
3225  "-E- %s: invalid archive name %s, expected %s\n",
3226  cModule, pcNamefs, pCommServ->cNamefs);
3227  iError = -1;
3228  goto gEndNewFile;
3229  }
3230  }
3231 
3232  strcpy(pCommServ->cNamefs, pcNamefs);
3233  iArchLen = strlen(pcNamefs);
3234 
3235  if (iDebug) printf(
3236  " archive name: %s (len %d chars)\n", pcNamefs, iArchLen);
3237 
3238  if (iArchLen <= 3)
3239  {
3240  fprintf(fLogClient,
3241  "-E- %s: invalid archive name '%s'\n", cModule, pcNamefs);
3242  iError = -1;
3243  goto gEndNewFile;
3244  }
3245 
3246  pcc = (char *) strchr(cTemp, *pcObjDelim); /* full name */
3247  pcc++; /* skip '/' in archive name */
3248  pcc2 = (char *) strchr(pcc, *pcObjDelim);
3249  if (pcc2 == NULL)
3250  {
3251  fprintf(fLogClient,
3252  "-E- %s: invalid remote file name %s: missing path name\n",
3253  cModule, pcFile);
3254  iError = -1;
3255  goto gEndNewFile;
3256  }
3257 
3258  if (iDebug)
3259  printf(" path + file name: %s\n", pcc2);
3260 
3261  pcc = pcc2;
3262  pcc++; /* skip 1st '/' in path name */
3263  pcc1 = (char *) strrchr(pcc, *pcObjDelim);
3264  if (pcc1 == NULL)
3265  {
3266  fprintf(fLogClient,
3267  "-E- %s: invalid remote file name %s: missing file name\n",
3268  cModule, pcFile);
3269  iError = -1;
3270  goto gEndNewFile;
3271  }
3272 
3273  if (iDebug)
3274  printf(" file name: %s\n", pcc1);
3275 
3276  iPathLen = pcc2-pcc1;
3277  if (iPathLen < 0)
3278  iPathLen = -iPathLen;
3279  if (iDebug)
3280  printf(" length path name: %d\n", iPathLen);
3281 
3282  if (iPathLen >= MAX_OBJ_HL)
3283  {
3284  ii = MAX_OBJ_HL - 1;
3285  if (iDebug)
3286  printf("-E- path name too long, max allowed %d chars\n", ii);
3287  fprintf(fLogClient,
3288  "-E- %s: remote path name (%d chars) too long, max allowed %d\n",
3289  cModule, iPathLen, ii);
3290  iError = -1;
3291  goto gEndNewFile;
3292  }
3293 
3294  strncpy(pcNamehl, pcc2, (unsigned) iPathLen);
3295  if (iDebug)
3296  printf(" path name: %s\n", pcNamehl);
3297 
3298  strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
3299  if (strcmp(pcNamehl, pCommAPI->cNamehl))
3300  {
3301  strcpy(pcNamehl, pCommAPI->cNamehl);
3302  printf(" gStore path name corrected to %s\n", pcNamehl);
3303 
3304  strcpy(pcFile, cPrefix);
3305  strcat(pcFile, cNamefs);
3306  strcat(pcFile, cNamehl);
3307  strcat(pcFile, pcc1);
3308  if (iDebug) printf(
3309  " new full file name: %s\n", pcFile);
3310  }
3311 
3312  iFileLen = strlen(pcc1);
3313  if (iDebug)
3314  printf(" length file name: %d\n", iFileLen);
3315 
3316  ii = MAX_OBJ_LL-1;
3317  if ((int) strlen(pcc1) > ii)
3318  {
3319  if (iDebug)
3320  printf("-E- file name too long, max allowed %d chars\n", ii);
3321  fprintf(fLogClient,
3322  "-E- %s: file name %s (%d chars) too long, max allowed %d\n",
3323  cModule, pcc1, iFileLen, ii);
3324  iError = -1;
3325  goto gEndNewFile;
3326  }
3327 
3328  strcpy(pcNamell, pcc1);
3329  if (iDebug)
3330  printf(" file name: %s\n", pcNamell);
3331 
3332  } /* (iMassSto) */
3333  else
3334  {
3335  strcpy(pCommServ->cNamefs, "");
3336 
3337  strcpy(cTemp, pcc); /* starts now with remote path name */
3338  pcc = cTemp;
3339  pcc++; /* skip leading '/' */
3340  pcc1 = (char *) strrchr(pcc, *pcObjDelim);
3341  if (pcc1 == NULL)
3342  {
3343  fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
3344  cModule, pcFile);
3345  iError = -1;
3346  goto gEndNewFile;
3347  }
3348 
3349  if (strlen(pcc1) > MAX_OBJ_LL-1)
3350  {
3351  ii = MAX_OBJ_LL-1;
3352  fprintf(fLogClient,
3353  "-E- %s: remote file name %s too long (max %d chars)\n",
3354  cModule, pcc1, ii);
3355  iError = -1;
3356  goto gEndNewFile;
3357  }
3358 
3359  strcpy(pcNamell, pcc1);
3360  if (iDebug) printf(
3361  " remote file name on RFIO server: %s\n", pcNamell);
3362 
3363  strncpy(pcc1, "\0", 1); /* terminates path name */
3364  if (strlen(cTemp) > MAX_OBJ_HL-1)
3365  {
3366  ii = MAX_OBJ_HL-1;
3367  fprintf(fLogClient,
3368  "-E- %s: remote path name %s too long (max %d chars)\n",
3369  cModule, cTemp, ii);
3370  iError = -1;
3371  goto gEndNewFile;
3372  }
3373 
3374  strcpy(pcNamehl, cTemp);
3375  if (iDebug) printf(
3376  " remote path name on RFIO server: %s\n", pcNamehl);
3377 
3378  } /* (iMassSto = 0) */
3379 
3380  if (strlen(pCommServ->cNamehl))
3381  {
3382  if (strcmp(pCommServ->cNamehl, pcNamehl))
3383  {
3384  fprintf(fLogClient, "-W- new path name %s, previous %s\n",
3385  pcNamehl, pCommServ->cNamehl);
3386  inewPath = 1;
3387  }
3388  else
3389  inewPath = 0;
3390  }
3391  else
3392  {
3393  strcpy(pCommServ->cNamehl, pcNamehl);
3394  strcpy(pCommAPI->cNamehl, pcNamehl);
3395  }
3396 
3397  if (strlen(pCommAPI->cNamefs) < 3)
3398  strcpy(pCommAPI->cNamefs, pCommServ->cNamefs);
3399 
3400  strcpy(pCommAPI->cNamell, pcNamell);
3401  strcpy(pCommServ->cNamell, pcNamell);
3402  if (inewPath)
3403  {
3404  strcpy(pCommServ->cNamehl, pcNamehl);
3405  strcpy(pCommAPI->cNamehl, pcNamehl);
3406  }
3407 
3408  if (iDebug)
3409  printf(" file name: %s\n", pcNamell);
3410 
3411  pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
3412 
3413  /********************** perform queries ***************************/
3414 
3415  if (iMassSto)
3416  {
3417  iATLServer = pCommAPI->iATLServer;
3418  if (iDebug) printf(
3419  " query file %s in ATL server %d\n", pcFile, iATLServer);
3420 
3421  pBufQuery = &sQuery;
3422  pQAttr = &(sQuery.objAttr);
3423 
3424  pCommServ->iAction = htonl(QUERY_ARCHIVE_RECORD); /* temp */
3425 
3426  iRC = rawQueryFile(pcurAPIFile->iSockMaster, 0,
3427  pCommServ, &pBufQuery);
3428 
3429  pCommServ->iAction = htonl(ARCHIVE_RECORD); /* reset */
3430 
3431  if (iRC)
3432  {
3433  if (iRC < 0)
3434  {
3435  if (iRC == -1001) sprintf(rfio_errmsg,
3436  "-E- no write access to archive %s in mass storage\n",
3437  pCommAPI->cNamefs);
3438  else if (iRC == -1000) sprintf(rfio_errmsg,
3439  "-E- no archive %s in mass storage found\n",
3440  pCommAPI->cNamefs);
3441  else sprintf(rfio_errmsg,
3442  "-E- file %s: query in mass storage failed, rc = %d\n",
3443  pcFile, iRC);
3444  }
3445  else sprintf(rfio_errmsg,
3446  "-E- file %s already available in mass storage\n",
3447  pcFile);
3448  fprintf(fLogClient, "%s", rfio_errmsg);
3449 
3450  if ( (iRC == -1001) || (iRC == -1000) )
3451  iError = -1;
3452  else
3453  iError = 1;
3454 
3455  goto gEndNewFile;
3456  }
3457 
3458  if (iDebug) printf(
3459  " file %s not yet available in mass storage\n", pcFile);
3460 
3461  } /* (iMassSto) */
3462 
3463 gNextCmdNewFile:
3464  iCopyMode = ntohl(pCopyCacheServ->iCopyMode);
3465  if (iCopyMode)
3466  {
3467  iCopyLen = ntohl(pCopyCacheServ->iCopyLen);
3468  if (iCopyLen == 0)
3469  {
3470  iCopyBuffer = 1;
3471  ii = irawCopyCache - HEAD_LEN;
3472  pCopyCacheServ->iCopyLen = htonl(ii);
3473  if (iDebug)
3474  printf(" send copy parameters to DM\n");
3475  }
3476  else if (iDebug)
3477  printf(" copy parameters already sent to DM\n");
3478  }
3479  else if (iDebug)
3480  printf(" data are only written to WC\n");
3481 
3482  if (iDebug)
3483  {
3484  printf(" send command buffer to server %s: id: %d, action %d, bufsize %d",
3485  pcurAPIFile->cNodeMover,
3486  pCommAPI->iIdent,
3487  pCommAPI->iAction,
3488  pCommAPI->iBufsizeFile);
3489  if (iCopyBuffer)
3490  printf(", data len %d\n",
3491  pCommAPI->iCommLen + irawCopyCache);
3492  else
3493  printf(", data len %d\n", pCommAPI->iCommLen);
3494  }
3495 
3496  iSockMover = pcurAPIFile->iSockMover;
3497  pcc = (char *) pCommServ;
3498  if (iCopyBuffer)
3499  pCommServ->iCommLen = htonl(pCommAPI->iCommLen + irawCopyCache);
3500  /* temp for data mover */
3501 
3502  if ( (iRC = send(iSockMover, pcc, (unsigned) irawComm, 0 )) < 0 )
3503  {
3504  fprintf(fLogClient,
3505  "-E- %s: sending command buffer to server %s (rc = %d)\n",
3506  cModule, pcurAPIFile->cNodeMover, iRC);
3507  perror(" ");
3508  iError = -1;
3509  goto gEndNewFile;
3510  }
3511 
3512  if (irawComm != iRC)
3513  {
3514  fprintf(fLogClient,
3515  "-E- %s: incomplete command buffer sent to server %s (%d of %d bytes)\n",
3516  cModule, pcurAPIFile->cNodeMover, iRC, irawComm);
3517 
3518  iError = -1;
3519  goto gEndNewFile;
3520  }
3521 
3522  if (iDebug) printf(
3523  " command buffer sent to server %s (%d byte)\n",
3524  pcurAPIFile->cNodeMover, irawComm);
3525 
3526  if (iCopyBuffer)
3527  {
3528  pcc = (char *) pCopyCacheServ;
3529  if ( (iRC = send(iSockMover, pcc, (unsigned) irawCopyCache, 0 )) < 0 )
3530  {
3531  fprintf(fLogClient,
3532  "-E- %s: sending copy buffer to server %s (rc = %d)\n",
3533  cModule, pcurAPIFile->cNodeMover, iRC);
3534  perror(" ");
3535  iError = -1;
3536  goto gEndNewFile;
3537  }
3538 
3539  if (irawCopyCache != iRC)
3540  {
3541  fprintf(fLogClient,
3542  "-E- %s: incomplete copy buffer sent to server %s (%d of %d bytes)\n",
3543  cModule, pcurAPIFile->cNodeMover, iRC, irawCopyCache);
3544 
3545  iError = -1;
3546  goto gEndNewFile;
3547  }
3548 
3549  if (iDebug) printf(
3550  " copy buffer sent to server %s (%d byte)\n",
3551  pcurAPIFile->cNodeMover, irawCopyCache);
3552 
3553  pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
3554  /* reset temp length for data mover again */
3555  }
3556 
3557  /******************* look for reply from server *******************/
3558 
3559  pcc = (char *) &sStatus;
3560  iStatusOkay = 0;
3561  iStatusLoop = 0;
3562  while (iStatusOkay == 0)
3563  {
3564  iStatusLoop++;
3565 
3566  memset(&sStatus, 0X00, sizeof(srawStatus));
3567  iRC = rawRecvStatus(iSockMover, pcc);
3568  iStatus = sStatus.iStatus;
3569  if (iDebug) printf(
3570  " status %d received (%d byte)\n", iStatus, iRC);
3571  if (iRC != HEAD_LEN)
3572  {
3573  if (iRC < HEAD_LEN) fprintf(fLogClient,
3574  "-E- %s: receiving status buffer from server\n",
3575  cModule);
3576  else /* received error message */
3577  {
3578  if (iStatus == STA_CACHE_FULL)
3579  {
3580  if ( (iStatusLoop < iStatusLoopMax) &&
3581  (iMassSto != 2) ) /* no delay for DAQPool */
3582  {
3583  fprintf(fLogClient,
3584  "-W- %s: write cache currently full ... sleep %d s (%d of %d)\n",
3585  cModule, iSleepCacheFull,
3586  iStatusLoop, iStatusLoopMax);
3587  continue;
3588  }
3589  else
3590  {
3591  fprintf(fLogClient,
3592  "-W- %s: write cache currently full, archive to tape\n",
3593  cModule);
3594  pCommServ->iAction = htonl(ARCHIVE_RECORD);
3595  pCommServ->iArchDev = htonl(ARCH_TAPE);
3596  pCommAPI->iAction = ARCHIVE_RECORD;
3597  pCommAPI->iArchDev = ARCH_TAPE;
3598 
3599  /* copy from WC no longer possible */
3600  iCopyMode = 0;
3601  pCopyCacheServ->iCopyMode = htonl(0);
3602 
3603  goto gNextCmdNewFile;
3604  }
3605  } /* (iStatus == STA_CACHE_FULL) */
3606  else if (iStatus == STA_SWITCH_SERVER)
3607  {
3608  strcpy(cNodeMover, sStatus.cStatus);
3609 
3610  fprintf(fLogClient,
3611  "-W- write cache on DM %s full or too much load, switch to %s\n",
3612  pcurAPIFile->cNodeMover, cNodeMover);
3613 
3614  if (iDebug) printf(
3615  " close connection %d to data mover %s\n",
3616  iSockMover, pcurAPIFile->cNodeMover);
3617  iRC = shutdown(iSockMover, 2);
3618  if (iDebug)
3619  printf(" rc shutdown = %d\n", iRC);
3620 
3621  iRC = close(iSockMover);
3622  if (iDebug)
3623  printf(" rc close = %d\n", iRC);
3624  else if (iRC == 0)
3625  fprintf(fLogClient,
3626  "-I- connection to data mover %s closed\n",
3627  pcurAPIFile->cNodeMover);
3628 
3629  /*************** connect to new data mover ************/
3630 
3631  if (iDebug) printf(
3632  " connecting to data mover %s:%d\n",
3633  cNodeMover, iPortMover);
3634 
3635  iRC = rconnect(cNodeMover, iPortMover,
3636  &iMaxConnect, &iSockMover);
3637  if (iRC)
3638  {
3639  fprintf(fLogClient,
3640  "-E- %s: cannot connect to new data mover %s:%d (ATL server %d)\n",
3641  cModule, cNodeMover, iPortMover, iATLServer);
3642  iError = -2;
3643  }
3644 
3645  fprintf(fLogClient,
3646  "-I- successfully connected to new data mover %s:%d (ATL server %d)",
3647  cNodeMover, iPortMover, iATLServer);
3648  if (iMaxConnect)
3649  fprintf(fLogClient, " after %ds", iMaxConnect);
3650  if (iDebug)
3651  printf(" (socket %d)\n", iSockMover);
3652  else
3653  fprintf(fLogClient, "\n");
3654 
3655  strcpy(pcurAPIFile->cNodeMover, cNodeMover);
3656  pcurAPIFile->iSockMover = iSockMover;
3657 
3658  pCopyCacheServ->iCopyLen = htonl(0);
3659  /* copy buffer must be sent again to DM */
3660  goto gNextCmdNewFile;
3661 
3662  } /* (iStatus == STA_SWITCH_SERVER) */
3663  else
3664  {
3665  fprintf(fLogClient, "-E- message received from server:\n");
3666  fprintf(fLogClient, " %s\n", sStatus.cStatus);
3667 
3668  if (iStatus == STA_ERROR_EOF)
3669  iError = 1;
3670  else
3671  iError = -2;
3672  }
3673 
3674  } /* (iRC >= HEAD_LEN) */
3675 
3676  goto gEndNewFile;
3677 
3678  } /* (iRC != HEAD_LEN) */
3679  iStatusOkay = 1;
3680 
3681  } /* while (iStatusOkay == 0) */
3682 
3683  if (iDebug)
3684  {
3685  printf(" status (%d) received from server (%d bytes",
3686  iStatus, iRC);
3687  if (iStatusLoop > 1)
3688  printf(", iter %d)\n", iStatusLoop);
3689  else
3690  printf(")\n");
3691  }
3692 
3693  iError = 0;
3694  /* = 1: file already in mass storage: try new name
3695  = -2: write cache of current data mover full: close, new open
3696  = -3: write cache of all data movers full: close, retry
3697  */
3698 
3699 gEndNewFile:
3700  if (iDebug)
3701  printf("-D- end %s\n\n", cModule);
3702 
3703  return iError;
3704 
3705 } /* rfio_newfile */
3706 
3707 /********************************************************************
3708  * rfio_close:
3709  * close remote file in GSI mass storage and
3710  * connection to GSI mass storage
3711  *
3712  * created 4.12.2000, Horst Goeringer
3713  ********************************************************************
3714  */
3715 
3716 int rfio_close(int iFileId) /* file id */
3717 {
3718  char cModule[32] = "rfio_close";
3719  int iDebug = 0;
3720  int iRC;
3721  int iSockMaster; /* socket for connection to master */
3722  int iSockMover; /* socket for connection to mover */
3723  int iStatus = STA_END_OF_SESSION;
3724  int ii = 0;
3725  char *pcc;
3726 
3727  srawStatus sStatusRecv;
3728  srawComm *pCommAPI;
3729  srawAPIFile *pcurAPIFile;
3730 
3731  if (iDebug) printf(
3732  "\n-D- begin %s: close remote file %d\n", cModule, iFileId);
3733 
3734  if (iFileCount == 0)
3735  {
3736  fprintf(fLogClient,
3737  "-E- %s: no remote file available for close\n", cModule);
3738  return -1;
3739  }
3740 
3741  while (ii < iFileMax)
3742  {
3743  if (pAPIFile[ii])
3744  {
3745  if (pAPIFile[ii]->iFileId == iFileId)
3746  break;
3747  }
3748  ii++;
3749  }
3750 
3751  if (ii == iFileMax)
3752  {
3753  fprintf(fLogClient, "-E- %s: remote file %d cannot be closed: not found\n",
3754  cModule, iFileId);
3755  return -1;
3756  }
3757 
3758  pcurAPIFile = pAPIFile[iFileId];
3759  pCommAPI = &(pcurAPIFile->sCommAPI);
3760  iStatus = STA_END_OF_SESSION;
3761  iSockMaster = pcurAPIFile->iSockMaster;
3762 
3763  if ( (pcurAPIFile->iMassSto) &&
3764  (pcurAPIFile->iOpMode == 0) ) /* 'normal' RFIO */
3765  fprintf(fLogClient, "-I- gStore file %s%s%s closed\n",
3766  pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
3767 
3768  if (iSockMaster >= 0)
3769  {
3770  /* stop master server process */
3771  iRC = rawSendStatus(iSockMaster, iStatus, NULL);
3772  if (iRC <= 0) fprintf(fLogClient,
3773  "-E- %s: sending status buffer (EOS) to master\n", cModule);
3774  else if (iDebug) printf(
3775  " status buffer (EOS) sent to master (%d bytes)\n", iRC);
3776 
3777  if (iDebug)
3778  printf(" close connection %d to master\n", iSockMaster);
3779  iRC = shutdown(iSockMaster, 2);
3780  if (iDebug)
3781  printf(" rc shutdown = %d\n", iRC);
3782  iRC = close(iSockMaster);
3783  if (iDebug)
3784  printf(" rc close = %d\n", iRC);
3785 
3786  } /* (iSockMaster >= 0) */
3787 
3788  iSockMover = pcurAPIFile->iSockMover;
3789  if (iSockMover >= 0)
3790  {
3791  /* stop data mover process */
3792  iRC = rawSendStatus(iSockMover, iStatus, NULL);
3793  if (iRC <= 0) fprintf(fLogClient,
3794  "-E- %s: sending status buffer (EOS) to data mover\n", cModule);
3795  else if (iDebug) printf(
3796  " status buffer (EOS) sent to data mover (%d bytes)\n", iRC);
3797 
3798  /* receive confirmation if written to tape */
3799  if ( (pCommAPI->iAction == ARCHIVE_RECORD) &&
3800  (pCommAPI->iArchDev == ARCH_TAPE) &&
3801  (pcurAPIFile->iOpMode == 0) ) /* in rfio_endfile alr. done */
3802  {
3803  memset(&sStatusRecv, 0X00, sizeof(srawStatus));
3804  pcc = (char *) &sStatusRecv;
3805  iRC = rawRecvStatus(iSockMover, pcc);
3806 
3807  if (iRC < HEAD_LEN) fprintf(fLogClient,
3808  "-E- %s: receiving confirmation of status buffer (EOS)\n",
3809  cModule);
3810  else if (iDebug) printf(
3811  " status (%d) confirmed by server (%d bytes)\n",
3812  sStatusRecv.iStatus, iRC);
3813  }
3814 
3815  if (iDebug)
3816  printf(" close connection %d to data mover\n", iSockMover);
3817  iRC = shutdown(iSockMover, 2);
3818  if (iDebug)
3819  printf(" rc shutdown = %d\n", iRC);
3820  iRC = close(iSockMover);
3821  if (iDebug)
3822  printf(" rc close = %d\n", iRC);
3823  else fprintf(fLogClient,
3824  "-I- connection to data mover %s closed\n",
3825  pcurAPIFile->cNodeMover);
3826 
3827  } /* (iSockMover >= 0) */
3828 
3829  free(pAPIFile[iFileId]);
3830  pAPIFile[iFileId] = NULL;
3831  iFileCount--;
3832 
3833  if (iDebug)
3834  {
3835  printf(
3836  " remote file control block %d deleted (%d still active)\n",
3837  iFileId, iFileCount);
3838  printf("-D- end %s\n\n", cModule);
3839  }
3840 
3841  return 0;
3842 
3843 } /* rfio_close */
3844 
3845 #ifdef __USE_LARGEFILE64
3846 
3847 /********************************************************************
3848  * rfio_preseek64: in remote file in GSI mass storage
3849  * move read/write file mark
3850  *
3851  * created 29. 5.2007, Horst Goeringer
3852  ********************************************************************
3853  */
3854 
3855 int rfio_preseek64(
3856  int iFileId,
3857  const void *piov,
3858  int iBufferNumber)
3859 {
3860  char cModule[32] = "rfio_preseek64";
3861  int iDebug = 0;
3862  int iRC = 0;
3863 
3864  if (iDebug) fprintf(fLogClient,
3865  "\n-D- begin %s: iFileId %d\n", cModule, iFileId);
3866 
3867  int ii = sizeof(long);
3868  if (ii < 8)
3869  {
3870  fprintf(fLogClient,
3871  "-E- 32 bit client: %s not supported\n", cModule);
3872 
3873  return -1;
3874  }
3875 
3876  fprintf(fLogClient,
3877  "-W- %s not yet implemented for gStore\n", cModule);
3878 
3879  if (iDebug)
3880  fprintf(fLogClient, "-D- end %s\n\n", cModule);
3881 
3882  return iRC;
3883 
3884 } /* rfio_preseek64 */
3885 
3886 /********************************************************************
3887  * rfio_lseek64: in remote file in GSI mass storage
3888  * move read/write file mark
3889  *
3890  * created 29. 5.2007, Horst Goeringer
3891  ********************************************************************
3892  */
3893 
3894 int64_t rfio_lseek64(
3895  int iFileId,
3896  int64_t i64locOffset,
3897  int ilocSeekMode)
3898 {
3899  char cModule[32] = "rfio_lseek64";
3900  int iDebug = 0;
3901  int iRC;
3902  int ilocOffset;
3903  int ii;
3904 
3905  ii = sizeof(long);
3906  if (ii < 8)
3907  {
3908  fprintf(fLogClient,
3909  "-E- 32 bit client: %s not supported\n", cModule);
3910 
3911  return -1;
3912  }
3913 
3914  if (iDebug) fprintf(fLogClient,
3915  "\n-D- begin %s: iFileId %d, Offset %lld, SeekMode %d\n",
3916  cModule, iFileId, (unsigned long) i64locOffset, ilocSeekMode);
3917 
3918  ilocOffset = (int) i64locOffset;
3919 
3920  iRC = rfio_lseek(iFileId, ilocOffset, ilocSeekMode);
3921 
3922  if (iDebug) fprintf(fLogClient,
3923  "-D- end %s: rc(rfio_lseek) = %d \n\n", cModule, iRC);
3924 
3925  return (int64_t) iRC;
3926 
3927 } /* rfio_lseek64 */
3928 
3929 #endif /* __USE_LARGEFILE64 */
3930 
3931 /********************************************************************
3932  * rfio_lseek: in remote file in GSI mass storage
3933  * move read/write file mark
3934  *
3935  * created 4.12.2000, Horst Goeringer
3936  ********************************************************************
3937  */
3938 
3939 int rfio_lseek(int iFileId, /* file id */
3940  int ilocOffset,
3941  int ilocSeekMode)
3942 {
3943  char cModule[32] = "rfio_lseek";
3944  int iDebug = 0;
3945  int iRC;
3946  int iSockMover; /* socket for connection to mover */
3947  int iSeekMode;
3948  int iOffset;
3949 
3950  srawAPIFile *pcurAPIFile;
3951 
3952  if (iDebug)
3953  {
3954  printf("\n-D- begin %s: file %d\n", cModule, iFileId);
3955  if (ilocSeekMode == SEEK_SET)
3956  printf(" position to %d bytes, \n", ilocOffset);
3957  else if (ilocSeekMode == SEEK_CUR)
3958  printf(" position to current + %d bytes, \n", ilocOffset);
3959  else if (ilocSeekMode == SEEK_END)
3960  printf(" position to file size + %d bytes, \n", ilocOffset);
3961  else
3962  {
3963  fprintf(fLogClient, "-E- %s: unexpected offset (%d)\n",
3964  cModule, ilocSeekMode);
3965  return -1;
3966  }
3967  }
3968 
3969  pcurAPIFile = pAPIFile[iFileId];
3970  iSeekMode = pcurAPIFile->iSeekMode;
3971 
3972  /* check if still seek request pending */
3973  if (iSeekMode != -1)
3974  {
3975  iSockMover = pcurAPIFile->iSockMover;
3976  iOffset = pcurAPIFile->iOffset;
3977  iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, 0);
3978  if (iRC != 0)
3979  {
3980  fprintf(fLogClient, "-E- %s: sending request for seek\n", cModule);
3981  return -1;
3982  }
3983  }
3984 
3985  pcurAPIFile->iSeekMode = ilocSeekMode;
3986  pcurAPIFile->iOffset = ilocOffset;
3987 
3988  if (iDebug)
3989  printf("-D- end %s\n\n", cModule);
3990 
3991  return 0;
3992 
3993 } /* rfio_lseek */
3994 
3995 /********************************************************************
3996  * rfio_fopen: open connection to gStore server and file
3997  *
3998  * created 4.12.2000, Horst Goeringer
3999  ********************************************************************
4000  */
4001 
4002 RFILE *rfio_fopen(char *pcFile, /* file name */
4003  char *pcOptions) /* options */
4004 {
4005  char cModule[32] = "rfio_fopen";
4006  int iDebug = 0;
4007  RFILE *fRemoteFile = NULL;
4008  int iCopyMode = 0; /* ignore parameters for data stream copy */
4009  char *pcCopyPath = NULL;
4010  int iCopyFraction = 0;
4011  int iMaxFile = 0;
4012  int iPathConvention = 0;
4013 
4014  if (iDebug)
4015  printf("\n-D- begin %s: calling rfio_fopen_gsidaq\n", cModule);
4016 
4017  fRemoteFile = rfio_fopen_gsidaq(
4018  pcFile,
4019  pcOptions,
4020  iCopyMode,
4021  pcCopyPath,
4022  iCopyFraction,
4023  iMaxFile,
4024  iPathConvention);
4025 
4026  if (iDebug)
4027  printf("-D- end %s\n\n", cModule);
4028 
4029  return fRemoteFile;
4030 
4031 } /* rfio_fopen */
4032 
4033 /********************************************************************
4034  * rfio_fopen_gsidaq_dm: open connection to gStore server and file and
4035  * prepare copy to lustre or read cache before migration to tape
4036  * provide DM name and running number
4037  *
4038  * created 23. 4.2010, Horst Goeringer
4039  ********************************************************************
4040  */
4041 
4043  char *pcFile, /* file name */
4044  char *pcOptions, /* options */
4045  char *pcDataMover,
4046  int *piDataMover,
4047  int iCopyMode,
4048  /* = 0: standard RFIO, ignore following arguments
4049  = 1: copy to pcCopyPath after file written to WC
4050  (for high data rates,
4051  don't interfere writing to cache)
4052  = 2: for lustre only:
4053  write each data buffer in parallel to
4054  write cache and to pcCopyPath
4055  (for low data rates, anyhow first buffers
4056  quickly available in lustre)
4057  */
4058  char *pcCopyPath,
4059  /* destination where to be copied
4060  = "/lustre..." => fully qualified path name
4061  if not existing: will be created according
4062  to user conventions:
4063  ".../d" => Hades, create .../dyydddhhmm
4064  = "RC" => read cache
4065  */
4066  int iCopyFraction,
4067  /* = i>0: copy each ith file to pcCopyPath
4068  if tape migration fails:
4069  ignore iCopyFraction, copy each file
4070  */
4071  int iMaxFile,
4072  /* for dataFS only:
4073  = 0: no file limit
4074  > 0: max no. of files to be written to directory
4075  max no. of files to be written to directory
4076  files already existing are ignored
4077  if iMaxFile reached, new dir will be created
4078  (same level as previous one)
4079  */
4080  int iPathConvention)
4081  /* rules for creation of initial/new path
4082  = 0: default convention
4083  initially specified .../xxx => .../xxx
4084  last .../xxx => create ...xxx1
4085  last .../xxxi => create ...xxxj j=i+1
4086  = 1: Hades convention: path name contains time stamp
4087  initially specified .../xxx => .../xxxyydddhhmm
4088  new => .../xxxyydddhhmm
4089  */
4090 {
4091  char cModule[32] = "rfio_fopen_gsidaq_dm";
4092  int iDebug = 0;
4093  int iFileId = -1; /* file identifier for server connection */
4094  int iDataMover = 0;
4095  int ilen;
4096  char *pcc;
4097 
4098  if (iDebug)
4099  printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
4100 
4101  if (*pcOptions == 'r')
4102  {
4103  iFileId = rfio_open_gsidaq(
4104  pcFile, O_RDONLY, 0,
4105  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4106  iPathConvention);
4107  }
4108  if (*pcOptions == 'w')
4109  {
4110  iFileId = rfio_open_gsidaq(
4111  pcFile, O_WRONLY | O_CREAT, 0,
4112  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4113  iPathConvention);
4114  }
4115 
4116  if (iFileId >= 0)
4117  {
4118  ilen = strlen(pAPIFile[iFileId]->cNodeMover);
4119  strcpy(pcDataMover, pAPIFile[iFileId]->cNodeMover);
4120  if (iDebug) printf(
4121  " connected with data mover %s\n", pcDataMover);
4122 
4123  pcc = pcDataMover;
4124  pcc += ilen - 2; /* last 2 digits are the running number */
4125  iDataMover = atoi(pcc);
4126  *piDataMover = iDataMover;
4127 
4128  if (iDebug) printf(
4129  " running number data mover: %d\n", iDataMover);
4130  }
4131 
4132  if (iDebug) printf(
4133  "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
4134  cModule, iFileId);
4135 
4136  if (iFileId < 0)
4137  return NULL;
4138 
4139  return pAPIFile[iFileId]; /* global, filled in rfio_open */
4140 
4141 } /* rfio_fopen_gsidaq_dm */
4142 
4143 /********************************************************************
4144  * rfio_fopen_gsidaq: open connection to gStore server and file and
4145  * prepare copy to lustre or read cache before migration to tape
4146  *
4147  * created 4.12.2000, Horst Goeringer
4148  ********************************************************************
4149  */
4150 
4152  char *pcFile, /* file name */
4153  char *pcOptions, /* options */
4154  int iCopyMode,
4155  /* = 0: standard RFIO, ignore following arguments
4156  = 1: copy to pcCopyPath after file written to WC
4157  (for high data rates,
4158  don't interfere writing to cache)
4159  = 2: for lustre only:
4160  write each data buffer in parallel to
4161  write cache and to pcCopyPath
4162  (for low data rates, anyhow first buffers
4163  quickly available in lustre)
4164  */
4165  char *pcCopyPath,
4166  /* destination where to be copied
4167  = "/lustre..." => fully qualified path name
4168  if not existing: will be created according
4169  to user conventions:
4170  ".../d" => Hades, create .../dyydddhhmm
4171  = "RC" => read cache
4172  */
4173  int iCopyFraction,
4174  /* = i>0: copy each ith file to pcCopyPath
4175  if tape migration fails:
4176  ignore iCopyFraction, copy each file
4177  */
4178  int iMaxFile,
4179  /* for dataFS only:
4180  = 0: no file limit
4181  > 0: max no. of files to be written to directory
4182  max no. of files to be written to directory
4183  files already existing are ignored
4184  if iMaxFile reached, new dir will be created
4185  (same level as previous one)
4186  */
4187  int iPathConvention)
4188  /* rules for creation of initial/new path
4189  = 0: default convention
4190  initially specified .../xxx => .../xxx
4191  last .../xxx => create ...xxx1
4192  last .../xxxi => create ...xxxj j=i+1
4193  = 1: Hades convention: path name contains time stamp
4194  initially specified .../xxx => .../xxxyydddhhmm
4195  new => .../xxxyydddhhmm
4196  */
4197 {
4198  char cModule[32] = "rfio_fopen_gsidaq";
4199  int iDebug = 0;
4200  int iFileId = -1; /* file identifier for server connection */
4201 
4202  if (iDebug)
4203  printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
4204 
4205  if (*pcOptions == 'r')
4206  {
4207  iFileId = rfio_open_gsidaq(
4208  pcFile, O_RDONLY, 0,
4209  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4210  iPathConvention);
4211  }
4212  if (*pcOptions == 'w')
4213  {
4214  iFileId = rfio_open_gsidaq(
4215  pcFile, O_WRONLY | O_CREAT, 0,
4216  iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
4217  iPathConvention);
4218  }
4219 
4220  if (iDebug) printf(
4221  "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
4222  cModule, iFileId);
4223 
4224  if (iFileId < 0)
4225  return NULL;
4226 
4227  return pAPIFile[iFileId]; /* global, filled in rfio_open */
4228 
4229 } /* rfio_fopen_gsidaq */
4230 
4231 /*********************************************************************
4232  * rfio_fnewfile: continue with next remote file in GSI mass storage
4233  *
4234  * created 2. 8.2004, Horst Goeringer
4235  *********************************************************************
4236  */
4237 
4238 int rfio_fnewfile(RFILE *pRemFile, /* remote file control block */
4239  char *pcFile) /* file name */
4240 {
4241  char cModule[32] = "rfio_fnewfile";
4242  int iDebug = 0;
4243  int iRC;
4244  int ii;
4245  int iFileId; /* file identifier for server connection */
4246 
4247  if (iDebug)
4248  {
4249  printf("\n-D- begin %s\n", cModule);
4250  fflush(stdout);
4251  }
4252 
4253  if (iFileCount <= 0)
4254  {
4255  fprintf(fLogClient, "-E- %s: still no connection to server opened\n",
4256  cModule);
4257  return -1;
4258  }
4259 
4260  if (pRemFile == NULL)
4261  {
4262  fprintf(fLogClient, "-E- %s: invalid file ptr (NULL) specified\n", cModule);
4263  return -1;
4264  }
4265 
4266  if ( (pcFile == NULL) || (strlen(pcFile) < 5) )
4267  {
4268  fprintf(fLogClient, "-E- %s: invalid file '%s' specified\n",
4269  cModule, pcFile);
4270  return -1;
4271  }
4272 
4273  ii = 0;
4274  while (ii < iFileMax)
4275  {
4276  if (pAPIFile[ii] == pRemFile) /* global, filled in rfio_open */
4277  break;
4278  ii++;
4279  }
4280 
4281  if (ii == iFileMax)
4282  {
4283  fprintf(fLogClient, "-E- %s: invalid file ptr specified\n", cModule);
4284  return -1;
4285  }
4286 
4287  iFileId = pRemFile->iFileId;
4288  iRC = rfio_newfile(iFileId, pcFile);
4289 
4290  if (iDebug)
4291  printf("-D- end %s\n\n", cModule);
4292 
4293  if (iFileId < 0)
4294  return -1;
4295 
4296  return iRC;
4297 
4298 } /* end rfio_fnewfile */
4299 
4300 /*********************************************************************
4301  * rfio_fread: read remote file in GSI mass storage
4302  *
4303  * created 4.12.2000, Horst Goeringer
4304  *********************************************************************
4305  */
4306 
4307 size_t rfio_fread(char *pcBuffer, /* data buffer */
4308  size_t iSize, /* size of data item */
4309  size_t iItems, /* number of data items */
4310  RFILE *pRemFile) /* remote file control block */
4311 {
4312  char cModule[32]="rfio_fread";
4313  int iDebug = 0;
4314  int iRC;
4315  int iFileId; /* file identifier for server connection */
4316  size_t iBytes;
4317 
4318  if (iDebug)
4319  printf("\n-D- begin %s\n", cModule);
4320 
4321  if (pRemFile == NULL)
4322  {
4323  fprintf(fLogClient, "-E- %s: remote file not open for read\n", cModule);
4324  return 0;
4325  }
4326 
4327  iFileId = pRemFile->iFileId;
4328  iBytes = iSize*iItems;
4329  iRC = (int) rfio_read(iFileId, pcBuffer, iBytes);
4330 
4331  if (iDebug)
4332  printf("-D- end %s\n", cModule);
4333 
4334  return (unsigned) iRC;
4335 
4336 } /* rfio_fread */
4337 
4338 /*********************************************************************
4339  * rfio_fwrite: write remote file to GSI mass storage
4340  *
4341  * created 4.12.2000, Horst Goeringer
4342  *********************************************************************
4343  */
4344 
4345 size_t rfio_fwrite(const char *pcBuffer, /* data buffer */
4346  size_t iSize, /* size of data item */
4347  size_t iItems, /* number of data items */
4348  RFILE *pRemFile) /* remote file control block */
4349 {
4350  char cModule[32]="rfio_fwrite";
4351  int iDebug = 0;
4352  int iFileId; /* file identifier for server connection */
4353  size_t iBytes;
4354  int iRC;
4355 
4356  if (iDebug)
4357  printf("\n-D- begin %s\n", cModule);
4358 
4359  if (pRemFile == NULL)
4360  {
4361  fprintf(fLogClient, "-E- %s: remote file not open for write\n", cModule);
4362  return 0;
4363  }
4364 
4365  iFileId = pRemFile->iFileId;
4366  iBytes = iSize*iItems;
4367  iRC = (int) rfio_write(iFileId, pcBuffer, iBytes);
4368 
4369  if (iDebug)
4370  printf("-D- end %s\n", cModule);
4371 
4372  return (unsigned) iRC;
4373 
4374 } /* rfio_fwrite */
4375 
4376 /********************************************************************
4377  * rfio_fendfile:
4378  * close remote file in GSI mass storage,
4379  * but keep connection to mass storage data mover
4380  *
4381  * created 16. 7.2004, Horst Goeringer
4382  ********************************************************************
4383  */
4384 
4385 int rfio_fendfile(RFILE *pRemFile) /* remote file control block */
4386 {
4387  char cModule[32] = "rfio_fendfile";
4388  int iDebug = 0;
4389  int iFileId; /* file identifier for server connection */
4390  int iRC;
4391 
4392  if (iDebug)
4393  printf("\n-D- begin %s\n", cModule);
4394 
4395  iFileId = pRemFile->iFileId;
4396  iRC = rfio_endfile(iFileId);
4397 
4398  if (iDebug)
4399  printf("-D- end %s\n", cModule);
4400 
4401  return iRC;
4402 
4403 } /* rfio_fendfile */
4404 
4405 /********************************************************************
4406  * rfio_fclose:
4407  * close remote file in GSI mass storage and
4408  * connection to GSI mass storage
4409  *
4410  * created 4.12.2000, Horst Goeringer
4411  ********************************************************************
4412  */
4413 
4414 int rfio_fclose(RFILE *pRemFile) /* remote file control block */
4415 {
4416  char cModule[32] = "rfio_fclose";
4417  int iDebug = 0;
4418  int iFileId; /* file identifier for server connection */
4419  int iRC;
4420 
4421  if (iDebug)
4422  printf("\n-D- begin %s\n", cModule);
4423 
4424  iFileId = pRemFile->iFileId;
4425  iRC = rfio_close(iFileId);
4426 
4427  if (iDebug)
4428  printf("-D- end %s\n", cModule);
4429 
4430  return iRC;
4431 
4432 } /* rfio_fclose */
4433 
4434 /********************************************************************
4435  * rfio_access: for remote file in GSI mass storage
4436  * get access status
4437  *
4438  * created 4.12.2000, Horst Goeringer
4439  ********************************************************************
4440  */
4441 
4442 int rfio_access(const char *pcFile, /* file name */
4443  int iMode)
4444 {
4445  char cModule[32] = "rfio_access";
4446  int iDebug = 0;
4447  int iRC = 0;
4448 
4449  int iFileId = -1;
4450 
4451  if (iDebug)
4452  printf("\n-D- begin %s\n", cModule);
4453 
4454  /* directories not (yet) supported */
4455  if (iMode == X_OK)
4456  {
4457  if (iDebug)
4458  printf(" check if executable - not supported\n");
4459  iRC = 1;
4460  goto gEndAccess;
4461  }
4462 
4463  if (iMode == F_OK)
4464  {
4465  if (iDebug)
4466  printf(" check for existence\n");
4467 
4468  iFileId = rfio_open(pcFile, O_RDONLY, -1);
4469  if (iFileId >= 0)
4470  {
4471  iRC = rfio_close(iFileId);
4472  if (iRC)
4473  {
4474  printf("-E- closing remote file %s\n", pcFile);
4475  perror(" ");
4476  }
4477  else if (iDebug)
4478  printf("-D- remote file %s closed\n", pcFile);
4479 
4480  /* file exists, access rights already checked */
4481 
4482  /* overwrite not allowed */
4483  if (iMode == W_OK)
4484  {
4485  if (iDebug)
4486  printf(" file %s must not be overwritten\n",
4487  pcFile);
4488  iRC = 1;
4489  }
4490  else if (iMode == R_OK)
4491  {
4492  if (iDebug)
4493  printf(" file %s is readable\n", pcFile);
4494  iRC = 0;
4495  }
4496  else
4497  {
4498  if (iDebug)
4499  printf(" file %s exists\n", pcFile);
4500  iRC = 0;
4501  }
4502  }
4503  else
4504  {
4505  /* file not existing */
4506  if (iMode == W_OK)
4507  {
4508  if (iDebug)
4509  printf(" file %s may be written\n", pcFile);
4510  iRC = 0;
4511  }
4512  else
4513  {
4514  if (iDebug)
4515  printf(" file %s not existing\n", pcFile);
4516  iRC = 1;
4517  }
4518  } /* file not existing */
4519  } /* check if file existing */
4520 
4521  /* assume correct handling of caller (root) after check for existence */
4522  if (iMode == R_OK)
4523  {
4524  if (iDebug)
4525  printf(" file %s is readable\n", pcFile);
4526  iRC = 0;
4527  }
4528  if (iMode == W_OK)
4529  {
4530  if (iDebug)
4531  printf(" file %s may be written\n", pcFile);
4532  iRC = 0;
4533  }
4534 
4535 gEndAccess:
4536  if (iDebug)
4537  printf("-D- end %s\n", cModule);
4538 
4539  return iRC;
4540 
4541 } /* rfio_access */
4542 
4543 #ifdef __USE_LARGEFILE64
4544 
4545 /*********************************************************************
4546  * rfio_fstat64: for remote file in GSI mass storage
4547  * get file status
4548  *
4549  * created 29. 5.2007, Horst Goeringer
4550  *********************************************************************
4551  */
4552 
4553 int rfio_fstat64(int iFileId,
4554  struct stat64 *pStatBuf64)/* file statistics buffer */
4555 {
4556  char cModule[32] = "rfio_fstat64";
4557  int iDebug = 0;
4558  int iRC = 0;
4559  int ii;
4560 
4561  unsigned long *plFileSizeC; /* ptr to file size in sComm */
4562  srawComm *pComm;
4563 
4564  if (iDebug)
4565  {
4566  fprintf(fLogClient, "\n-D- begin %s: file %d\n", cModule, iFileId);
4567  if (iFileCount)
4568  fprintf(fLogClient, ", %d remote files currently open\n", iFileCount);
4569  else
4570  fprintf(fLogClient, "\n");
4571  }
4572 
4573  ii = sizeof(long);
4574  if (ii < 8)
4575  {
4576  fprintf(fLogClient,
4577  "-E- 32 bit client: %s not supported\n", cModule);
4578 
4579  return -1;
4580  }
4581 
4582  ii = 0;
4583  if (iFileCount > 0) while (ii <= iFileMax)
4584  {
4585  if (pAPIFile[ii] != NULL)
4586  {
4587  if (pAPIFile[ii]->iFileId == iFileId)
4588  break;
4589  }
4590 
4591  ii++;
4592  }
4593 
4594  if ( (ii > iFileMax) || (iFileCount == 0) )
4595  {
4596  fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
4597  cModule, iFileId);
4598  if (iDebug)
4599  fprintf(fLogClient, "-D- end %s\n\n", cModule);
4600 
4601  return -1;
4602  }
4603 
4604  pComm = &(pAPIFile[ii]->sCommAPI);
4605  plFileSizeC = (unsigned long *) &(pComm->iFileSize);
4606 
4607  if (iDebug)
4608  {
4609  fprintf(fLogClient, " specified remote fileId %d found:\n", iFileId);
4610  fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
4611  pComm->cNamefs, pComm->cNamehl, pComm->cNamell, *plFileSizeC);
4612  }
4613 
4614  /* initialize stat structure with parameters of local stream stdin */
4615  iRC = fstat64(0, pStatBuf64);
4616  if (iRC)
4617  {
4618  fprintf(fLogClient, "-E- %s: fstat64() failed, rc = %d\n", cModule, iRC);
4619  if (iDebug)
4620  printf("-D- end %s\n\n", cModule);
4621 
4622  return -1;
4623  }
4624 
4625  /* now set correct file size */
4626  pStatBuf64->st_size = *plFileSizeC;
4627 
4628  if (iDebug) fprintf(fLogClient,
4629  "-D- end %s: irc(fstat64) = %d\n", cModule, iRC);
4630 
4631  return iRC;
4632 
4633 } /* rfio_fstat64 */
4634 
4635 #endif /* __USE_LARGEFILE64 */
4636 
4637 /*********************************************************************
4638  * rfio_fstat: for remote file in GSI mass storage
4639  * get file status
4640  *
4641  * created 26. 2.2001, Horst Goeringer
4642  *********************************************************************
4643  */
4644 
4645 int rfio_fstat(int iFileId, /* file id */
4646  struct stat *pStatBuf) /* buffer with file statistics */
4647 {
4648  char cModule[32] = "rfio_fstat";
4649  int iDebug = 0;
4650  int iRC = 0;
4651  int ii = 0;
4652 
4653  srawComm *pComm;
4654 
4655  if (iDebug)
4656  {
4657  printf("\n-D- begin %s", cModule);
4658  if (iFileCount)
4659  printf(", %d remote files currently open\n", iFileCount);
4660  else
4661  printf("\n");
4662  }
4663 
4664  ii = 0;
4665  if (iFileCount > 0) while (ii <= iFileMax)
4666  {
4667  if (pAPIFile[ii] != NULL)
4668  {
4669  if (pAPIFile[ii]->iFileId == iFileId)
4670  break;
4671  }
4672 
4673  ii++;
4674  }
4675 
4676  if ( (ii > iFileMax) || (iFileCount == 0) )
4677  {
4678  fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
4679  cModule, iFileId);
4680  if (iDebug)
4681  printf("-D- end %s\n\n", cModule);
4682 
4683  return -1;
4684  }
4685 
4686  pComm = &(pAPIFile[ii]->sCommAPI);
4687  if (iDebug)
4688  {
4689  printf(" specified remote fileId %d found:\n", iFileId);
4690  printf(" object %s%s%s, filesize %u byte\n",
4691  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
4692  pComm->iFileSize);
4693  }
4694 
4695  /* bzero(pStatBuf, sizeof(pStatBuf)); funktioniert nicht als init */
4696 
4697  /* initialize stat structure with parameters of local stream stdin */
4698  iRC = fstat(0, pStatBuf);
4699  if (iRC)
4700  {
4701  fprintf(fLogClient, "-E- %s: fstat() failed, rc = %d\n", cModule, iRC);
4702  if (iDebug)
4703  printf("-D- end %s\n\n", cModule);
4704 
4705  return -1;
4706  }
4707 
4708  /* now set correct file size */
4709  pStatBuf->st_size = pComm->iFileSize;
4710 
4711  if (iDebug)
4712  printf("-D- end %s\n\n", cModule);
4713 
4714  return 0;
4715 
4716 } /* rfio_fstat */
4717 
4718 /********************************************************************
4719  * rfio_parse: for remote file in GSI mass storage
4720  * parse name to host and path
4721  *
4722  * created 4.12.2000, Horst Goeringer
4723  ********************************************************************
4724  */
4725 
4726 int rfio_parse(char *pcFile, /* file name */
4727  char **pcNode,
4728  char **pcPath)
4729 {
4730  char cModule[32] = "rfio_parse";
4731  int iDebug = 0;
4732 
4733  if (iDebug)
4734  printf("\n-D- begin %s\n", cModule);
4735 
4736  if (iDebug)
4737  printf("-D- end %s\n", cModule);
4738 
4739  return 0;
4740 
4741 } /* rfio_parse */
4742 
4743 /********************************************************************
4744  * rfio_perror: for remote file in GSI mass storage
4745  * print error message to stderr
4746  *
4747  * created 26. 2.2001, Horst Goeringer
4748  ********************************************************************
4749  */
4750 
4751 void rfio_perror(const char *pUMsg) /* user prefix to error message */
4752 {
4753  char cModule[32] = "rfio_perror";
4754  int iDebug = 0;
4755 
4756  if (iDebug)
4757  printf("\n-D- begin %s\n", cModule);
4758 
4759  if (strlen(rfio_errmsg) == 0)
4760  fprintf(stderr, "%s : No error message\n", pUMsg);
4761  else
4762  fprintf(stderr, "%s : %s\n", pUMsg, rfio_errmsg);
4763 
4764  if (iDebug)
4765  printf("-D- end %s\n", cModule);
4766 
4767  return;
4768 
4769 } /* rfio_perror */
4770 
4771 /********************************************************************
4772  * rfio_serror: for remote file in GSI mass storage
4773  * print last RFIO related error message to string
4774  *
4775  * created 26. 2.2001, Horst Goeringer
4776  ********************************************************************
4777  */
4778 
4779 char * rfio_serror()
4780 {
4781  char cModule[32] = "rfio_serror";
4782  int iDebug = 0;
4783 
4784  if (iDebug) printf(
4785  "\n-D- begin %s: error (len %d byte):\n",
4786  cModule, (int) strlen(rfio_errmsg));
4787 
4788  printf("%s", rfio_errmsg);
4789  fprintf(fLogClient, "%s", rfio_errmsg);
4790 
4791  if (iDebug)
4792  printf("-D- end %s\n", cModule);
4793 
4794  if (strlen(rfio_errmsg) == 0)
4795  return NULL;
4796 
4797  return rfio_errmsg;
4798 
4799 } /* rfio_serror */
4800 
4801 /********************************************************************
4802  * rfio_unlink: for remote file in GSI mass storage
4803  *
4804  * created 4.12.2000, Horst Goeringer
4805  ********************************************************************
4806  */
4807 
4808 int rfio_unlink(const char *pcFile) /* file name */
4809 {
4810  char cModule[32] = "rfio_unlink";
4811  int iDebug = 0;
4812 
4813  if (iDebug)
4814  printf("\n-D- begin %s\n", cModule);
4815 
4816  fprintf(fLogClient,
4817  "-W- %s not yet implemented for gStore\n", cModule);
4818 
4819  if (iDebug)
4820  printf("-D- end %s\n", cModule);
4821 
4822  return 1;
4823 
4824 } /* rfio_unlink */
4825 
4826 /********************************************************************
4827  * rfiosetopt: for remote file in GSI mass storage
4828  *
4829  * created 9. 9.2002, Horst Goeringer
4830  ********************************************************************
4831  */
4832 
4833 int rfiosetopt(int iopt, int *pival, int ilen)
4834 {
4835  char cModule[32] = "rfiosetopt";
4836  int iDebug = 0;
4837 
4838  if (iDebug)
4839  printf("\n-D- begin %s\n", cModule);
4840 
4841  if (iDebug)
4842  printf("-D- end %s\n", cModule);
4843 
4844  return 0;
4845 
4846 } /* rfiosetopt */
4847 
4848 /********************************************************************
4849  * rfio_mkdir: for remote file in GSI mass storage
4850  *
4851  * created 28. 8.2003, Horst Goeringer
4852  ********************************************************************
4853  */
4854 
4855 int rfio_mkdir(const char *path, int mode)
4856 {
4857  char cModule[32] = "rfio_mkdir";
4858  int iDebug = 0;
4859 
4860  if (iDebug)
4861  printf("\n-D- begin %s\n", cModule);
4862 
4863  fprintf(fLogClient,
4864  "-W- %s not yet implemented for gStore\n", cModule);
4865 
4866  if (iDebug)
4867  printf("-D- end %s\n", cModule);
4868 
4869  return 0;
4870 
4871 } /* rfio_mkdir */
4872 
4873 /********************************************************************
4874  * rfio_opendir: for remote file in GSI mass storage
4875  *
4876  * created 28. 8.2003, Horst Goeringer
4877  ********************************************************************
4878  */
4879 
4880 void *rfio_opendir(const char *dirpath)
4881 {
4882  char cModule[32] = "rfio_opendir";
4883  int iDebug = 0;
4884 
4885  if (iDebug)
4886  printf("\n-D- begin %s\n", cModule);
4887 
4888  fprintf(fLogClient,
4889  "-W- %s not yet implemented for gStore\n", cModule);
4890 
4891  if (iDebug)
4892  printf("-D- end %s\n", cModule);
4893 
4894  return 0;
4895 
4896 } /* rfio_opendir */
4897 
4898 /********************************************************************
4899  * rfio_readdir: for remote file in GSI mass storage
4900  *
4901  * created 28. 8.2003, Horst Goeringer
4902  ********************************************************************
4903  */
4904 
4905 void *rfio_readdir(void *dirp)
4906 {
4907  char cModule[32] = "rfio_readdir";
4908  int iDebug = 0;
4909 
4910  if (iDebug)
4911  printf("\n-D- begin %s\n", cModule);
4912 
4913  fprintf(fLogClient,
4914  "-W- %s not yet implemented for gStore\n", cModule);
4915 
4916  if (iDebug)
4917  printf("-D- end %s\n", cModule);
4918 
4919  return 0;
4920 
4921 } /* rfio_readdir */
4922 
4923 /********************************************************************
4924  * rfio_closedir: for remote file in GSI mass storage
4925  *
4926  * created 28. 8.2003, Horst Goeringer
4927  ********************************************************************
4928  */
4929 
4930 int rfio_closedir(void *dirp)
4931 {
4932  char cModule[32] = "rfio_closedir";
4933  int iDebug = 0;
4934 
4935  if (iDebug)
4936  printf("\n-D- begin %s\n", cModule);
4937 
4938  fprintf(fLogClient,
4939  "-W- %s not yet implemented for gStore\n", cModule);
4940 
4941  if (iDebug)
4942  printf("-D- end %s\n", cModule);
4943 
4944  return 0;
4945 
4946 } /* rfio_closedir */
4947 
4948 #ifdef __USE_LARGEFILE64
4949 
4950 /********************************************************************
4951  * rfio_stat64: for remote file in GSI mass storage
4952  * get file status
4953  *
4954  * created 29. 5.2007, Horst Goeringer
4955  ********************************************************************
4956  */
4957 
4958 int rfio_stat64(const char *pcFile, struct stat64 *pStatBuf64)
4959 {
4960  char cModule[32] = "rfio_stat64";
4961  int iDebug = 0;
4962  int iRC;
4963 
4964  int iMapFound = 0; /* =1: specified file already open */
4965  int iFileId = -1;
4966  int ii;
4967  char *pcc;
4968  char cObject[MAX_FULL_FILE] = "";
4969 
4970  srawComm *pComm;
4971  unsigned long *plFileSizeC; /* ptr to file size in sComm */
4972 
4973  if (iDebug)
4974  fprintf(fLogClient, "\n-D- begin %s: file %s\n", cModule, pcFile);
4975 
4976  ii = sizeof(long);
4977  if (ii < 8)
4978  {
4979  fprintf(fLogClient,
4980  "-E- 32 bit client: %s not supported\n", cModule);
4981 
4982  return -1;
4983  }
4984 
4985  iOnlyQuery = 1; /* no DM selection */
4986  ii = 0;
4987  if (iFileCount > 0)
4988  while (ii <= iFileMax)
4989  {
4990  if (pAPIFile[ii] != NULL)
4991  {
4992  pComm = &(pAPIFile[ii]->sCommAPI);
4993  strcpy(cObject, pComm->cNamefs);
4994  strcat(cObject, pComm->cNamehl);
4995  strcat(cObject, pComm->cNamell);
4996 
4997  if (iDebug) fprintf(fLogClient,
4998  " %d: %s already open\n", ii, cObject);
4999 
5000  pcc = strstr(pcFile, cObject);
5001  if (pcc != NULL)
5002  {
5003  iMapFound = 1;
5004  if (iDebug)
5005  fprintf(fLogClient, " %d: %s maps\n", ii, cObject);
5006  break;
5007  }
5008  }
5009  else if (iDebug) fprintf(fLogClient,
5010  " %d: no (more) open file found\n", ii);
5011 
5012  ii++;
5013  }
5014 
5015  if (iMapFound == 0)
5016  {
5017  if (iDebug) fprintf(fLogClient,
5018  " remote file %s not yet open\n", pcFile);
5019 
5020  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5021  if (iFileId < 0) fprintf(fLogClient,
5022  "-E- %s: open for remote file %s failed\n", cModule, pcFile);
5023  }
5024  else
5025  {
5026  iFileId = pAPIFile[ii]->iFileId;
5027  if (iFileId < 0) fprintf(fLogClient,
5028  "-E- %s: invalid handle (%d) for remote file %s found\n",
5029  cModule, iFileId, pcFile);
5030  }
5031 
5032  /* info still available, must be freed here */
5033  if (iFileId >= 0)
5034  {
5035  pComm = &(pAPIFile[ii]->sCommAPI);
5036  plFileSizeC = (unsigned long *) &(pComm->iFileSize);
5037 
5038  if (iDebug)
5039  {
5040  fprintf(fLogClient, " remote fileId %d:\n", iFileId);
5041  fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
5042  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5043  *plFileSizeC);
5044  }
5045 
5046  /* for caller */
5047  pStatBuf64->st_size = *plFileSizeC;
5048 
5049  free(pAPIFile[iFileId]);
5050  pAPIFile[iFileId] = NULL;
5051  iFileCount--;
5052  }
5053 
5054 
5055  if (iDebug)
5056  fprintf(fLogClient, "-D- end %s\n\n", cModule);
5057 
5058  return iRC;
5059 
5060 } /* rfio_stat64 */
5061 
5062 #endif /* __USE_LARGEFILE64 */
5063 
5064 /********************************************************************
5065  * rfio_stat: for remote file in GSI mass storage
5066  * get file status
5067  *
5068  * created 28. 8.2003, Horst Goeringer
5069  ********************************************************************
5070  */
5071 
5072 int rfio_stat(const char *pcFile, struct stat *pStatBuf)
5073 {
5074  char cModule[32] = "rfio_stat";
5075  int iDebug = 0;
5076 
5077  int iMapFound = 0; /* =1: specified file already open */
5078  int iFileId = -1;
5079  int iRC;
5080  int ii;
5081  char *pcc;
5082  char cObject[MAX_FULL_FILE] = "";
5083 
5084  srawComm *pComm;
5085 
5086  if (iDebug)
5087  printf("\n-D- begin %s\n", cModule);
5088 
5089  iOnlyQuery = 1; /* no DM selection */
5090  ii = 0;
5091  if (iFileCount > 0)
5092  while (ii <= iFileMax)
5093  {
5094  if (pAPIFile[ii] != NULL)
5095  {
5096  pComm = &(pAPIFile[ii]->sCommAPI);
5097  strcpy(cObject, pComm->cNamefs);
5098  strcat(cObject, pComm->cNamehl);
5099  strcat(cObject, pComm->cNamell);
5100 
5101  if (iDebug)
5102  printf(" %d: %s already open\n", ii, cObject);
5103 
5104  pcc = strstr(pcFile, cObject);
5105  if (pcc != NULL)
5106  {
5107  iMapFound = 1;
5108  if (iDebug)
5109  printf(" %d: %s maps\n", ii, cObject);
5110  break;
5111  }
5112  }
5113  else if (iDebug)
5114  printf(" %d: no (more) open file found\n", ii);
5115 
5116  ii++;
5117  }
5118 
5119  if (iMapFound == 0)
5120  {
5121  if (iDebug) printf(
5122  " remote file %s not yet open\n", pcFile);
5123 
5124  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5125  if (iFileId < 0) fprintf(fLogClient,
5126  "-E- %s: open for remote file %s failed\n", cModule, pcFile);
5127  }
5128  else
5129  {
5130  iFileId = pAPIFile[ii]->iFileId;
5131  if (iFileId < 0) fprintf(fLogClient,
5132  "-E- %s: invalid handle (%d) for remote file %s found\n",
5133  cModule, iFileId, pcFile);
5134  }
5135 
5136  /* info still available, must be freed here */
5137  if (iFileId >= 0)
5138  {
5139  pComm = &(pAPIFile[ii]->sCommAPI);
5140  if (iDebug)
5141  {
5142  printf(" remote fileId %d:\n", iFileId);
5143  printf(" object %s%s%s, filesize %u byte\n",
5144  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5145  pComm->iFileSize);
5146  }
5147 
5148  /* for caller */
5149  pStatBuf->st_size = pComm->iFileSize;
5150 
5151  free(pAPIFile[iFileId]);
5152  pAPIFile[iFileId] = NULL;
5153  iFileCount--;
5154  }
5155 
5156  if (iDebug)
5157  printf("-D- end %s\n\n", cModule);
5158 
5159  if (iFileId >= 0)
5160  return 0;
5161  else
5162  return iFileId;
5163 
5164 } /* rfio_stat */
5165 
5166 /********************************************************************
5167  * rfio_cache_stat: for remote file in GSI mass storage
5168  * returns cache status of file:
5169  * < 0: not in gStore or error
5170  * = 0: in offline storage, staging before access strongly recommended
5171  * > 0: available for fast access
5172  * = 1: in read cache (staged)
5173  * = 2: in write cache, staging before access recommended
5174  * (users do not know when migration to offline storage
5175  * takes place)
5176  *
5177  * created 12.11.2008, Horst Goeringer
5178  ********************************************************************
5179  */
5180 
5181 int rfio_cache_stat(const char *pcFile)
5182 {
5183  char cModule[32] = "rfio_cache_stat";
5184  int iDebug = 0;
5185 
5186  int iMapFound = 0; /* =1: specified file already open */
5187  int iFileId = -1;
5188  int iRC;
5189  int iCache = 0; /* to be returned */
5190  int ii;
5191  char *pcc;
5192  char cObject[MAX_FULL_FILE] = "";
5193 
5194  srawComm *pComm;
5195 
5196  if (iDebug)
5197  {
5198  printf("\n-D- begin %s: %d files open\n", cModule, iFileCount);
5199  printf(" get cache status of file %s\n", pcFile);
5200  }
5201 
5202  iOnlyQuery = 1; /* no DM selection */
5203  ii = 0;
5204  if (iFileCount > 0)
5205  while (ii <= iFileMax)
5206  {
5207  if (pAPIFile[ii] != NULL)
5208  {
5209  pComm = &(pAPIFile[ii]->sCommAPI);
5210  strcpy(cObject, pComm->cNamefs);
5211  strcat(cObject, pComm->cNamehl);
5212  strcat(cObject, pComm->cNamell);
5213 
5214  if (iDebug)
5215  printf(" %d: %s already open\n", ii, cObject);
5216 
5217  pcc = strstr(pcFile, cObject);
5218  if (pcc != NULL)
5219  {
5220  iMapFound = 1;
5221  if (iDebug)
5222  printf(" %d: %s maps\n", ii, cObject);
5223  break;
5224  }
5225  }
5226  else if (iDebug)
5227  printf(" %d: no (more) open file found\n", ii);
5228 
5229  ii++;
5230  }
5231 
5232  if (iMapFound == 0)
5233  {
5234  if (iDebug) printf(
5235  " remote file %s not yet open\n", pcFile);
5236 
5237  iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
5238  if (iFileId < 0)
5239  {
5240  fprintf(fLogClient,
5241  "-E- remote file %s not in gStore or unavailable\n",
5242  pcFile);
5243 
5244  iCache = -1;
5245  goto gEndCacheStat;
5246  }
5247 
5248  if (iDebug) printf(
5249  " remote file %s successfully opened for query and closed\n", pcFile);
5250  }
5251  else
5252  {
5253  iFileId = pAPIFile[ii]->iFileId;
5254  if (iFileId < 0)
5255  {
5256  fprintf(fLogClient,
5257  "-E- %s: invalid handle (%d) for remote file %s found\n",
5258  cModule, iFileId, pcFile);
5259 
5260  iCache = -1;
5261  goto gEndCacheStat;
5262  }
5263  }
5264 
5265  /* info still available, must be freed here */
5266  if (iFileId >= 0)
5267  {
5268  pComm = &(pAPIFile[ii]->sCommAPI);
5269  if (pComm->iStageFSid > 0)
5270  iCache = 1; /* file in read cache */
5271  else if (pComm->iFSidWC > 0)
5272  iCache = 2; /* file in write cache */
5273  else
5274  iCache = 0; /* file not in cache */
5275 
5276  if (iDebug)
5277  {
5278  printf(" remote fileId %d:\n", iFileId);
5279  printf(" object %s%s%s, size %u byte, cache status %d\n",
5280  pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
5281  pComm->iFileSize, iCache);
5282  if (pComm->iStageFSid > 0)
5283  printf(" read cache FS %d\n", pComm->iStageFSid);
5284  else if (pComm->iFSidWC > 0)
5285  printf(" write cache FS %d\n", pComm->iFSidWC);
5286  }
5287 
5288  free(pAPIFile[iFileId]);
5289  pAPIFile[iFileId] = NULL;
5290  iFileCount--;
5291  }
5292 
5293 gEndCacheStat:
5294  iOnlyQuery = 0;
5295  if (iDebug)
5296  printf("-D- end %s\n\n", cModule);
5297 
5298  return iCache;
5299 
5300 } /* rfio_cache_stat */
5301 
5302 /********************************************************************
5303  * rfio_gsi_query: query file information of opened remote file
5304  *
5305  * created 7. 2.2001, Horst Goeringer
5306  ********************************************************************
5307  */
5308 
5309 int rfio_gsi_query(int iFileId, /* file id */
5310  int iFull, /* verbosity */
5311  int iOut, /* max length output string */
5312  char *pInfo) /* info string */
5313 {
5314  char cModule[32] = "rfio_gsi_query";
5315  int iDebug = 0;
5316  int iRC = 0;
5317  int ii = 0;
5318 
5319  srawAPIFile *pcurAPIFile;
5320  srawObjAttr *pQueryAPI; /* query information */
5321 
5322  if (iDebug)
5323  printf("\n-D- begin %s\n", cModule);
5324 
5325  if (iFileCount == 0)
5326  {
5327  printf("-E- %s: no remote file available\n", cModule);
5328  iRC = -1;
5329  goto gEndQuery;
5330  }
5331 
5332  while (ii < iFileMax)
5333  {
5334  if (pAPIFile[ii])
5335  {
5336  if (pAPIFile[ii]->iFileId == iFileId)
5337  break;
5338  }
5339  ii++;
5340  }
5341 
5342  if (ii == iFileMax)
5343  {
5344  printf("-E- %s: remote file %d not found\n", cModule, iFileId);
5345  iRC = -1;
5346  goto gEndQuery;
5347  }
5348 
5349  pcurAPIFile = pAPIFile[iFileId];
5350  pQueryAPI = &(pcurAPIFile->sQueryAPI);
5351  iRC = rawQueryString(pQueryAPI, iFull, iOut, pInfo);
5352  if (iDebug)
5353  {
5354  printf(" %s\n", pInfo);
5355  if (iRC != iOut) printf(
5356  " (used %d byte, avail %d byte)\n", iRC, iOut);
5357  }
5358 
5359 gEndQuery:
5360  if (iDebug)
5361  printf("-D- end %s\n\n", cModule);
5362 
5363  return iRC;
5364 
5365 } /* rfio_gsi_query */
5366 
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:2529
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:736
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:2043
#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:4808
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:4645
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:4726
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:4855
#define MAX_ATLSERVER
Definition: rawcommn.h:202
void rfio_perror(const char *pUMsg)
Definition: rawapin.c:4751
#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:3016
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:2842
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:5181
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:4002
#define RFILE
Definition: rawapigsi.h:17
int rawSendStatus(int, int, char *)
Definition: rawProcn.c:2113
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:3939
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:4833
int iSockMaster
Definition: rawclin.h:146
size_t rfio_fwrite(const char *pcBuffer, size_t iSize, size_t iItems, RFILE *pRemFile)
Definition: rawapin.c:4345
srawCopyCache sCopyCacheServ
Definition: rawclin.h:165
char * rawGetHLName(char *)
Definition: rawProcn.c:657
int iStageFSid
Definition: rawcommn.h:426
int rawQueryFile(int, int, srawComm *, void **)
Definition: rawProcn.c:946
int rfio_fendfile(RFILE *pRemFile)
Definition: rawapin.c:4385
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:166
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:600
int iCommLen
Definition: rawcommn.h:400
size_t rfio_fread(char *pcBuffer, size_t iSize, size_t iItems, RFILE *pRemFile)
Definition: rawapin.c:4307
static char cNamehl[MAX_OBJ_HL]
Definition: rawProcn.c:167
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:1286
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:4442
char * rfio_serror()
Definition: rawapin.c:4779
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:4042
char cArchiveDate[MAX_DATE]
Definition: rawcommn.h:659
void * rfio_readdir(void *dirp)
Definition: rawapin.c:4905
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:3716
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:5072
int rawRecvStatus(int, char *)
Definition: rawProcn.c:1904
#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:4930
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:5309
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:4880
int rawRecvHeadC(int, char *, int, int, char *)
Definition: rawProcn.c:1495
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:4414
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:4151
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:4238