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