00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 #include <stdio.h>
00147 #include <ctype.h>
00148 #include <string.h>
00149 #include <fcntl.h>
00150 #include <time.h>
00151 #include <stdlib.h>
00152
00153 #ifdef Linux
00154 #include <netinet/in.h>
00155 #include <sys/stat.h>
00156 #include <unistd.h>
00157 #endif
00158
00159 FILE *fLogClient = NULL;
00160 #define MAX_LOG_FILE 64
00161 static char cLogClient[MAX_LOG_FILE] = "";
00162 static int iLogFile = 1;
00163 static int iOS64 = 0;
00164
00165 #ifdef Lynx
00166 #include "error_mac.h"
00167 #include "errnum_def.h"
00168 #include "err_mask_def.h"
00169 #include "f_ut_printm.h"
00170
00171 #define fprintf fprintm
00172
00173 #endif
00174
00175 #include "rawdefn.h"
00176 #include "rawapin.h"
00177 #include "rawentn.h"
00178
00179 #include "rawapitd.h"
00180 #include "rawapitd-gsin.h"
00181 #include "rawapplcli.h"
00182
00183 int* piEntryList;
00184 int imySigS;
00185 FILE *fLogFile = NULL;
00186
00187
00188 int serrno;
00189 int rfio_errno;
00190 int tStageHostKey;
00191 int tStagePortKey;
00192 int tSvcClassKey;
00193 int tCastorVersionKey;
00194
00195 char *rawGetFSpName(char *);
00196
00197 static char rfio_errmsg[STATUS_LEN] = "";
00198
00199 #define MAX_BUFSIZE 32768
00200 static int iint = sizeof(int);
00201 static int irawComm = sizeof(srawComm);
00202 static int iObjAttr = sizeof(srawObjAttr);
00203 static int irawFileSystem = sizeof(srawFileSystem);
00204 static int irawCopyCache = sizeof(srawCopyCache);
00205 static int irawAPIFile = sizeof(srawAPIFile);
00206
00207 static int iOnlyQuery = 0;
00208 static char cPrefix[MAX_FULL_FILE] = "";
00209 static char cNodePrefix[MAX_NODE] = "";
00210 static char cNodeMaster[MAX_NODE] = "";
00211 static char cNodeMover[MAX_NODE] = "";
00212 static int iPortMaster = PORT_MASTER;
00213 static int iPortMover = PORT_MOVER;
00214 static int iATLServer;
00215
00216
00217 static int iStatusLoopMax = MAXLOOP_CACHE_FULL;
00218
00219 static int iSleepCacheFull = SLEEP_CACHE_FULL;
00220
00221 static int iFileCount = 0;
00222 static int iFileMax = 10;
00223 static RFILE *pAPIFile[10] =
00224 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
00225
00226 #ifdef __USE_LARGEFILE64
00227
00228
00229
00230
00231
00232
00233
00234
00235 int rfio_open64(const char *pcFile,
00236 int iFlags,
00237 int iMode)
00238 {
00239 char cModule[32] = "rfio_open64";
00240 int iDebug = 0;
00241 int iFileId = -1;
00242 int ii;
00243
00244 if (iDebug) fprintf(fLogClient,
00245 "\n-D- begin %s: file %s, flags %d, mode %d\n",
00246 cModule, pcFile, iFlags, iMode);
00247
00248 ii = sizeof(long);
00249 if (ii < 8)
00250 {
00251 fprintf(fLogClient,
00252 "-E- 32 bit client: %s not supported\n", cModule);
00253
00254 return -1;
00255 }
00256
00257 iFileId = rfio_open(pcFile, iFlags, iMode);
00258
00259 if (iDebug) fprintf(fLogClient,
00260 "-D- end %s: iFileId(rfio_open) = %d\n\n", cModule, iFileId);
00261
00262 return iFileId;
00263
00264 }
00265
00266 #endif
00267
00268
00269
00270
00271
00272
00273
00274
00275 int rfio_open(const char *pcFile,
00276 int iFlags,
00277 int iOpenMode)
00278 {
00279 char cModule[32] = "rfio_open";
00280 int iDebug = 0;
00281 int iFileId = -1;
00282 int iCopyMode = 0;
00283 char *pcCopyPath = NULL;
00284 int iCopyFraction = 0;
00285 int iMaxFile = 0;
00286 int iPathConvention = 0;
00287
00288 if (iDebug)
00289 printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
00290
00291 iFileId = rfio_open_gsidaq(pcFile, iFlags, iOpenMode,
00292 iCopyMode,
00293 pcCopyPath,
00294 iCopyFraction,
00295 iMaxFile,
00296 iPathConvention);
00297
00298 if (iDebug) printf(
00299 "-D- end %s, iFileId(rfio_open_gsidaq) = %d\n\n",
00300 cModule, iFileId);
00301
00302 return iFileId;
00303
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 int rfio_open_gsidaq(
00315 const char *pcFile,
00316 int iFlags,
00317 int iOpenMode,
00318 int iCopyMode,
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 char *pcCopyPath,
00330
00331
00332
00333
00334
00335
00336
00337 int iCopyFraction,
00338
00339
00340 int iMaxFile,
00341
00342
00343
00344
00345
00346
00347
00348 int iPathConvention)
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 {
00359 char cModule[32] = "rfio_open_gsidaq";
00360 int iDebug = 0;
00361 int iRC;
00362 int iMaxConnect = 0;
00363 int ii1, ii2;
00364
00365 #ifndef Lynx
00366 char cstr[16];
00367 time_t tstr;
00368 time_t tcur;
00369 struct tm *ptloc;
00370 pid_t pstr;
00371 #endif
00372
00373 unsigned long *plFileSizeC;
00374 int iObjInit = 1;
00375 int iMassSto = -1;
00376
00377
00378
00379
00380 int iStage = 0;
00381 int iCache = 0;
00382 int iStatus = 0;
00383 int iStatusLen = 0;
00384 int iIdent;
00385 int iBuf, iBufl;
00386 int iDataMoverSelect = 0;
00387
00388 int iStatusOkay = 0;
00389 int iStatusLoop = 0;
00390
00391 int iPoolId = 0;
00392
00393
00394 int iAction = 0;
00395 int iError = 0;
00396 int iSendEOS = 0;
00397
00398
00399 int iFileId = -1;
00400 char cServer[24] = "";
00401 int iSockMaster = -1;
00402 int iSockMover = -1;
00403
00404 int iSeekMode = -1;
00405 int iOffset = 0;
00406 int iBufsizeAct = 0;
00407 int iBufnoServ = 0;
00408 int iDataServ = 0;
00409
00410 int iMapFound = 0;
00411 int ii;
00412 char *pcc, *pcc1;
00413 char cTemp[STATUS_LEN] = "";
00414 char cMsg[STATUS_LEN] = " ";
00415 char cNamefs[MAX_OBJ_FS] = "", *pcNamefs;
00416 char cNamehl[MAX_OBJ_HL] = "", *pcNamehl;
00417 char cNamell[MAX_OBJ_LL] = "", *pcNamell;
00418 char cObject[MAX_FULL_FILE] = "";
00419
00420 char cOwner[DSM_MAX_OWNER_LENGTH] = "";
00421 char cliNode[MAX_NODE] = "";
00422 char cAccess[16] = "";
00423
00424 struct tm buf_time;
00425
00426 srawDataMover sDataMoverSelect;
00427
00428 srawDataMoverAttr *pDataMoverSelect;
00429
00430 srawStatus sStatus;
00431 srawAPIFile *pcurAPIFile;
00432 srawComm *pCommAPI;
00433 srawComm *pCommServ;
00434 srawObjAttr *pQueryAPI;
00435 srawCopyCache *pCopyCacheServ;
00436
00437
00438 srawFileSystem sFileSystemServ;
00439
00440
00441 void *pBufQuery;
00442 srawQueryResult sQuery;
00443 srawObjAttr *pQAttr = NULL;
00444
00445 if (fLogFile == NULL)
00446 fLogFile = stdout;
00447 if (fLogClient == NULL)
00448 fLogClient = stdout;
00449
00450 pDataMoverSelect = &(sDataMoverSelect.sDataMoverAttr);
00451 pcNamefs = cNamefs;
00452 pcNamehl = cNamehl;
00453 pcNamell = cNamell;
00454
00455 if (iFlags == O_RDONLY)
00456 {
00457 iAction = 1;
00458 strcpy(cAccess, "read");
00459 }
00460 else
00461 {
00462 iAction = 2;
00463 strcpy(cAccess, "write");
00464 }
00465
00466 ii = sizeof(long);
00467 if (ii == 8)
00468 iOS64 = 1;
00469 else if (ii != 4) printf(
00470 "-W- unexpected size of long integer: %d byte\n", ii);
00471
00472 if (iDebug)
00473 {
00474 ii *= 8;
00475 printf("\n-D- begin %s (%d bit OS)", cModule, ii);
00476 if (iFileCount)
00477 printf(", %d remote files currently open", iFileCount);
00478 printf("\n");
00479 }
00480
00481 ii = 0;
00482 if (iFileCount > 0)
00483 while (ii < iFileMax)
00484 {
00485 if (pAPIFile[ii] != NULL)
00486 {
00487 pCommAPI = &(pAPIFile[ii]->sCommAPI);
00488 strcpy(cObject, pCommAPI->cNamefs);
00489 strcat(cObject, pCommAPI->cNamehl);
00490 strcat(cObject, pCommAPI->cNamell);
00491
00492 if (iDebug)
00493 printf(" %d: %s already open\n", ii, cObject);
00494
00495 pcc = strstr(pcFile, cObject);
00496 if (pcc != NULL)
00497 {
00498 iMapFound = 1;
00499 if (iDebug)
00500 printf(" %d: %s maps\n", ii, cObject);
00501 break;
00502 }
00503 }
00504 else if (iDebug)
00505 printf(" %d: no (more) open file found\n", ii);
00506
00507 ii++;
00508 }
00509
00510 if (iMapFound)
00511 {
00512 fprintf(fLogClient,
00513 "-E- %s: requested file %s is already open\n",
00514 cModule, pcFile);
00515
00516 iError = -1;
00517 goto gError;
00518 }
00519
00520 if (ii == iFileMax)
00521 {
00522 fprintf(fLogClient,
00523 "-E- %s: max %d remote files may be open simultaneously\n",
00524 cModule, iFileMax);
00525
00526 iError = -1;
00527 goto gError;
00528 }
00529
00530 pAPIFile[ii] = (srawAPIFile *) malloc((unsigned) irawAPIFile);
00531 if (pAPIFile[ii] == NULL)
00532 {
00533 fprintf(fLogClient,
00534 "-E- %s: allocating file control block no. %d (%d byte)\n",
00535 cModule, ii, irawAPIFile);
00536 perror(" ");
00537
00538 iError = -1;
00539 goto gError;
00540 }
00541
00542 iFileId = ii;
00543 iFileCount++;
00544 if (iDebug) printf(
00545 " file control block no. %d allocated (%d byte)\n",
00546 ii, irawAPIFile);
00547
00548 pcurAPIFile = pAPIFile[ii];
00549 if (iOpenMode < 0)
00550 {
00551 iOpenMode = 0;
00552 iOnlyQuery = 1;
00553 pcurAPIFile->iOpMode = 2;
00554
00555 if (iDebug)
00556 printf(" query only, iOpenMode %d reset to 0\n", iOpenMode);
00557 }
00558 else
00559 pcurAPIFile->iOpMode = 0;
00560
00561 pcurAPIFile->iFileId = iFileId;
00562 pcurAPIFile->iFlags = iFlags;
00563 pcurAPIFile->iMode = iOpenMode;
00564 pcurAPIFile->iSockMaster = -1;
00565 pcurAPIFile->iSockMover = -1;
00566 pcurAPIFile->iSeekMode = iSeekMode;
00567 pcurAPIFile->iOffset = iOffset;
00568 pcurAPIFile->iBufsizeAct = iBufsizeAct;
00569 pcurAPIFile->iBufnoServ = iBufnoServ;
00570 pcurAPIFile->iDataServ = iDataServ;
00571 pcurAPIFile->iAction = iAction;
00572
00573 pCommAPI = &(pcurAPIFile->sCommAPI);
00574 pCommAPI->iIdent = IDENT_COMM;
00575 pCommAPI->iCommLen = irawComm - HEAD_LEN;
00576 if (iOS64)
00577 pCommAPI->iClient32 = 0;
00578 else
00579 pCommAPI->iClient32 = 1;
00580
00581 pQueryAPI = &(pcurAPIFile->sQueryAPI);
00582 pCommServ = &(pcurAPIFile->sCommServ);
00583 pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
00584
00585
00586
00587 if ( (strchr(pcFile, *pcStar) != NULL) ||
00588 (strchr(pcFile, *pcQM) != NULL) ||
00589 (strchr(pcFile, *pcPerc) != NULL) )
00590 {
00591 fprintf(fLogClient,
00592 "-E- %s: files with wildcard characters ('%s') not allowed using RFIO\n",
00593 cModule, pcFile);
00594
00595 iError = -1;
00596 goto gError;
00597 }
00598
00599
00600 pcc = (char *) strchr(pcFile, *pcDevDelim);
00601 if (pcc == NULL)
00602 {
00603 fprintf(fLogClient,
00604 "-E- %s(1): invalid remote file name '%s': node name missing\n",
00605 cModule, pcFile);
00606
00607 iError = -1;
00608 goto gError;
00609 }
00610
00611
00612 strcpy(cTemp, pcFile);
00613 pcc = (char *) strrchr(cTemp, *pcDevDelim);
00614 pcc++;
00615 strncpy(pcc, "\0", 1);
00616 pcc1 = cTemp;
00617 strcpy(cPrefix, pcc1);
00618 while (*pcc1 != '\0')
00619 {
00620 *pcc1 = tolower(*pcc1);
00621 pcc1++;
00622 }
00623
00624
00625 if (iDebug)
00626 printf(" URL in small letters: '%s'\n", cTemp);
00627
00628
00629 pcc = strstr(cTemp, ".gsi.de");
00630 if (pcc)
00631 {
00632 strncpy(pcc++, ":", 1);
00633 strncpy(pcc, "\0", 1);
00634 if (iDebug)
00635 printf(" remove trailing '.gsi.de': %s\n", cTemp);
00636 }
00637
00638
00639 if (strncmp(cTemp, "rfio", 4) == 0)
00640 {
00641 pcc = (char *) strchr(cTemp, *pcDevDelim);
00642 pcc++;
00643 pcc1 = (char *) strrchr(pcc, *pcDevDelim);
00644 if (pcc1 == NULL)
00645 {
00646 fprintf(fLogClient,
00647 "-E- %s(2): invalid prefix '%s' of remote file name: node name missing\n",
00648 cModule, pcFile);
00649
00650 iError = -1;
00651 goto gError;
00652 }
00653 strncpy(pcc1, "\0", 1);
00654
00655
00656 if (strlen(pcc) == 0)
00657 {
00658 fprintf(fLogClient,
00659 "-E- %s(3): invalid remote file name '%s': node name missing\n",
00660 cModule, pcFile);
00661
00662 iError = -1;
00663 goto gError;
00664 }
00665
00666 strcpy(cNodePrefix, pcc);
00667 if (iDebug)
00668 printf(" node name after prefix 'rfio': '%s'\n", cNodePrefix);
00669
00670 if (strncmp(cTemp, "rfiodaq:", 8) == 0)
00671 {
00672 if ( (iAction == 1) && (iOnlyQuery == 0) )
00673 {
00674 fprintf(fLogClient, "-E- %s: reading from DaqPool not allowed\n",
00675 cModule);
00676 fprintf(fLogClient, " correct object specification:\n");
00677 fprintf(fLogClient, " [rfio:]node:/archive/path/file\n");
00678
00679 iError = -1;
00680 goto gError;
00681 }
00682
00683 iMassSto = 2;
00684 strcpy(cServer, "gStore entry server");
00685 iPoolId = 4;
00686 }
00687 else if (strncmp(cTemp, "rfio:", 5) == 0)
00688 {
00689 iMassSto = 1;
00690 strcpy(cServer, "gStore entry server");
00691 if (iAction == 1)
00692 {
00693 if (iOnlyQuery == 0)
00694 iPoolId = 2;
00695 }
00696 else if (iAction == 2)
00697 iPoolId = 3;
00698 }
00699 else if (strncmp(cTemp, "rfiocopy:", 9) == 0)
00700 {
00701 iMassSto = 0;
00702 strcpy(cServer, "RFIO server");
00703 iPoolId = 0;
00704 iPortMaster = PORT_RFIO_SERV;
00705 iPortMover = PORT_RFIO_SERV;
00706 }
00707 else
00708 {
00709 fprintf(fLogClient,
00710 "-E- %s: invalid remote file name '%s': unknown prefix\n",
00711 cModule, pcFile);
00712
00713 iError = -1;
00714 goto gError;
00715 }
00716 }
00717 else
00718 {
00719
00720 pcc = (char *) strchr(cTemp, *pcDevDelim);
00721 pcc1 = (char *) strrchr(pcc, *pcDevDelim);
00722 if (pcc1 != pcc)
00723 {
00724 fprintf(fLogClient,
00725 "-E- %s: invalid remote file name '%s': invalid prefix\n",
00726 cModule, pcFile);
00727
00728 iError = -1;
00729 goto gError;
00730 }
00731
00732 if (strlen(pcc) == 0)
00733 {
00734 fprintf(fLogClient,
00735 "-E- %s(4): invalid remote file name '%s': node name missing\n",
00736 cModule, pcFile);
00737
00738 iError = -1;
00739 goto gError;
00740 }
00741
00742 iMassSto = 1;
00743 strcpy(cServer, "gStore entry server");
00744 if (iAction == 1)
00745 {
00746 if (iOnlyQuery == 0)
00747 iPoolId = 2;
00748 }
00749 else if (iAction == 2)
00750 iPoolId = 3;
00751
00752 strncpy(pcc, "\0", 1);
00753 strcpy(cNodePrefix, cTemp);
00754 if (iDebug)
00755 printf(" node name: '%s'\n", cNodePrefix);
00756 }
00757
00758 if ( (strcmp(cNodePrefix, "adsmexp") == 0) ||
00759 (strcmp(cNodePrefix, "gsitsma") == 0) )
00760 {
00761 fprintf(fLogClient, "-E- %s: gStore server %s no longer supported\n",
00762 cModule, cNodePrefix);
00763
00764 iError = -1;
00765 goto gError;
00766 }
00767
00768 pcurAPIFile->iMassSto = iMassSto;
00769 if (iDebug)
00770 {
00771 if ( (iAction == 2) ||
00772 ((iAction == 1) && (iOnlyQuery == 0)) )
00773 printf(" %s, request poolId %d\n", cServer, iPoolId);
00774 else
00775 printf(" %s\n", cServer);
00776 }
00777
00778
00779
00780 pcc = (char *) strrchr(pcFile, *pcDevDelim);
00781 pcc++;
00782
00783 if ( (strlen(pcc) == 0) || (strcmp(pcc, " ") == 0) )
00784 {
00785 if (iAction == 1)
00786 {
00787 fprintf(fLogClient,
00788 "-E- %s: missing remote object for read access\n", cModule);
00789
00790 iError = -1;
00791 goto gError;
00792 }
00793
00794 pcurAPIFile->iOpMode = 1;
00795 iObjInit = 0;
00796
00797 if (iDebug)
00798 {
00799 if (iMassSto > 0)
00800 printf(" remote object will be initialized later\n");
00801 else
00802 printf(" remote file will be initialized later\n");
00803 }
00804
00805
00806
00807 strcpy(pcNamefs, "");
00808 strcpy(pcNamehl, "");
00809 strcpy(pcNamell, "");
00810 strcpy(pCommAPI->cNamefs, "");
00811 strcpy(pCommAPI->cNamehl, "");
00812 strcpy(pCommAPI->cNamell, "");
00813 }
00814 else
00815 {
00816 iObjInit = 1;
00817 strcpy(cTemp, pcc);
00818 pcc = (char *) strchr(cTemp, *pcObjDelim);
00819 if (pcc == NULL)
00820 {
00821 fprintf(fLogClient,
00822 "-E- %s: invalid remote file name %s\n", cModule, cTemp);
00823
00824 iError = -1;
00825 goto gError;
00826 }
00827
00828 pcc++;
00829 pcc1 = (char *) strchr(pcc, *pcObjDelim);
00830
00831 if (iMassSto > 0)
00832 {
00833 if (iDebug)
00834 printf(" remote object %s\n", cTemp);
00835
00836 if ( (pcc == NULL) || (pcc1 == NULL) )
00837 {
00838 fprintf(fLogClient,
00839 "-E- %s: invalid remote object name '%s': archive name missing\n",
00840 cModule, pcFile);
00841
00842 iError = -1;
00843 goto gError;
00844 }
00845
00846 pcc = pcc1;
00847 strncpy(pcc1, "\0", 1);
00848 if (strlen(cTemp) > MAX_OBJ_FS-1)
00849 {
00850 ii = MAX_OBJ_FS-1;
00851 fprintf(fLogClient, "-E- %s: archive name '%s' too long (max %d)\n",
00852 cModule, cTemp, ii);
00853
00854 iError = -1;
00855 goto gError;
00856 }
00857
00858 if (strlen(cTemp) < 2)
00859 {
00860 fprintf(fLogClient, "-E- %s: invalid archive name '%s'\n",
00861 cModule, cTemp);
00862
00863 iError = -1;
00864 goto gError;
00865 }
00866
00867 strcpy(pcNamefs, cTemp);
00868 if (iDebug)
00869 printf(" archive name %s\n", pcNamefs);
00870
00871 strncpy(pcc, pcObjDelim, 1);
00872 pcc++;
00873 pcc1 = (char *) strrchr(pcc, *pcObjDelim);
00874 if (pcc1 == NULL)
00875 {
00876 fprintf(fLogClient,
00877 "-E- %s: invalid remote object name '%s': path name missing\n",
00878 cModule, pcFile);
00879
00880 iError = -1;
00881 goto gError;
00882 }
00883
00884 if (strlen(pcc1) > MAX_OBJ_LL-1)
00885 {
00886 ii = MAX_OBJ_LL-1;
00887 fprintf(fLogClient, "-E- %s: file name '%s' too long (max %d)\n",
00888 cModule, pcc1, ii);
00889
00890 iError = -1;
00891 goto gError;
00892 }
00893
00894 if (strlen(pcc1) < 2)
00895 {
00896 fprintf(fLogClient, "-E- %s: invalid file name '%s'\n", cModule, pcc1);
00897
00898 iError = -1;
00899 goto gError;
00900 }
00901
00902 strcpy(pcNamell, pcc1);
00903 if (iDebug)
00904 printf(" file name %s\n", pcNamell);
00905
00906 pcc--;
00907 strncpy(pcc1, "\0", 1);
00908 if (strlen(pcc) > MAX_OBJ_HL-1)
00909 {
00910 ii = MAX_OBJ_HL-1;
00911 fprintf(fLogClient, "-E- %s: path name '%s' too long (max %d)\n",
00912 cModule, pcc, ii);
00913
00914 iError = -1;
00915 goto gError;
00916 }
00917
00918 if (strlen(pcc) < 2)
00919 {
00920 fprintf(fLogClient, "-E- %s: invalid path name '%s'\n", cModule, pcc);
00921
00922 iError = -1;
00923 goto gError;
00924 }
00925
00926 strcpy(pcNamehl, pcc);
00927 if (iDebug)
00928 printf(" path name %s\n", pcNamehl);
00929
00930 strcpy(pCommAPI->cNamefs, rawGetFSpName(pcNamefs));
00931 iRC = rawGetLLName(pcNamell, pcObjDelim, pCommAPI->cNamell);
00932 if (iRC)
00933 {
00934 fprintf(fLogClient, "-E- %s: invalid gStore file name: %s\n",
00935 cModule, pCommAPI->cNamell);
00936
00937 iError = -1;
00938 goto gError;
00939 }
00940
00941 strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
00942 if (strcmp(pcNamehl, pCommAPI->cNamehl))
00943 {
00944 strcpy(pcNamehl, pCommAPI->cNamehl);
00945 printf(" gStore path name corrected to %s\n", pcNamehl);
00946
00947 strcpy((char *) pcFile, cPrefix);
00948 strcat((char *) pcFile, pCommAPI->cNamefs);
00949 strcat((char *) pcFile, pCommAPI->cNamehl);
00950 strcat((char *) pcFile, pCommAPI->cNamell);
00951 if (iDebug) printf(
00952 " new full file name: %s\n", pcFile);
00953 }
00954 }
00955 else
00956 {
00957 if (iDebug)
00958 printf(" remote file %s\n", cTemp);
00959
00960 strcpy(pcNamefs, "");
00961
00962
00963 pcc1 = (char *) strrchr(cTemp, *pcObjDelim);
00964 if (pcc1 == NULL)
00965 {
00966 fprintf(fLogClient, "-E- %s: invalid remote file name '%s'\n",
00967 cModule, cTemp);
00968
00969 iError = -1;
00970 goto gError;
00971 }
00972
00973 if (strlen(pcc1) > MAX_OBJ_LL-1)
00974 {
00975 ii = MAX_OBJ_LL-1;
00976 fprintf(fLogClient, "-E- %s: file name '%s' too long (max %d)\n",
00977 cModule, pcc1, ii);
00978
00979 iError = -1;
00980 goto gError;
00981 }
00982
00983 if (strlen(pcc1) < 2)
00984 {
00985 fprintf(fLogClient, "-E- %s: invalid file name '%s'\n", cModule, pcc1);
00986
00987 iError = -1;
00988 goto gError;
00989 }
00990
00991 strcpy(pcNamell, pcc1);
00992 if (iDebug)
00993 printf(" file name %s\n", pcNamell);
00994
00995 strncpy(pcc1, "\0", 1);
00996 if (strlen(cTemp) > MAX_OBJ_HL-1)
00997 {
00998 ii = MAX_OBJ_HL-1;
00999 fprintf(fLogClient, "-E- %s: path name '%s' too long (max %d)\n",
01000 cModule, cTemp, ii);
01001
01002 iError = -1;
01003 goto gError;
01004 }
01005
01006 if (strlen(cTemp) < 2)
01007 {
01008 fprintf(fLogClient, "-E- %s: invalid path name '%s'\n",
01009 cModule, cTemp);
01010
01011 iError = -1;
01012 goto gError;
01013 }
01014
01015 strcpy(pcNamehl, cTemp);
01016 if (iDebug)
01017 printf(" path name %s\n", pcNamehl);
01018
01019 strcpy(pCommAPI->cNamefs, "\0");
01020 strcpy(pCommAPI->cNamehl, pcNamehl);
01021 strcpy(pCommAPI->cNamell, pcNamell);
01022
01023 }
01024 }
01025
01026
01027
01028 if (iCopyMode)
01029 {
01030 if (iAction != 2)
01031 {
01032 fprintf(fLogClient,
01033 "-E- copy from write cache only for write actions\n");
01034
01035 iError = -1;
01036 goto gError;
01037 }
01038
01039 if (iMassSto != 2)
01040 {
01041 fprintf(fLogClient,
01042 "-E- copy from write cache to lustre only when writing to DAQPool\n");
01043
01044 iError = -1;
01045 goto gError;
01046 }
01047
01048 if (iObjInit)
01049 {
01050 fprintf(fLogClient,
01051 "-E- copy from write cache only supported with rfio_[f]newfile\n");
01052
01053 iError = -1;
01054 goto gError;
01055 }
01056
01057 if ( (iCopyMode < 0) || (iCopyMode > 2) )
01058 {
01059 fprintf(fLogClient, "-E- invalid copy mode: %d\n", iCopyMode);
01060
01061 iError = -1;
01062 goto gError;
01063 }
01064
01065 if ( (strlen(pcCopyPath) == 0) || (pcCopyPath == NULL) )
01066 {
01067 fprintf(fLogClient, "-E- copy path missing\n");
01068
01069 iError = -1;
01070 goto gError;
01071 }
01072
01073 if (iCopyFraction < 0)
01074 {
01075 fprintf(fLogClient,
01076 "-E- invalid fraction of files to copied: %d (must be > 0)\n",
01077 iCopyFraction);
01078
01079 iError = -1;
01080 goto gError;
01081 }
01082
01083 if (iCopyFraction == 0)
01084 {
01085 fprintf(fLogClient,
01086 "-W- fraction of files to copied: 0 specified, assume 1 (copy all)\n");
01087
01088 iCopyFraction = 1;
01089 }
01090
01091 strcpy(cTemp, pcCopyPath);
01092 pcc = cTemp;
01093
01094
01095 while (*pcc != '\0')
01096 {
01097 *pcc = tolower(*pcc);
01098 pcc++;
01099 }
01100 if (strcmp(cTemp, "rc") == 0)
01101 {
01102 fprintf(fLogClient,
01103 "-E- copy to read cache not yet implemented\n");
01104
01105 iError = -1;
01106 goto gError;
01107 }
01108
01109 strcpy(cTemp, pcCopyPath);
01110
01111
01112 ii1 = 1;
01113 ii2 = 0;
01114 pcc = cTemp;
01115 while (ii1)
01116 {
01117 pcc1 = strrchr(cTemp, '/');
01118 ii = pcc1 - pcc + 1;
01119 if (ii == strlen(pcc))
01120 {
01121 ii2++;
01122 strncpy(pcc1, "\0", 1);
01123 }
01124 else
01125 ii1 = 0;
01126 }
01127
01128 if (ii2)
01129 {
01130 strcpy(pcCopyPath, cTemp);
01131 fprintf(fLogClient,
01132 " %d trailing '/' ignored, use copy destination '%s'\n",
01133 ii2, pcCopyPath);
01134 }
01135
01136
01137 if ( (strncmp(pcCopyPath, cDataFSHigh1, strlen(cDataFSHigh1))) &&
01138 (strncmp(pcCopyPath, cDataFSHigh2, strlen(cDataFSHigh2))) )
01139 {
01140 fprintf(fLogClient,
01141 "-E- invalid copy destination %s\n", pcCopyPath);
01142
01143 iError = -1;
01144 goto gError;
01145 }
01146
01147 if (iMaxFile < 0)
01148 {
01149 fprintf(fLogClient,
01150 "-E- invalid max file no. for copy destination: %d\n",
01151 iMaxFile);
01152
01153 iError = -1;
01154 goto gError;
01155 }
01156
01157 if ( (iPathConvention < 0) || (iPathConvention > 1) )
01158 {
01159 fprintf(fLogClient,
01160 "-E- invalid convention no. for creation of new copy destination path: %d\n",
01161 iPathConvention);
01162
01163 iError = -1;
01164 goto gError;
01165 }
01166
01167 if (iCopyMode == 1)
01168 {
01169 if (iCopyFraction == 1) fprintf(fLogClient,
01170 "-I- copy each file to %s", pcCopyPath);
01171 else fprintf(fLogClient,
01172 "-I- copy each %d. file to %s", iCopyFraction, pcCopyPath);
01173 if (iPathConvention == 1)
01174 fprintf(fLogClient, "*");
01175 fprintf(fLogClient, " before tape migration\n");
01176 fprintf(fLogClient, " check success as asynchroneous copy process\n");
01177 }
01178 else
01179 {
01180 if (iCopyFraction == 1) fprintf(fLogClient,
01181 "-I- write data buffers of each file to gStore write cache and to %s",
01182 pcCopyPath);
01183 else fprintf(fLogClient,
01184 "-I- for each %d. file write data buffers additionally to %s",
01185 iCopyFraction, pcCopyPath);
01186 if (iPathConvention == 1)
01187 fprintf(fLogClient, "*\n");
01188 else
01189 fprintf(fLogClient, "\n");
01190 }
01191 if ( (iMaxFile) && (strcmp("rc", pcCopyPath)) ) fprintf(fLogClient,
01192 " if %d files are written, create new directory (convention no. %d)\n",
01193 iMaxFile, iPathConvention);
01194
01195
01196 pCopyCacheServ->iIdent = htonl( (unsigned int) IDENT_COPY_CACHE);
01197 pCopyCacheServ->iCopyMode = htonl(iCopyMode);
01198 pCopyCacheServ->iCopyLen = htonl(0);
01199
01200 strcpy(pCopyCacheServ->cCopyPath, pcCopyPath);
01201 pCopyCacheServ->iCopyFraction = htonl(iCopyFraction);
01202 pCopyCacheServ->iMaxFile = htonl(iMaxFile);
01203 pCopyCacheServ->iPathConvention = htonl(iPathConvention);
01204
01205 if (iDebug) printf(
01206 " parameters for write cache copy stored\n");
01207
01208 }
01209
01210 if (iMassSto > 0)
01211 {
01212 iPortMaster = PORT_MASTER;
01213 if (iCopyMode)
01214 iPortMover = PORT_MOVER_DATAFS;
01215 else
01216 iPortMover = PORT_MOVER;
01217
01218 pcc = cNodePrefix + strlen(cNodePrefix) - 2;
01219 if (strcmp(pcc, "_d") == 0)
01220 {
01221 strncpy(pcc, "\0", 1);
01222 if (iDebug)
01223 printf(" switch to test system\n");
01224
01225 iPortMaster -= 10;
01226 iPortMover -= 10;
01227 }
01228
01229 if ( (strcmp(cNodePrefix, "gstore") == 0) ||
01230 (strcmp(cNodePrefix, "//lxgstore") == 0) ||
01231 (strcmp(cNodePrefix, "///lxgstore") == 0) ||
01232 (strcmp(cNodePrefix, "///gstore") == 0) ||
01233 (strcmp(cNodePrefix, "//gstore") == 0) )
01234 strcpy(cNodeMaster, cNodeMaster0);
01235 else
01236 strcpy(cNodeMaster, cNodePrefix);
01237
01238 if (iDebug) printf(
01239 " gStore entry server %s (node in URL %s)\n",
01240 cNodeMaster, cNodePrefix);
01241 fflush(stdout);
01242 }
01243 else
01244 strcpy(cNodeMaster, cNodePrefix);
01245
01246 strcpy(pCommAPI->cNodeCacheMgr, cNodeMaster);
01247
01248 pCommAPI->iSynchId = 0;
01249 pCommAPI->iExecStatus = 0;
01250 pCommAPI->iWaitTime = 0;
01251 strcpy(pCommAPI->cTapeLib, "0");
01252
01253 if ( iAction == 1)
01254 {
01255 if (iOnlyQuery)
01256 pCommAPI->iAction = QUERY;
01257 else
01258 pCommAPI->iAction = QUERY_RETRIEVE_RECORD;
01259 }
01260 else
01261 {
01262 if (iMassSto)
01263 pCommAPI->iAction = QUERY_ARCHIVE_RECORD;
01264 else
01265 pCommAPI->iAction = ARCHIVE_RECORD;
01266 }
01267
01268 if (iDebug)
01269 {
01270 if (iMassSto == 0)
01271 {
01272 if (iObjInit) printf(
01273 " %s node %s:%d, file %s%s",
01274 cServer, cNodeMaster, iPortMaster, pcNamehl, pcNamell);
01275 else printf(
01276 " %s node %s:%d", cServer, cNodeMaster, iPortMaster);
01277 }
01278 else
01279 {
01280 if (iObjInit) printf(
01281 " %s %s:%d, TSM object %s%s%s",
01282 cServer, cNodeMaster, iPortMaster,
01283 pcNamefs, pcNamehl, pcNamell);
01284 else printf(
01285 " %s %s:%d", cServer, cNodeMaster, iPortMaster);
01286 }
01287 if (iPoolId)
01288 {
01289 if (iPoolId == 2)
01290 printf(", request StagePool\n");
01291 else if (iPoolId == 3)
01292 printf(", request ArchivePool\n");
01293 else if (iPoolId == 4)
01294 printf(", request DaqPool\n");
01295 }
01296 else
01297 printf("\n");
01298
01299 if (iObjInit) printf(
01300 " FS name '%s', HL name '%s', LL name '%s', action %d\n",
01301 pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell,
01302 pCommAPI->iAction);
01303 else printf(
01304 " action %d, object follows later\n", pCommAPI->iAction);
01305
01306 }
01307
01308
01309
01310 strcpy(cOwner, rawGetUserid());
01311 iRC = gethostname(cliNode, MAX_NODE);
01312 if (iRC)
01313 {
01314 fprintf(fLogClient, "-E- %s: getting client host name: %s\n",
01315 cModule, strerror(iRC));
01316
01317 iError = -1;
01318 goto gError;
01319 }
01320
01321 if (iDebug) printf(
01322 " user %s on node %s, platform %s\n",
01323 cOwner, cliNode, cOS);
01324
01325 #ifndef Lynx
01326 iLogFile = 0;
01327 if ( (iMassSto) &&
01328 (fLogClient == stdout) &&
01329 (iLogFile) )
01330 {
01331 strcpy(cLogClient, "./RFIO");
01332 strcat(cLogClient, cOwner);
01333 tstr = time(NULL);
01334 sprintf(cstr, ".t%d", (int) tstr);
01335 strcat(cLogClient, cstr);
01336 pstr = getpid();
01337 sprintf(cstr, ".p%d", pstr);
01338 strcat(cLogClient, cstr);
01339 strcat(cLogClient, ".log");
01340
01341 ii1 = strlen(cLogClient);
01342 ii2 = MAX_LOG_FILE;
01343 if (ii1 >= ii2)
01344 printf("-E- %s: log file name %s too long (%d, max %d)\n",
01345 cModule, cLogClient, ii1, --ii2);
01346
01347 fLogClient = fopen(cLogClient, "w");
01348 if (fLogClient == NULL)
01349 {
01350 printf("-W- can not open log file %s, write to stdout\n",
01351 cLogClient);
01352 perror(" ");
01353 fLogClient = stdout;
01354 }
01355
01356 printf("-I- log file %s\n", cLogClient);
01357 fprintf(fLogClient, "*** log file: %s, client node: %s\n",
01358 cLogClient, cliNode);
01359
01360
01361 tcur = time(NULL);
01362 ptloc = localtime_t(&tcur, &buf_time);
01363 (ptloc->tm_mon)++;
01364 ptloc->tm_year += 1900;
01365
01366 fprintf(fLogClient,
01367 " current date %d/%.2d/%.2d, time %.2d:%.2d:%.2d\n",
01368 ptloc->tm_year,
01369 ptloc->tm_mon,
01370 ptloc->tm_mday,
01371 ptloc->tm_hour,
01372 ptloc->tm_min,
01373 ptloc->tm_sec);
01374 fflush(fLogClient);
01375
01376 }
01377 #endif
01378
01379 strcpy(pCommAPI->cApplType, cApplType);
01380 strcpy(pCommAPI->cOwner, cOwner);
01381 strcpy(pCommAPI->cliNode, cliNode);
01382 strcpy(pCommAPI->cOS, cOS);
01383 strcpy(pCommAPI->cDataFS, "");
01384 pCommAPI->iDataFS = 0;
01385
01386 if (iAction == 2)
01387 {
01388 pCommAPI->iPoolIdWC = iPoolId;
01389 pCommAPI->iPoolIdRC = 0;
01390 strcpy(pCommAPI->cNodeRC, "");
01391 pCommAPI->iStageFSid = 0;
01392
01393 if (iPoolId == 4)
01394 pCommAPI->iArchDev = ARCH_DAQ_DISK;
01395 else
01396 pCommAPI->iArchDev = ARCH_DISK;
01397 }
01398 else
01399 {
01400 pCommAPI->iPoolIdRC = iPoolId;
01401 pCommAPI->iPoolIdWC = 0;
01402 pCommAPI->iArchDev = RETR_STAGE_TEMP;
01403 }
01404
01405 if (iDebug)
01406 {
01407 if (iAction == 2)
01408 printf(" request WC poolId %d, device %d\n",
01409 pCommAPI->iPoolIdWC, pCommAPI->iArchDev);
01410 else if (iOnlyQuery == 0)
01411 printf(" request RC poolId %d, device %d\n",
01412 pCommAPI->iPoolIdRC, pCommAPI->iArchDev);
01413 }
01414
01415 pCommServ->iIdent = htonl(pCommAPI->iIdent);
01416 pCommServ->iAction = htonl(pCommAPI->iAction);
01417 pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
01418 pCommServ->iBufsizeFile = htonl(0);
01419 pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
01420 pCommServ->iExecStatus = htonl(pCommAPI->iExecStatus);
01421 pCommServ->iWaitTime = htonl(pCommAPI->iWaitTime);
01422 strcpy(pCommServ->cNamefs, pCommAPI->cNamefs);
01423 strcpy(pCommServ->cNamehl, pCommAPI->cNamehl);
01424 strcpy(pCommServ->cNamell, pCommAPI->cNamell);
01425 strcpy(pCommServ->cOwner, pCommAPI->cOwner);
01426 strcpy(pCommServ->cOS, pCommAPI->cOS);
01427 strcpy(pCommServ->cApplType, pCommAPI->cApplType);
01428 strcpy(pCommServ->cliNode, pCommAPI->cliNode);
01429 strcpy(pCommServ->cTapeLib, pCommAPI->cTapeLib);
01430 strcpy(pCommServ->cDataFS, pCommAPI->cDataFS);
01431 strcpy(pCommServ->cNodeCacheMgr, pCommAPI->cNodeCacheMgr);
01432 pCommServ->iDataFS = htonl(pCommAPI->iDataFS);
01433 pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
01434 pCommServ->iPoolIdWC = htonl(pCommAPI->iPoolIdWC);
01435 pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
01436 pCommServ->iStageFSid = htonl(pCommAPI->iStageFSid);
01437 pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
01438 pCommServ->iClient32 = htonl(pCommAPI->iClient32);
01439
01440
01441
01442 if (iDebug) printf(
01443 " connecting to %s %s:%d\n",
01444 cServer, cNodeMaster, iPortMaster);
01445
01446 iRC = rconnect(cNodeMaster, iPortMaster, &iMaxConnect, &iSockMaster);
01447 if (iRC)
01448 {
01449 fprintf(fLogClient, "-E- %s: cannot connect to %s %s:%d\n",
01450 cModule, cServer, cNodeMaster, iPortMaster);
01451 iSendEOS = 0;
01452 iError = -1;
01453 goto gClose;
01454 }
01455
01456 strcpy(pcurAPIFile->cNodeMaster, cNodeMaster);
01457 pcurAPIFile->iSockMaster = iSockMaster;
01458
01459 if (iDebug)
01460 {
01461 printf("-I- successfully connected to %s %s:%d",
01462 cServer, cNodeMaster, iPortMaster);
01463 if (iMaxConnect)
01464 printf(" after %ds", iMaxConnect);
01465 printf(" (socket %d)\n", iSockMaster);
01466 }
01467
01468 if (iMassSto == 0)
01469 {
01470 pCommServ->iFileType = htonl(STREAM);
01471 pCommServ->iBufsizeFile = htonl(0);
01472 pCommServ->iFileSize = htonl(0);
01473 pCommServ->iFileSize2 = htonl(0);
01474 pCommServ->iStageFSid = htonl(0);
01475
01476
01477 pCommAPI->iFileType = ntohl(pCommServ->iFileType);
01478 pCommAPI->iBufsizeFile = ntohl(pCommServ->iBufsizeFile);
01479 pCommAPI->iFileSize = ntohl(pCommServ->iFileSize);
01480 pCommAPI->iFileSize2 = ntohl(pCommServ->iFileSize2);
01481 pCommAPI->iStageFSid = ntohl(pCommServ->iStageFSid);
01482
01483
01484 strcpy(cNodeMover, cNodeMaster);
01485 strcpy(pcurAPIFile->cNodeMover, cNodeMaster);
01486 iSockMover = iSockMaster;
01487 pcurAPIFile->iSockMover = iSockMaster;
01488
01489 iSockMaster = -1;
01490 pcurAPIFile->iSockMaster = -1;
01491
01492 }
01493 else
01494 {
01495 if (iAction == 2)
01496 iATLServer = ATLSERVER_ARCHIVE;
01497 else
01498 iATLServer = 0;
01499
01500 pCommAPI->iATLServer = iATLServer;
01501 pCommServ->iATLServer = htonl(iATLServer);
01502
01503 if (iObjInit)
01504 {
01505
01506
01507 pCommAPI->iSynchId = 0;
01508 pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
01509
01510 pBufQuery = &sQuery;
01511 pQAttr = &(sQuery.objAttr);
01512
01513 if (iDebug)
01514 {
01515 printf(" query file %s in gStore\n", pcFile);
01516 ii = 1;
01517 }
01518 else
01519 ii = 0;
01520
01521 iRC = rawQueryFile(iSockMaster, ii, pCommServ, &pBufQuery);
01522
01523 if (iAction != 2)
01524 {
01525 iATLServer = ntohl(pQAttr->iATLServer);
01526 pCommAPI->iATLServer = iATLServer;
01527 pCommServ->iATLServer = htonl(iATLServer);
01528 }
01529
01530 if (iRC < 0)
01531 {
01532 if (iRC == -1001)
01533 {
01534 if (iATLServer == 0) sprintf(rfio_errmsg,
01535 "-E- no %s access to archive %s in all ATL servers\n",
01536 cAccess, pCommAPI->cNamefs);
01537 else sprintf(rfio_errmsg,
01538 "-E- no %s access to archive %s in ATL server %d\n",
01539 cAccess, pCommAPI->cNamefs, iATLServer);
01540 }
01541 else if (iRC == -1000) sprintf(rfio_errmsg,
01542 "-E- no archive %s in ATL server %d found\n",
01543 pCommAPI->cNamefs, iATLServer);
01544 else sprintf(rfio_errmsg,
01545 "-E- file %s: query in ATL server %d failed, rc = %d\n",
01546 pcFile, iATLServer, iRC);
01547 fprintf(fLogClient, "%s", rfio_errmsg);
01548
01549 iSendEOS = 1;
01550 iError = -1;
01551 goto gClose;
01552 }
01553
01554 if (iRC == 0)
01555 {
01556 if (iAction == 1)
01557 {
01558 if (iOnlyQuery)
01559 sprintf(rfio_errmsg,
01560 " file %s not available in gStore\n", pcFile);
01561 else
01562 sprintf(rfio_errmsg,
01563 "-E- %s: file %s not available in gStore\n",
01564 cModule, pcFile);
01565 fprintf(fLogClient, "%s", rfio_errmsg);
01566
01567 iError = 1;
01568 iSendEOS = 1;
01569 goto gClose;
01570 }
01571
01572 if (iDebug) printf(
01573 " file %s not yet available in gStore\n", pcFile);
01574 }
01575 else
01576 {
01577 if ( (iAction == 1) &&
01578 (iOnlyQuery == 0) )
01579 {
01580 if ( (pQAttr->iFileSize2) && (iOS64 == 0) )
01581 {
01582 sprintf(rfio_errmsg,
01583 "-E- filesize of %s >= 4 GB, cannot be read with 32 bit client\n",
01584 pcFile);
01585 fprintf(fLogClient, "%s", rfio_errmsg);
01586
01587 iSendEOS = 1;
01588 iError = 1;
01589 goto gClose;
01590 }
01591 }
01592 else if (iAction == 2)
01593 {
01594 sprintf(rfio_errmsg,
01595 "-E- file %s already available in gStore\n", pcFile);
01596 fprintf(fLogClient, "%s", rfio_errmsg);
01597
01598 iSendEOS = 1;
01599 iError = 1;
01600 goto gClose;
01601 }
01602
01603 memcpy(pQueryAPI, pQAttr, (unsigned) iObjAttr);
01604
01605 if (iDebug)
01606 {
01607 printf(" file %s available in gStore (ATL server %d)\n",
01608 pcFile, iATLServer);
01609
01610 if (iRC > 1) printf(
01611 "-W- %d versions of file %s exist\n", iRC, pcFile);
01612 ii = 1;
01613 }
01614 else
01615 ii = 0;
01616
01617 rawQueryString(pQueryAPI, ii, sizeof(cMsg), cMsg);
01618 if ( (iDebug) || (iOnlyQuery) )
01619 printf(" %s", cMsg);
01620
01621 iStage = ntohl(pQAttr->iFS);
01622 iCache = 0;
01623 pCommAPI->iStageFSid = 0;
01624 pCommAPI->iFSidWC = 0;
01625 if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_STAGE) ||
01626 (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE) ||
01627 (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED) )
01628 {
01629 strcpy(cNodeMover, pQAttr->cNode);
01630 pCommAPI->iStageFSid = iStage;
01631 pCommAPI->iPoolIdRC = ntohl(pQAttr->iPoolId);
01632
01633 if (iDebug)
01634 {
01635 printf(" file %s staged in FS %d of DM %s (poolId %d)",
01636 pcFile, iStage, cNodeMover, pCommAPI->iPoolIdRC);
01637 if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE)
01638 printf(", still incomplete)\n");
01639 else if (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED)
01640 printf(", already locked)\n");
01641 else printf("\n");
01642 }
01643 }
01644 else if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_CACHE) ||
01645 (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE) ||
01646 (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED) )
01647 {
01648 iCache = 1;
01649
01650
01651 strcpy(sFileSystemServ.cOS, "Windows");
01652 strcpy(sFileSystemServ.cNode, pQAttr->cNode);
01653 sFileSystemServ.iFileSystem = pQAttr->iFS;
01654
01655 sFileSystemServ.iFileSystem = pQAttr->iFS;
01656
01657 strcpy(sFileSystemServ.cArchiveDate, pQAttr->cDateCreate);
01658
01659 strcpy(sFileSystemServ.cArchiveUser, pQAttr->cOwner);
01660
01661
01662 strcpy(cNodeMover, pQAttr->cNode);
01663 strcpy(pCommAPI->cNodeWC, cNodeMover);
01664 pCommAPI->iFSidWC = iStage;
01665 pCommAPI->iPoolIdWC = ntohl(pQAttr->iPoolId);
01666
01667 if (iDebug)
01668 {
01669 printf(" file %s cached in FS %d of DM %s (poolId %d)",
01670 pcFile, iStage, cNodeMover, pCommAPI->iPoolIdWC);
01671 if (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE)
01672 printf(", still incomplete)\n");
01673 else if (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED)
01674 printf(", already locked)\n");
01675 else printf("\n");
01676 }
01677 }
01678 else
01679 {
01680 iStage = 0;
01681 if (iDebug)
01682 printf(" file %s not yet staged\n", pcFile);
01683 }
01684 }
01685 }
01686 else
01687 {
01688
01689
01690
01691 pCommServ->iAction = htonl(SPM_REQUEST_MOVER);
01692
01693 if (iDebug) printf(
01694 " send command buffer to %s: id: %d, action %d (ATL server %d), len %d\n",
01695 cServer, ntohl(pCommServ->iIdent),
01696 ntohl(pCommServ->iAction),
01697 ntohl(pCommServ->iATLServer),
01698 ntohl(pCommServ->iCommLen));
01699
01700 if (iAction == 2)
01701 {
01702 pCommAPI->iSynchId = 1;
01703 pCommServ->iSynchId = htonl(pCommAPI->iSynchId);
01704
01705 if (iDebug) printf(
01706 " keep entry server session for next query\n");
01707 }
01708
01709 pcc = (char *) pCommServ;
01710 iRC = send(iSockMaster, pcc, (unsigned) irawComm, 0);
01711 if (iRC < 0)
01712 {
01713 fprintf(fLogClient,
01714 "-E- %s: sending command buffer (action %d) to %s\n",
01715 cModule, ntohl(pCommServ->iAction), cServer);
01716 perror(" ");
01717
01718 iSendEOS = 1;
01719 iError = 1;
01720 goto gClose;
01721 }
01722
01723 if (irawComm != iRC)
01724 {
01725 fprintf(fLogClient,
01726 "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
01727 cModule, cServer, iRC, irawComm);
01728
01729 iSendEOS = 1;
01730 iError = 1;
01731 goto gClose;
01732 }
01733
01734 if (iDebug) printf(
01735 " command buffer (action %d) sent to %s (%d byte)\n",
01736 ntohl(pCommServ->iAction), cServer, irawComm);
01737
01738 }
01739
01740
01741
01742 if (iOnlyQuery)
01743 ;
01744 else
01745 if ( ( (iAction == 1) && ((iStage == 0) || (iCache == 1)) ) ||
01746 (iAction == 2) )
01747 {
01748 if (iDebug) printf(
01749 " receiving attributes of data mover selected by master\n");
01750
01751 iDataMoverSelect = 0;
01752
01753 while (iDataMoverSelect == 0)
01754 {
01755 pcc = (char *) &sDataMoverSelect;
01756 strcpy(cMsg, "");
01757
01758 iRC = rawRecvHeadC(iSockMaster, pcc, 0, -1, cMsg);
01759
01760 iIdent = ntohl(sDataMoverSelect.iIdent);
01761 iStatus = ntohl(sDataMoverSelect.iStatus);
01762 iStatusLen = ntohl(sDataMoverSelect.iStatusLen);
01763
01764 if (iDebug) printf(
01765 " ident %d, status %d, len %d\n",
01766 iIdent, iStatus, iStatusLen);
01767
01768 if (iStatus != STA_SWITCH_SERVER)
01769 {
01770 if (iRC < 0) fprintf(fLogClient,
01771 "-E- %s: receiving data mover attr header\n%s",
01772 cModule, cMsg);
01773
01774 if ( (iStatus == STA_CACHE_FULL) && (iAction == 2) )
01775 {
01776 iStatusLoop++;
01777 if ( (iStatusLoop < iStatusLoopMax) &&
01778 (iMassSto != 2) )
01779 fprintf(fLogClient,
01780 "-W- %s: write cache currently full (select) ... sleep %d s (%d of %d)\n",
01781 cModule, iSleepCacheFull, iStatusLoop,
01782 iStatusLoopMax);
01783 else
01784 {
01785 fprintf(fLogClient,
01786 "-W- %s: write cache currently full, archive to tape\n",
01787 cModule);
01788
01789 if (iDebug) printf(
01790 " received DM name: %s\n", cMsg);
01791 iDataMoverSelect = 1;
01792 strcpy(cNodeMover, cMsg);
01793 strcpy(pDataMoverSelect->cNode, cMsg);
01794 pDataMoverSelect->iATLServer = htonl(0);
01795 pDataMoverSelect->iExecStatus = htonl(0);
01796 pDataMoverSelect->iWaitTime = htonl(0);
01797
01798 pCommAPI->iArchDev = ARCH_TAPE;
01799 pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
01800
01801 goto gReceivedDM;
01802 }
01803
01804
01805
01806
01807 pCommServ->iAction = htonl(SPM_REQUEST_MOVER);
01808
01809 if (iDebug) printf(
01810 " send command buffer to %s: id: %d, action %d, len %d\n",
01811 cServer, pCommAPI->iIdent,
01812 ntohl(pCommServ->iAction),
01813 ntohl(pCommServ->iCommLen));
01814
01815 pcc = (char *) pCommServ;
01816 iRC = send(iSockMaster, pcc, (unsigned) irawComm, 0);
01817 if (iRC != irawComm)
01818 {
01819 if (iRC < 0)
01820 {
01821 fprintf(fLogClient,
01822 "-E- %s: sending command buffer (action %d) to %s\n",
01823 cModule, ntohl(pCommServ->iAction), cServer);
01824 perror(" ");
01825 }
01826 else fprintf(fLogClient,
01827 "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
01828 cModule, cServer, iRC, irawComm);
01829
01830 iSendEOS = 1;
01831 iError = 1;
01832 goto gClose;
01833 }
01834
01835 if (iDebug) printf(
01836 " command buffer (action %d) sent to %s (%d byte)\n",
01837 ntohl(pCommServ->iAction), cServer, irawComm);
01838
01839 continue;
01840
01841 }
01842
01843 fprintf(fLogClient, "-E- %s: received error status from %s",
01844 cModule, cServer);
01845 if (iRC)
01846 printf("\n%s" , cMsg);
01847 else
01848 printf("\n");
01849
01850 iSendEOS = 1;
01851 iError = 1;
01852 goto gClose;
01853
01854 }
01855
01856 if (iDebug) printf(
01857 " header of data mover attr received (%d bytes)\n",
01858 iRC);
01859
01860
01861 pcc = (char *) &(sDataMoverSelect.sDataMoverAttr);
01862 iBufl = sizeof(srawDataMover) - HEAD_LEN;
01863 iBuf = iBufl;
01864 while(iBuf > 0)
01865 {
01866 if ( (iRC = recv( iSockMaster, pcc, (unsigned) iBuf, 0 )) < 0 )
01867 {
01868 fprintf(fLogClient,
01869 "-E- %s: receiving data part of data mover info\n",
01870 cModule);
01871 perror("-E- receiving data part of data mover info");
01872
01873 iSendEOS = 1;
01874 iError = 1;
01875 goto gClose;
01876 }
01877
01878 if (iRC == 0)
01879 {
01880 ii = iBufl - iBuf;
01881 fprintf(fLogClient,
01882 "-E- %s: connection to sender broken, %d byte of data part of data mover info (%d byte) received\n",
01883 cModule, ii, iBufl);
01884
01885 iError = 1;
01886 goto gClose;
01887 }
01888
01889 iBuf -= iRC;
01890 pcc += iRC;
01891 }
01892
01893 pDataMoverSelect = &(sDataMoverSelect.sDataMoverAttr);
01894 iDataMoverSelect = iBufl / sizeof(srawDataMoverAttr);
01895
01896 strcpy(cNodeMover, pDataMoverSelect->cNode);
01897
01898 if (iATLServer != (int) ntohl(pDataMoverSelect->iATLServer))
01899 {
01900 if ( (iATLServer <= 0) || (iATLServer > MAX_ATLSERVER) )
01901 fprintf(fLogClient,
01902 "-E- %s: invalid ATL server no. %d received\n",
01903 cModule, iATLServer);
01904 else fprintf(fLogClient,
01905 "-W- %s: unexpected ATL server of selected DM: %d, expected %d\n",
01906 cModule,
01907 ntohl(pDataMoverSelect->iATLServer), iATLServer);
01908
01909 iATLServer = ntohl(pDataMoverSelect->iATLServer);
01910 pCommAPI->iATLServer = iATLServer;
01911 pCommServ->iATLServer = htonl(iATLServer);
01912 }
01913
01914 if (iDebug)
01915 {
01916 printf(" data part of data mover info received (%d byte)\n",
01917 iBufl);
01918 printf(" %d data mover selected: %s for ATL server %d\n",
01919 iDataMoverSelect, cNodeMover, iATLServer);
01920 }
01921 else if (iAction == 1) printf(
01922 "-I- staging file to data mover %s (ATL server %d) ...\n",
01923 cNodeMover, iATLServer);
01924
01925 }
01926
01927 if (iDataMoverSelect != 1)
01928 {
01929 fprintf(fLogClient,
01930 "-W- expected 1 selected data mover, ignore remaining %d\n",
01931 --iDataMoverSelect);
01932 iDataMoverSelect = 1;
01933 }
01934 }
01935
01936
01937 gReceivedDM:
01938
01939 pCommServ->iATLServer = htonl(iATLServer);
01940
01941 if (iAction == 1)
01942 {
01943 pCommServ->iFileType = pQAttr->iFileType;
01944 pCommServ->iBufsizeFile = pQAttr->iBufsizeFile;
01945 pCommServ->iFileSize = pQAttr->iFileSize;
01946 pCommServ->iFileSize2 = pQAttr->iFileSize2;
01947 pCommServ->iObjHigh = pQAttr->iObjHigh;
01948 pCommServ->iObjLow = pQAttr->iObjLow;
01949
01950 pCommServ->iStageFSid = htonl(0);
01951 pCommServ->iFSidWC = htonl(0);
01952 if (iDebug) printf(" iMediaClass %d, disk FS %d\n",
01953 ntohl(pQAttr->iMediaClass), iStage);
01954 if (iStage)
01955 {
01956 if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_STAGE) ||
01957 (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_LOCKED) ||
01958 (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_INCOMPLETE) )
01959 pCommServ->iStageFSid = pQAttr->iFS;
01960 else if ( (ntohl(pQAttr->iMediaClass) == GSI_MEDIA_CACHE) ||
01961 (ntohl(pQAttr->iMediaClass) == GSI_CACHE_LOCKED) ||
01962 (ntohl(pQAttr->iMediaClass) == GSI_CACHE_INCOMPLETE) )
01963 pCommServ->iFSidWC = pQAttr->iFS;
01964 }
01965 }
01966 else
01967 {
01968 pCommServ->iFileType = htonl(STREAM);
01969 pCommServ->iBufsizeFile = htonl(0);
01970 pCommServ->iFileSize = htonl(0);
01971 pCommServ->iFileSize2 = htonl(0);
01972 pCommServ->iObjHigh = htonl(0);
01973 pCommServ->iObjLow = htonl(0);
01974 pCommServ->iStageFSid = htonl(0);
01975 pCommServ->iFSidWC = htonl(0);
01976 }
01977
01978
01979 pCommAPI->iATLServer = iATLServer;
01980 pCommAPI->iFileType = ntohl(pCommServ->iFileType);
01981 pCommAPI->iBufsizeFile = ntohl(pCommServ->iBufsizeFile);
01982 pCommAPI->iFileSize = ntohl(pCommServ->iFileSize);
01983 pCommAPI->iFileSize2 = ntohl(pCommServ->iFileSize2);
01984 pCommAPI->iObjHigh = ntohl(pCommServ->iObjHigh);
01985 pCommAPI->iObjLow = ntohl(pCommServ->iObjLow);
01986 pCommAPI->iStageFSid = ntohl(pCommServ->iStageFSid);
01987 pCommAPI->iFSidWC = ntohl(pCommServ->iFSidWC);
01988
01989 if (iStage)
01990 {
01991 pCommServ->iExecStatus = htonl(0);
01992 pCommAPI->iExecStatus = 0;
01993 }
01994 else
01995 {
01996 pCommServ->iExecStatus = pDataMoverSelect->iExecStatus;
01997 pCommAPI->iExecStatus = ntohl(pDataMoverSelect->iExecStatus);
01998
01999 pCommServ->iWaitTime = pDataMoverSelect->iWaitTime;
02000 pCommAPI->iWaitTime = ntohl(pDataMoverSelect->iWaitTime);
02001 }
02002
02003
02004
02005 if (iOnlyQuery == 0)
02006 {
02007 if (iDebug) printf(
02008 " connecting to data mover %s:%d\n",
02009 cNodeMover, iPortMover);
02010
02011 iRC = rconnect(cNodeMover, iPortMover,
02012 &iMaxConnect, &iSockMover);
02013 if (iRC)
02014 {
02015 fprintf(fLogClient,
02016 "-E- %s: cannot connect to data mover %s:%d (ATL server %d)\n",
02017 cModule, cNodeMover, iPortMover, iATLServer);
02018 iSendEOS = 1;
02019 iError = 1;
02020 goto gClose;
02021 }
02022
02023 fprintf(fLogClient,
02024 "-I- successfully connected to data mover %s:%d (ATL server %d)",
02025 cNodeMover, iPortMover, iATLServer);
02026 if (iDebug)
02027 {
02028 if (iMaxConnect)
02029 fprintf(fLogClient, " after %ds", iMaxConnect);
02030 fprintf(fLogClient, " (socket %d)\n", iSockMover);
02031 }
02032 else
02033 fprintf(fLogClient, "\n");
02034
02035 strcpy(pcurAPIFile->cNodeMover, cNodeMover);
02036 pcurAPIFile->iSockMover = iSockMover;
02037 strcpy(cServer, "data mover");
02038 }
02039
02040
02041
02042 if (iOnlyQuery)
02043 {
02044 iSendEOS = 1;
02045 goto gClose;
02046 }
02047
02048
02049
02050 if ( (iSockMaster >= 0) && (iAction == 1) )
02051 {
02052 if (iDebug)
02053 printf("-D- close connection %d to master\n", iSockMaster);
02054 iRC = shutdown(iSockMaster, 2);
02055 if (iDebug)
02056 printf(" rc shutdown = %d\n", iRC);
02057 iRC = close(iSockMaster);
02058 if (iDebug)
02059 printf(" rc close = %d\n", iRC);
02060
02061 iSockMaster = -1;
02062 pcurAPIFile->iSockMaster = -1;
02063
02064 }
02065
02066 }
02067
02068 if (iAction == 1)
02069 {
02070 pCommAPI->iAction = RETRIEVE_RECORD;
02071 strcpy(pCommAPI->cNodeRC, cNodeMover);
02072
02073 if (iCache == 1)
02074 {
02075
02076 pCommAPI->iCommLen += irawFileSystem;
02077 pCommAPI->iFSidWC = iStage;
02078
02079 }
02080 }
02081 else
02082 {
02083
02084 pCommAPI->iAction = ARCHIVE_RECORD;
02085 }
02086
02087 pCommServ->iAction = htonl(pCommAPI->iAction);
02088 pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
02089
02090 pCommServ->iPoolIdWC = htonl(pCommAPI->iPoolIdWC);
02091 strcpy(pCommServ->cNodeWC, pCommAPI->cNodeWC);
02092 pCommServ->iFSidWC = htonl(pCommAPI->iFSidWC);
02093
02094 pCommServ->iPoolIdRC = htonl(pCommAPI->iPoolIdRC);
02095 strcpy(pCommServ->cNodeRC, pCommAPI->cNodeRC);
02096 pCommServ->iStageFSid = htonl(pCommAPI->iStageFSid);
02097
02098 if (iObjInit)
02099 {
02100 gNextCmdOpen:
02101 if (iDebug)
02102 {
02103 printf(
02104 " send command buffer to %s: id: %d, action %d, data len %d\n",
02105 cServer, pCommAPI->iIdent,
02106 ntohl(pCommServ->iAction),
02107 ntohl(pCommServ->iCommLen));
02108 if (iMassSto)
02109 {
02110 pCommServ->iFileSize = ntohl(pCommServ->iFileSize);
02111 pCommServ->iFileSize2 = ntohl(pCommServ->iFileSize2);
02112 plFileSizeC = (unsigned long *) &(pCommServ->iFileSize);
02113
02114 printf(" filesize %lu bytes, record size %d",
02115 *plFileSizeC, ntohl(pCommServ->iBufsizeFile));
02116 if (iAction == 1) printf(
02117 ", poolIdRC %d, poolIdWC %d, obj id %d-%d\n",
02118 ntohl(pCommServ->iPoolIdRC), ntohl(pCommServ->iPoolIdWC),
02119 ntohl(pCommServ->iObjHigh), ntohl(pCommServ->iObjLow));
02120 else
02121 printf(", poolId %d\n", ntohl(pCommServ->iPoolIdWC));
02122
02123
02124 pCommServ->iFileSize = htonl(pCommServ->iFileSize);
02125 pCommServ->iFileSize2 = htonl(pCommServ->iFileSize2);
02126 }
02127 }
02128
02129 pcc = (char *) pCommServ;
02130 if ( (iRC = send(iSockMover, pcc, (unsigned) irawComm, 0 )) < 0 )
02131 {
02132 fprintf(fLogClient, "-E- %s: sending command buffer to %s (rc = %d)\n",
02133 cModule, cServer, iRC);
02134 perror(" ");
02135
02136 iSendEOS = 1;
02137 iError = 1;
02138 goto gClose;
02139 }
02140
02141 if (irawComm != iRC)
02142 {
02143 fprintf(fLogClient,
02144 "-E- %s: incomplete command buffer sent to %s (%d of %d bytes)\n",
02145 cModule, cServer, iRC, irawComm);
02146
02147 iSendEOS = 1;
02148 iError = 1;
02149 goto gClose;
02150 }
02151
02152 if (iDebug) printf(
02153 " command buffer sent to %s (%d byte)\n", cServer, irawComm);
02154
02155
02156 if (iCache == 1)
02157 {
02158 pcc = (char *) &sFileSystemServ;
02159 iRC = send(iSockMover, pcc, (unsigned) irawFileSystem, 0);
02160 if (irawFileSystem != iRC)
02161 {
02162 if (iRC < 0)
02163 {
02164 fprintf(fLogClient,
02165 "-E- %s: sending filesystem buffer to data mover %s failed\n",
02166 cModule, cNodeMover);
02167 perror(" ");
02168 }
02169 else fprintf(fLogClient,
02170 "-E- %s: incomplete filesystem buffer sent to data mover %s\n",
02171 cModule, cNodeMover);
02172
02173 iSendEOS = 1;
02174 iError = 1;
02175 goto gClose;
02176 }
02177
02178 if (iDebug) printf(
02179 " write cache info (%d bytes) sent to data mover %s\n",
02180 irawFileSystem, cNodeMover);
02181
02182 }
02183
02184
02185
02186 pcc = (char *) &sStatus;
02187 iStatusOkay = 0;
02188 iStatusLoop = 0;
02189 while (iStatusOkay == 0)
02190 {
02191 iStatusLoop++;
02192
02193 memset(&sStatus, 0X00, sizeof(srawStatus));
02194 iRC = rawRecvStatus(iSockMover, pcc);
02195 iStatus = sStatus.iStatus;
02196 if (iRC != HEAD_LEN)
02197 {
02198 if (iRC < HEAD_LEN)
02199 {
02200 fprintf(fLogClient, "-E- %s: receiving status buffer from %s",
02201 cModule, cServer);
02202 if (iRC > 0)
02203 fprintf(fLogClient, ": (%d byte)\n", iRC);
02204 else
02205 fprintf(fLogClient, "\n");
02206 }
02207 else
02208 {
02209 if ( (iStatus == STA_CACHE_FULL) && (iAction == 2) )
02210 {
02211 if ( (iStatusLoop < iStatusLoopMax) &&
02212 (iMassSto != 2) )
02213 {
02214 fprintf(fLogClient,
02215 "-W- %s: write cache currently full (create) ... sleep %d s (%d of %d)\n",
02216 cModule, iSleepCacheFull,
02217 iStatusLoop, iStatusLoopMax);
02218 continue;
02219 }
02220 else
02221 {
02222 fprintf(fLogClient,
02223 "-W- %s: write cache currently full: archive to tape\n",
02224 cModule);
02225 pCommAPI->iAction = ARCHIVE_RECORD;
02226 pCommAPI->iArchDev = ARCH_TAPE;
02227 pCommServ->iAction = htonl(pCommAPI->iAction);
02228 pCommServ->iArchDev = htonl(pCommAPI->iArchDev);
02229
02230 goto gNextCmdOpen;
02231 }
02232 }
02233 else if ( (iStatus == STA_SWITCH_SERVER) &&
02234 (iAction == 2) )
02235 {
02236 strcpy(cNodeMover, sStatus.cStatus);
02237
02238 fprintf(fLogClient,
02239 "-W- write cache on DM %s full, switch to %s\n",
02240 pcurAPIFile->cNodeMover, cNodeMover);
02241
02242 if (iDebug) printf(
02243 " close connection %d to data mover %s\n",
02244 iSockMover, pcurAPIFile->cNodeMover);
02245 iRC = shutdown(iSockMover, 2);
02246 if (iDebug)
02247 printf(" rc shutdown = %d\n", iRC);
02248 iRC = close(iSockMover);
02249 if (iDebug)
02250 printf(" rc close = %d\n", iRC);
02251
02252
02253
02254 if (iDebug) printf(
02255 " connecting to data mover %s:%d\n",
02256 cNodeMover, iPortMover);
02257
02258 iRC = rconnect(cNodeMover, iPortMover,
02259 &iMaxConnect, &iSockMover);
02260 if (iRC)
02261 {
02262 fprintf(fLogClient,
02263 "-E- %s: cannot connect to new data mover %s:%d (ATL server %d)\n",
02264 cModule, cNodeMover, iPortMover, iATLServer);
02265 iError = -2;
02266 }
02267
02268 fprintf(fLogClient,
02269 "-I- successfully connected to new data mover %s:%d (ATL server %d)",
02270 cNodeMover, iPortMover, iATLServer);
02271 if (iMaxConnect)
02272 fprintf(fLogClient, " after %ds", iMaxConnect);
02273 if (iDebug)
02274 printf(" (socket %d)\n", iSockMover);
02275 else
02276 fprintf(fLogClient, "\n");
02277
02278 strcpy(pcurAPIFile->cNodeMover, cNodeMover);
02279 pcurAPIFile->iSockMover = iSockMover;
02280
02281 goto gNextCmdOpen;
02282
02283 }
02284 else
02285 {
02286 fprintf(fLogClient, "-E- %s: message received from %s:\n",
02287 cModule, cServer);
02288 fprintf(fLogClient, " %s\n", sStatus.cStatus);
02289 iError = 2;
02290 }
02291 }
02292
02293 iSendEOS = 1;
02294 goto gClose;
02295 }
02296
02297 iStatusOkay = 1;
02298
02299 }
02300
02301 if (iDebug)
02302 {
02303 printf(" status (%d) received from %s (%d bytes",
02304 iStatus, cServer, iRC);
02305 if (iStatusLoop > 1)
02306 printf(", iter %d)\n", iStatusLoop);
02307 else
02308 printf(")\n");
02309 }
02310 }
02311
02312 iError = 0;
02313
02314 gClose:
02315 if ( (iSockMaster >= 0) &&
02316 ((iAction == 1) || (iError)) )
02317 {
02318
02319 if (iSendEOS)
02320 {
02321 iStatus = STA_END_OF_SESSION;
02322 iRC = rawSendStatus(iSockMaster, iStatus, NULL);
02323 if (iRC <= 0) fprintf(fLogClient,
02324 "-E- %s: sending status buffer to entry server (EOS)\n", cModule);
02325 else if (iDebug) printf(
02326 " status buffer (EOS) sent to entry server (%d bytes)\n", iRC);
02327 }
02328
02329 if (iDebug)
02330 printf(" close connection %d to entry server\n", iSockMaster);
02331 iRC = shutdown(iSockMaster, 2);
02332 if (iDebug)
02333 printf(" irc shutdown = %d\n", iRC);
02334 iRC = close(iSockMaster);
02335 if (iDebug)
02336 printf(" irc close = %d\n", iRC);
02337
02338 }
02339
02340 if (iError)
02341 {
02342 gError:
02343 if (iSockMover >= 0)
02344 {
02345 if (iSendEOS)
02346 {
02347
02348 iStatus = STA_END_OF_SESSION;
02349 iRC = rawSendStatus(iSockMover, iStatus, NULL);
02350 if (iRC <= 0) fprintf(fLogClient,
02351 "-E- %s: sending status buffer (EOS) to %s\n", cModule, cServer);
02352 else if (iDebug) printf(
02353 " status buffer (EOS) sent to %s (%d bytes)\n",
02354 cServer, iRC);
02355 }
02356
02357 if (iDebug) printf(
02358 " close connection %d to %s\n", iSockMover, cServer);
02359 iRC = shutdown(iSockMover, 2);
02360 if (iDebug)
02361 printf(" rc shutdown = %d\n", iRC);
02362 iRC = close(iSockMover);
02363 if (iDebug)
02364 printf(" rc close = %d\n", iRC);
02365 }
02366
02367 if (iFileId >= 0)
02368 {
02369 free(pAPIFile[iFileId]);
02370 pAPIFile[iFileId] = NULL;
02371 iFileCount--;
02372 }
02373
02374 }
02375
02376 if (iDebug)
02377 printf("-D- end %s\n\n", cModule);
02378
02379 if (iError)
02380 return -1;
02381 else
02382 return iFileId;
02383
02384 }
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395 int rfio_endfile(int iFileId)
02396 {
02397 char cModule[32] = "rfio_endfile";
02398 int iDebug = 0;
02399 int iRC = 0;
02400 int iSockMover;
02401 int iStatus = STA_END_OF_SESSION;
02402 int ii = 0;
02403
02404 char cServer[16] = "data mover";
02405 char *pcc;
02406
02407 srawStatus sStatus;
02408 srawAPIFile *pcurAPIFile;
02409 srawComm *pCommAPI;
02410 srawComm *pCommServ;
02411 srawCopyCache *pCopyCacheServ;
02412
02413
02414 if (iDebug) printf(
02415 "\n-D- begin %s: close remote file %d\n", cModule, iFileId);
02416 fflush(stdout);
02417
02418 if (iFileCount == 0)
02419 {
02420 fprintf(fLogClient,
02421 "-E- %s: no remote file available for close\n", cModule);
02422 return -1;
02423 }
02424
02425 while (ii < iFileMax)
02426 {
02427 if (pAPIFile[ii])
02428 {
02429 if (pAPIFile[ii]->iFileId == iFileId)
02430 break;
02431 }
02432 ii++;
02433 }
02434
02435 if (ii == iFileMax)
02436 {
02437 fprintf(fLogClient, "-E- %s: remote file %d cannot be closed: not found\n",
02438 cModule, iFileId);
02439 return -1;
02440 }
02441
02442 pcurAPIFile = pAPIFile[iFileId];
02443 pCommAPI = &(pcurAPIFile->sCommAPI);
02444 pCommServ = &(pcurAPIFile->sCommServ);
02445 pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
02446
02447 pcurAPIFile->iBufnoServ = 0;
02448 iSockMover = pcurAPIFile->iSockMover;
02449 if (iSockMover >= 0)
02450 {
02451
02452 iStatus = STA_END_OF_FILE;
02453 iRC = rawSendStatus(iSockMover, iStatus, NULL);
02454 if (iRC <= 0)
02455 fprintf(fLogClient, "-E- %s: sending status buffer (EOF) to %s\n",
02456 cModule, cServer);
02457 else if (iDebug) printf(
02458 " status buffer (EOF) sent to %s (%d bytes)\n",
02459 cServer, iRC);
02460
02461 memset(&sStatus, 0X00, sizeof(srawStatus));
02462 pcc = (char *) &sStatus;
02463 iRC = rawRecvStatus(iSockMover, pcc);
02464 if (iRC < HEAD_LEN)
02465 {
02466 fprintf(fLogClient, "-E- %s: receiving status buffer\n", cModule);
02467 iRC = -1;
02468 goto gErrorEndFile;
02469 }
02470
02471 iStatus = sStatus.iStatus;
02472 if (iDebug) printf(
02473 " status buffer (%d) received (%d byte)\n",
02474 iStatus, iRC);
02475
02476 if (iRC > HEAD_LEN)
02477 {
02478 if (iStatus == STA_CACHE_COPY)
02479 fprintf(fLogClient, sStatus.cStatus);
02480 else
02481 {
02482 fprintf(fLogClient,
02483 "-W- %s: message received from server:\n", cModule);
02484 fprintf(fLogClient, sStatus.cStatus);
02485
02486 if (iStatus != STA_CACHE_COPY_ERROR)
02487 {
02488 iRC = -1;
02489 goto gErrorEndFile;
02490 }
02491 }
02492 }
02493
02494 if (pcurAPIFile->iMassSto)
02495 {
02496 if ( (pcurAPIFile->iOpMode != 2) &&
02497 (iDebug) )
02498 fprintf(fLogClient,
02499 "-I- gStore file %s%s%s closed\n",
02500 pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
02501 }
02502 else fprintf(fLogClient,
02503 "-I- remote output file %s%s%s closed\n",
02504 pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
02505
02506 }
02507
02508 if (iDebug)
02509 {
02510 printf(
02511 " remote file control block %d still active (overall %d)\n",
02512 iFileId, iFileCount);
02513 printf("-D- end %s\n\n", cModule);
02514 }
02515
02516 iRC = 0;
02517
02518 gErrorEndFile:
02519 return iRC;
02520
02521 }
02522
02523
02524
02525
02526
02527
02528
02529
02530 ssize_t rfio_read(int iFileId,
02531 char *pcBuffer,
02532 size_t iItems)
02533 {
02534 char cModule[32] = "rfio_read";
02535 int iDebug = 0;
02536 int iRC;
02537
02538 int iSockMover;
02539 int iSeekMode;
02540 int iOffset;
02541 int iBufsizeRead;
02542 int iBufnoServ;
02543 int iDataServ;
02544
02545 int iStatus;
02546 int iStatusLen;
02547 int iBufsizeRecv;
02548
02549 char *pcc;
02550 int ii = 0;
02551 int iBuf, iBufl;
02552 int *pint;
02553
02554 srawAPIFile *pcurAPIFile;
02555 srawComm *pCommAPI;
02556 srawComm *pCommServ;
02557
02558 if (iDebug)
02559 printf("\n-D- begin %s: fileId %d\n", cModule, iFileId);
02560
02561 if (iFileCount == 0)
02562 {
02563 fprintf(fLogClient, "-E- %s: no remote file open for read\n", cModule);
02564 return -1;
02565 }
02566
02567 while (ii < iFileMax)
02568 {
02569 if (pAPIFile[ii])
02570 {
02571 if (pAPIFile[ii]->iFileId == iFileId)
02572 break;
02573 }
02574 ii++;
02575 }
02576
02577 if (ii == iFileMax)
02578 {
02579 fprintf(fLogClient, "-E- %s: remote file %d cannot be read: not opened\n",
02580 cModule, iFileId);
02581 return -1;
02582 }
02583
02584 if (iDebug)
02585 printf(" open buffer %d, fileId %d\n", ii, iFileId);
02586
02587 pcurAPIFile = pAPIFile[iFileId];
02588 pCommAPI = &(pcurAPIFile->sCommAPI);
02589 pCommServ = &(pcurAPIFile->sCommServ);
02590
02591 iBufnoServ = pcurAPIFile->iBufnoServ;
02592 iDataServ = pcurAPIFile->iDataServ;
02593
02594 iBufnoServ++;
02595 if (iDebug)
02596 {
02597 printf(" remote file control block %d selected\n", ii);
02598 printf(" file %d, buffer %d: read %d bytes\n",
02599 iFileId, iBufnoServ, iItems);
02600 }
02601
02602 iBufsizeRead = pcurAPIFile->iBufsizeAct;
02603 if (iDebug)
02604 {
02605 if (iBufsizeRead != iItems)
02606 printf( " new buffer size %d\n", iItems);
02607 printf(" send request for new buffer\n");
02608 }
02609
02610 iSockMover = pcurAPIFile->iSockMover;
02611 iSeekMode = pcurAPIFile->iSeekMode;
02612 iOffset = pcurAPIFile->iOffset;
02613 iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, (signed) iItems);
02614 if (iRC != 0)
02615 {
02616 fprintf(fLogClient, "-E- %s: sending request for next data buffer\n",
02617 cModule);
02618 return -1;
02619 }
02620
02621
02622 if (iSeekMode != -1)
02623 {
02624 pcurAPIFile->iSeekMode = -1;
02625 pcurAPIFile->iOffset = 0;
02626 }
02627
02628 pcurAPIFile->iBufsizeAct = (int) iItems;
02629
02630
02631
02632
02633 pcc = (char *) &iBufsizeRecv;
02634 iBuf = iint;
02635 while(iBuf > 0)
02636 {
02637 gRetryLen:
02638 if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
02639 {
02640 fprintf(fLogClient,
02641 "-E- %s: receiving data length from server (buffer %d)",
02642 cModule, iBufnoServ);
02643 perror("");
02644 goto gRetryLen;
02645 }
02646
02647 if (iRC == 0)
02648 {
02649 ii = iint - iBuf;
02650 fprintf(fLogClient,
02651 "-E- %s: connection to sender broken, %d byte of data length (%d byte) received (buffer %d)\n",
02652 cModule, ii, iint, iBufnoServ);
02653
02654 return -1;
02655 }
02656
02657 iBuf -= iRC;
02658 pcc += iRC;
02659
02660 if (iDebug == 2)
02661 {
02662 printf("%d.", iRC);
02663 fflush(stdout);
02664 }
02665 }
02666
02667 iBufsizeRecv = ntohl(iBufsizeRecv);
02668 if (iDebug == 2)
02669 printf("%d_", iBufsizeRecv);
02670
02671 if (iBufsizeRecv < 0)
02672 {
02673 if (iBufsizeRecv != IDENT_STATUS)
02674 {
02675 fprintf(fLogClient, "-E- %s: invalid status header received (%d)\n",
02676 cModule, iBufsizeRecv);
02677 return -1;
02678 }
02679 if (iDebug)
02680 printf("-D- status header found\n");
02681
02682
02683 pcc = pcBuffer;
02684 iBuf = HEAD_LEN - 4;
02685 iBufl = iBuf;
02686 while(iBuf > 0)
02687 {
02688 if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
02689 {
02690 fprintf(fLogClient,
02691 "-E- %s: receiving remainder of status header from server (buffer %d)",
02692 cModule, iBufnoServ);
02693 perror(" ");
02694
02695 return -1;
02696 }
02697
02698 if (iRC == 0)
02699 {
02700 ii = iBufl - iBuf;
02701 fprintf(fLogClient,
02702 "-W- %s: connection to sender broken, %d byte of remainder of status header (%d byte) received (buffer %d)\n",
02703 cModule, ii, iBufl, iBufnoServ);
02704
02705 return -1;
02706 }
02707
02708 if (iDebug == 2)
02709 printf("%d.", iRC);
02710
02711 iBuf -= iRC;
02712 pcc += iRC;
02713 }
02714
02715 pint = (int *) pcBuffer;
02716 iStatus = ntohl(*pint);
02717 if ( (iStatus != STA_END_OF_FILE) &&
02718 (iStatus != STA_END_OF_SESSION) &&
02719 (iStatus != STA_ERROR) &&
02720 (iStatus != STA_ERROR_EOF) )
02721 {
02722 fprintf(fLogClient, "-E- %s: unexpected status from server: %d\n",
02723 cModule, iStatus);
02724 return -1;
02725 }
02726
02727 if ( (iStatus == STA_END_OF_FILE) ||
02728 (iStatus == STA_END_OF_SESSION) )
02729 {
02730 if (iDebug) printf(" EOF on input\n");
02731
02732 if (iDataServ == 0)
02733 {
02734 fprintf(fLogClient, "-E- %s: %s%s%s empty\n",
02735 cModule, pCommServ->cNamefs,
02736 pCommServ->cNamehl, pCommServ->cNamell);
02737 return -1;
02738 }
02739 else return 0;
02740 }
02741 else
02742 {
02743 pint++;
02744 iStatusLen = ntohl(*pint);
02745 if (iStatusLen > 0)
02746 {
02747 iRC = rawRecvError(iSockMover, iStatusLen, pcc);
02748 if (iRC < 0)
02749 {
02750 fprintf(fLogClient,
02751 "-E- %s: receiving status message from server, rc = %d\n",
02752 cModule, iRC);
02753 return -1;
02754 }
02755
02756 if ( (iStatus == STA_ERROR) ||
02757 (iStatus == STA_ERROR_EOF) )
02758 {
02759 fprintf(fLogClient,
02760 "-E- %s: received error status from server:\n",
02761 cModule);
02762 fprintf(fLogClient, "%s\n", pcc);
02763 return -1;
02764 }
02765
02766
02767 printf("%s\n", pcc);
02768
02769 }
02770 }
02771
02772 }
02773 else if (iBufsizeRecv != iItems)
02774 {
02775 if (iDebug)
02776 {
02777 if (iBufsizeRecv) printf(
02778 "-W- requested %d bytes, received buffer length %d bytes\n",
02779 iItems, iBufsizeRecv);
02780 else printf("-W- EOF reached\n");
02781 }
02782 iItems = (size_t) iBufsizeRecv;
02783 }
02784
02785
02786 iBuf = iBufsizeRecv;
02787 pcc = pcBuffer;
02788 while(iBuf > 0)
02789 {
02790 gRetryData:
02791 if ( (iRC = recv( iSockMover, pcc, (unsigned) iBuf, 0 )) < 0 )
02792 {
02793 if (iDebug) fprintf(fLogClient,
02794 "-E- %s: receiving data from server (buffer %d)\n",
02795 cModule, iBufnoServ);
02796 perror("EEE ");
02797 goto gRetryData;
02798 }
02799
02800 if (iRC == 0)
02801 {
02802 ii = iBufsizeRecv - iBuf;
02803 fprintf(fLogClient,
02804 "-W- %s: connection to sender broken, %d byte of data buffer (%d byte) received (buffer %d)\n",
02805 cModule, ii, iBufsizeRecv, iBufnoServ);
02806
02807 return -1;
02808 }
02809
02810 if (iDebug == 2)
02811 {
02812 printf("%d:", iRC);
02813 fflush(stdout);
02814 }
02815
02816 iBuf -= iRC;
02817 pcc += iRC;
02818 pcurAPIFile->iDataServ += iRC;
02819
02820 }
02821
02822 if (iBufsizeRecv)
02823 {
02824 pcurAPIFile->iBufnoServ++;
02825 if (iDebug == 2)
02826 printf(" buffer %d received\n", pcurAPIFile->iBufnoServ);
02827 }
02828
02829 if (iDebug)
02830 printf("-D- end %s\n\n", cModule);
02831
02832 return iBufsizeRecv;
02833
02834 }
02835
02836
02837
02838
02839
02840
02841
02842
02843 ssize_t rfio_write(int iFileId,
02844 const char *pcBuffer,
02845 size_t iItems)
02846 {
02847 char cModule[32] = "rfio_write";
02848 int iDebug = 0;
02849
02850 int iRC;
02851 char *pcc;
02852 int ii = 0;
02853 int iBuf;
02854
02855 int iSockMover;
02856 int iBufsizeWrite;
02857 int iBufnoServ;
02858
02859 srawAPIFile *pcurAPIFile;
02860
02861 srawComm *pCommAPI;
02862 srawComm *pCommServ;
02863
02864 if (iDebug)
02865 {
02866 printf("\n-D- begin %s\n", cModule);
02867 fflush(stdout);
02868 }
02869
02870 if (iItems <= 0)
02871 {
02872 fprintf(fLogClient,
02873 "-W- invalid no. of bytes to write: %d\n", iItems);
02874 return 0;
02875 }
02876
02877 if (iFileCount == 0)
02878 {
02879 fprintf(fLogClient, "-E- %s: no remote file open for write\n", cModule);
02880 return -1;
02881 }
02882
02883 ii = 0;
02884 while (ii < iFileMax)
02885 {
02886 if (pAPIFile[ii])
02887 {
02888 if (pAPIFile[ii]->iFileId == iFileId)
02889 break;
02890 }
02891 ii++;
02892 }
02893
02894 if (ii == iFileMax)
02895 {
02896 fprintf(fLogClient,
02897 "-E- %s: remote file %d cannot be written: not opened\n",
02898 cModule, iFileId);
02899 return -1;
02900 }
02901
02902 pcurAPIFile = pAPIFile[iFileId];
02903 pCommServ = &(pcurAPIFile->sCommServ);
02904 pCommAPI = &(pcurAPIFile->sCommAPI);
02905
02906 iBufnoServ = pcurAPIFile->iBufnoServ;
02907 iBufnoServ++;
02908
02909 if (iDebug)
02910 {
02911 printf(" remote file control block %d selected\n", ii);
02912 printf(" file %d, buffer %d: write %d bytes\n",
02913 iFileId, iBufnoServ, iItems);
02914 }
02915
02916 if (iItems > pCommAPI->iBufsizeFile)
02917 {
02918 pCommAPI->iBufsizeFile = (int) iItems;
02919 pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
02920 }
02921
02922 if (iDebug)
02923 {
02924 if (pcurAPIFile->iBufsizeAct != iItems)
02925 printf( " new buffer size %d\n", iItems);
02926 printf(" send new buffer\n");
02927 }
02928
02929
02930
02931
02932 iSockMover = pcurAPIFile->iSockMover;
02933 pcurAPIFile->iBufsizeAct = (int) iItems;
02934 iBufsizeWrite = htonl( (int) iItems);
02935 iBuf = iint;
02936 pcc = (char *) &iBufsizeWrite;
02937 while (iBuf)
02938 {
02939 iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
02940 if (iRC <= 0)
02941 {
02942 if (iRC == 0) fprintf(fLogClient,
02943 "-E- %s: sending data length to server broken\n", cModule);
02944 else
02945 {
02946 fprintf(fLogClient,
02947 "-E- %s: sending data length to server (buffer %d)",
02948 cModule, iBufnoServ);
02949 perror(" ");
02950 }
02951 return -1;
02952 }
02953
02954 iBuf -= iRC;
02955 pcc += iRC;
02956
02957 if (iDebug == 2)
02958 {
02959 printf("%d(%d)_", iRC, iItems);
02960 fflush(stdout);
02961 }
02962
02963 }
02964
02965 iBuf = (int) iItems;
02966 pcc = (char *) pcBuffer;
02967 while (iBuf)
02968 {
02969 iRC = send( iSockMover, pcc, (unsigned) iBuf, 0 );
02970 if (iRC <= 0)
02971 {
02972 if (iRC == 0) fprintf(fLogClient,
02973 "-E- %s: sending data to server broken\n", cModule);
02974 else
02975 {
02976 fprintf(fLogClient,
02977 "-E- %s: sending data to server (buffer %d, %d bytes)",
02978 cModule, iBufnoServ, iBuf);
02979 perror(" ");
02980 }
02981 return -1;
02982 }
02983
02984 iBuf -= iRC;
02985 pcc += iRC;
02986 pcurAPIFile->iDataServ += iRC;
02987
02988 if (iDebug == 2)
02989 {
02990 printf("%d.", iRC);
02991 fflush(stdout);
02992 }
02993
02994 }
02995
02996 if (iItems)
02997 {
02998 pcurAPIFile->iBufnoServ++;
02999 if (iDebug == 2)
03000 printf(" buffer %d sent\n", pcurAPIFile->iBufnoServ);
03001 }
03002
03003 if (iDebug)
03004 printf("-D- end %s\n", cModule);
03005
03006 return (ssize_t) iItems;
03007
03008 }
03009
03010
03011
03012
03013
03014
03015
03016
03017 int rfio_newfile(int iFileId,
03018 char *pcFile)
03019 {
03020 char cModule[32] = "rfio_newfile";
03021 int iDebug = 0;
03022 int iRC;
03023 int ii = 0;
03024 int iArchLen = 0;
03025 int iPathLen = 0;
03026 int iFileLen = 0;
03027 int iCopyMode = 0;
03028 int iCopyLen = 0;
03029 int iCopyBuffer = 0;
03030
03031 int iMassSto = -1;
03032
03033
03034 int iMaxConnect = 0;
03035 int iSockMover;
03036 char cNodeMover[MAX_NODE] = "";
03037 int inewPath = 0;
03038 int iError = 0;
03039 int iStatus = 0;
03040 int iStatusOkay = 0;
03041 int iStatusLoop = 0;
03042
03043 char *pcc, *pcc1, *pcc2;
03044 char cTemp[STATUS_LEN] = "";
03045
03046 char cNamefs[MAX_OBJ_FS] = "", *pcNamefs;
03047 char cNamehl[MAX_OBJ_HL] = "", *pcNamehl;
03048 char cNamell[MAX_OBJ_LL] = "", *pcNamell;
03049
03050 srawStatus sStatus;
03051 void *pBufQuery;
03052 srawQueryResult sQuery;
03053 srawObjAttr *pQAttr;
03054
03055 srawAPIFile *pcurAPIFile;
03056 srawComm *pCommAPI;
03057 srawComm *pCommServ;
03058 srawCopyCache *pCopyCacheServ;
03059
03060
03061 pcNamefs = cNamefs;
03062 pcNamehl = cNamehl;
03063 pcNamell = cNamell;
03064
03065 if (iDebug)
03066 printf("\n-D- begin %s\n", cModule);
03067
03068 if (iFileCount == 0)
03069 {
03070 fprintf(fLogClient,
03071 "-E- %s: no open connection to server existing\n", cModule);
03072 iError = -1;
03073 goto gEndNewFile;
03074 }
03075
03076 ii = 0;
03077 while (ii < iFileMax)
03078 {
03079 if (pAPIFile[ii])
03080 {
03081 if (pAPIFile[ii]->iFileId == iFileId)
03082 break;
03083 }
03084 ii++;
03085 }
03086
03087 if (ii == iFileMax)
03088 {
03089 fprintf(fLogClient, "-E- %s: no open connection to server\n", cModule);
03090 iError = -1;
03091 goto gEndNewFile;
03092 }
03093
03094 if (iDebug)
03095 printf(" requested API control block %d\n", iFileId);
03096
03097 pcurAPIFile = pAPIFile[iFileId];
03098 pCommAPI = &(pcurAPIFile->sCommAPI);
03099 pCommServ = &(pcurAPIFile->sCommServ);
03100 pCopyCacheServ = &(pcurAPIFile->sCopyCacheServ);
03101
03102 if ( (pcurAPIFile->iAction == 1) ||
03103 (pCommAPI->iAction == QUERY_RETRIEVE_RECORD) ||
03104 (pCommAPI->iAction == RETRIEVE_RECORD) )
03105 {
03106 fprintf(fLogClient, "-E- %s for read not supported\n", cModule);
03107 iError = -1;
03108 goto gEndNewFile;
03109 }
03110 else if (pcurAPIFile->iAction == 2)
03111 {
03112 if (iDebug)
03113 printf(" connection is open for write\n");
03114 }
03115 else
03116 {
03117 fprintf(fLogClient, "-E- %s: connection is open for unexpected action %d\n",
03118 cModule, pcurAPIFile->iAction);
03119 iError = -1;
03120 goto gEndNewFile;
03121 }
03122
03123 if (iDebug)
03124 printf(" check name parts in %s\n", pcFile);
03125
03126 pcc1 = (char *) strrchr(pcFile, *pcDevDelim);
03127 if (pcc1 == NULL)
03128 {
03129 fprintf(fLogClient,
03130 "-E- %s: invalid remote file name %s: node name missing\n",
03131 cModule, pcFile);
03132 iError = -1;
03133 goto gEndNewFile;
03134 }
03135
03136 strcpy(cTemp, pcFile);
03137 pcc = (char *) strchr(pcFile, *pcObjDelim);
03138 if (pcc == NULL)
03139 {
03140 fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
03141 cModule, pcFile);
03142 iError = -1;
03143 goto gEndNewFile;
03144 }
03145
03146 ii = pcc1 - pcc;
03147 if (ii < 0)
03148 ii = -ii;
03149 if (ii != 1)
03150 {
03151 fprintf(fLogClient,
03152 "-E- %s: invalid remote file name %s - possibly leading '/' in archive name missing\n",
03153 cModule, pcFile);
03154 iError = -1;
03155 goto gEndNewFile;
03156 }
03157
03158 if (strncmp(cTemp, "rfiocopy:", 9) == 0)
03159 {
03160 iMassSto = 0;
03161 if (iDebug)
03162 printf(" copy via RFIO server\n");
03163 }
03164 else if (strncmp(cTemp, "rfiodaq:", 8) == 0)
03165 {
03166 iMassSto = 2;
03167 if (iDebug)
03168 printf(" copy to mass storage (DAQPool)\n");
03169 }
03170 else if (strncmp(cTemp, "rfio:", 5) == 0)
03171 {
03172 iMassSto = 1;
03173 if (iDebug)
03174 printf(" copy to mass storage (ArchivePool)\n");
03175 }
03176 else
03177 {
03178 iMassSto = 1;
03179 if (iDebug)
03180 printf(" copy to mass storage (ArchivePool)\n");
03181 }
03182
03183 if (pcurAPIFile->iMassSto != iMassSto)
03184 {
03185 fprintf(fLogClient,
03186 "-E- %s: remote file %s incompatible with open server connection\n",
03187 cModule, pcFile);
03188 iError = -1;
03189 goto gEndNewFile;
03190 }
03191
03192 if (iDebug) printf(
03193 " requested server consistent with open connection (%d)\n",
03194 iMassSto);
03195
03196
03197 if (iMassSto)
03198 {
03199 if (strlen(pcc) > MAX_OBJ_FS - 1)
03200 strncpy(pcNamefs, pcc, MAX_OBJ_FS-1);
03201 else
03202 strcpy(pcNamefs, pcc);
03203
03204 pcc = pcNamefs;
03205 pcc++;
03206 pcc1 = (char *) strchr(pcc, *pcObjDelim);
03207 if (pcc1 == NULL)
03208 {
03209 ii = MAX_OBJ_FS-1;
03210 if (iDebug) printf(
03211 "-E- archive name starting with %s too long, max allowed %d chars\n",
03212 pcNamefs, ii);
03213 fprintf(fLogClient,
03214 "-E- %s: archive name starting with %s too long, max allowed %d chars\n",
03215 cModule, pcNamefs, ii);
03216 iError = -1;
03217 goto gEndNewFile;
03218 }
03219
03220 strncpy(pcc1, "\0", 1);
03221 if (strlen(pCommServ->cNamefs))
03222 {
03223 if (strcmp(pCommServ->cNamefs, pcNamefs))
03224 {
03225 fprintf(fLogClient,
03226 "-E- %s: invalid archive name %s, expected %s\n",
03227 cModule, pcNamefs, pCommServ->cNamefs);
03228 iError = -1;
03229 goto gEndNewFile;
03230 }
03231 }
03232
03233 strcpy(pCommServ->cNamefs, pcNamefs);
03234 iArchLen = strlen(pcNamefs);
03235
03236 if (iDebug) printf(
03237 " archive name: %s (len %d chars)\n", pcNamefs, iArchLen);
03238
03239 if (iArchLen <= 3)
03240 {
03241 fprintf(fLogClient,
03242 "-E- %s: invalid archive name '%s'\n", cModule, pcNamefs);
03243 iError = -1;
03244 goto gEndNewFile;
03245 }
03246
03247 pcc = (char *) strchr(cTemp, *pcObjDelim);
03248 pcc++;
03249 pcc2 = (char *) strchr(pcc, *pcObjDelim);
03250 if (pcc2 == NULL)
03251 {
03252 fprintf(fLogClient,
03253 "-E- %s: invalid remote file name %s: missing path name\n",
03254 cModule, pcFile);
03255 iError = -1;
03256 goto gEndNewFile;
03257 }
03258
03259 if (iDebug)
03260 printf(" path + file name: %s\n", pcc2);
03261
03262 pcc = pcc2;
03263 pcc++;
03264 pcc1 = (char *) strrchr(pcc, *pcObjDelim);
03265 if (pcc1 == NULL)
03266 {
03267 fprintf(fLogClient,
03268 "-E- %s: invalid remote file name %s: missing file name\n",
03269 cModule, pcFile);
03270 iError = -1;
03271 goto gEndNewFile;
03272 }
03273
03274 if (iDebug)
03275 printf(" file name: %s\n", pcc1);
03276
03277 iPathLen = pcc2-pcc1;
03278 if (iPathLen < 0)
03279 iPathLen = -iPathLen;
03280 if (iDebug)
03281 printf(" length path name: %d\n", iPathLen);
03282
03283 if (iPathLen >= MAX_OBJ_HL)
03284 {
03285 ii = MAX_OBJ_HL - 1;
03286 if (iDebug)
03287 printf("-E- path name too long, max allowed %d chars\n", ii);
03288 fprintf(fLogClient,
03289 "-E- %s: remote path name (%d chars) too long, max allowed %d\n",
03290 cModule, iPathLen, ii);
03291 iError = -1;
03292 goto gEndNewFile;
03293 }
03294
03295 strncpy(pcNamehl, pcc2, (unsigned) iPathLen);
03296 if (iDebug)
03297 printf(" path name: %s\n", pcNamehl);
03298
03299 strcpy(pCommAPI->cNamehl, rawGetHLName(pcNamehl));
03300 if (strcmp(pcNamehl, pCommAPI->cNamehl))
03301 {
03302 strcpy(pcNamehl, pCommAPI->cNamehl);
03303 printf(" gStore path name corrected to %s\n", pcNamehl);
03304
03305 strcpy(pcFile, cPrefix);
03306 strcat(pcFile, cNamefs);
03307 strcat(pcFile, cNamehl);
03308 strcat(pcFile, pcc1);
03309 if (iDebug) printf(
03310 " new full file name: %s\n", pcFile);
03311 }
03312
03313 iFileLen = strlen(pcc1);
03314 if (iDebug)
03315 printf(" length file name: %d\n", iFileLen);
03316
03317 ii = MAX_OBJ_LL-1;
03318 if ((int) strlen(pcc1) > ii)
03319 {
03320 if (iDebug)
03321 printf("-E- file name too long, max allowed %d chars\n", ii);
03322 fprintf(fLogClient,
03323 "-E- %s: file name %s (%d chars) too long, max allowed %d\n",
03324 cModule, pcc1, iFileLen, ii);
03325 iError = -1;
03326 goto gEndNewFile;
03327 }
03328
03329 strcpy(pcNamell, pcc1);
03330 if (iDebug)
03331 printf(" file name: %s\n", pcNamell);
03332
03333 }
03334 else
03335 {
03336 strcpy(pCommServ->cNamefs, "");
03337
03338 strcpy(cTemp, pcc);
03339 pcc = cTemp;
03340 pcc++;
03341 pcc1 = (char *) strrchr(pcc, *pcObjDelim);
03342 if (pcc1 == NULL)
03343 {
03344 fprintf(fLogClient, "-E- %s: invalid remote file name %s\n",
03345 cModule, pcFile);
03346 iError = -1;
03347 goto gEndNewFile;
03348 }
03349
03350 if (strlen(pcc1) > MAX_OBJ_LL-1)
03351 {
03352 ii = MAX_OBJ_LL-1;
03353 fprintf(fLogClient,
03354 "-E- %s: remote file name %s too long (max %d chars)\n",
03355 cModule, pcc1, ii);
03356 iError = -1;
03357 goto gEndNewFile;
03358 }
03359
03360 strcpy(pcNamell, pcc1);
03361 if (iDebug) printf(
03362 " remote file name on RFIO server: %s\n", pcNamell);
03363
03364 strncpy(pcc1, "\0", 1);
03365 if (strlen(cTemp) > MAX_OBJ_HL-1)
03366 {
03367 ii = MAX_OBJ_HL-1;
03368 fprintf(fLogClient,
03369 "-E- %s: remote path name %s too long (max %d chars)\n",
03370 cModule, cTemp, ii);
03371 iError = -1;
03372 goto gEndNewFile;
03373 }
03374
03375 strcpy(pcNamehl, cTemp);
03376 if (iDebug) printf(
03377 " remote path name on RFIO server: %s\n", pcNamehl);
03378
03379 }
03380
03381 if (strlen(pCommServ->cNamehl))
03382 {
03383 if (strcmp(pCommServ->cNamehl, pcNamehl))
03384 {
03385 fprintf(fLogClient, "-W- new path name %s, previous %s\n",
03386 pcNamehl, pCommServ->cNamehl);
03387 inewPath = 1;
03388 }
03389 else
03390 inewPath = 0;
03391 }
03392 else
03393 {
03394 strcpy(pCommServ->cNamehl, pcNamehl);
03395 strcpy(pCommAPI->cNamehl, pcNamehl);
03396 }
03397
03398 if (strlen(pCommAPI->cNamefs) < 3)
03399 strcpy(pCommAPI->cNamefs, pCommServ->cNamefs);
03400
03401 strcpy(pCommAPI->cNamell, pcNamell);
03402 strcpy(pCommServ->cNamell, pcNamell);
03403 if (inewPath)
03404 {
03405 strcpy(pCommServ->cNamehl, pcNamehl);
03406 strcpy(pCommAPI->cNamehl, pcNamehl);
03407 }
03408
03409 if (iDebug)
03410 printf(" file name: %s\n", pcNamell);
03411
03412 pCommServ->iBufsizeFile = htonl(pCommAPI->iBufsizeFile);
03413
03414
03415
03416 if (iMassSto)
03417 {
03418 iATLServer = pCommAPI->iATLServer;
03419 if (iDebug) printf(
03420 " query file %s in ATL server %d\n", pcFile, iATLServer);
03421
03422 pBufQuery = &sQuery;
03423 pQAttr = &(sQuery.objAttr);
03424
03425 pCommServ->iAction = htonl(QUERY_ARCHIVE_RECORD);
03426
03427 iRC = rawQueryFile(pcurAPIFile->iSockMaster, 0,
03428 pCommServ, &pBufQuery);
03429
03430 pCommServ->iAction = htonl(ARCHIVE_RECORD);
03431
03432 if (iRC)
03433 {
03434 if (iRC < 0)
03435 {
03436 if (iRC == -1001) sprintf(rfio_errmsg,
03437 "-E- no write access to archive %s in mass storage\n",
03438 pCommAPI->cNamefs);
03439 else if (iRC == -1000) sprintf(rfio_errmsg,
03440 "-E- no archive %s in mass storage found\n",
03441 pCommAPI->cNamefs);
03442 else sprintf(rfio_errmsg,
03443 "-E- file %s: query in mass storage failed, rc = %d\n",
03444 pcFile, iRC);
03445 }
03446 else sprintf(rfio_errmsg,
03447 "-E- file %s already available in mass storage\n",
03448 pcFile);
03449 fprintf(fLogClient, "%s", rfio_errmsg);
03450
03451 if ( (iRC == -1001) || (iRC == -1000) )
03452 iError = -1;
03453 else
03454 iError = 1;
03455
03456 goto gEndNewFile;
03457 }
03458
03459 if (iDebug) printf(
03460 " file %s not yet available in mass storage\n", pcFile);
03461
03462 }
03463
03464 gNextCmdNewFile:
03465 iCopyMode = ntohl(pCopyCacheServ->iCopyMode);
03466 if (iCopyMode)
03467 {
03468 iCopyLen = ntohl(pCopyCacheServ->iCopyLen);
03469 if (iCopyLen == 0)
03470 {
03471 iCopyBuffer = 1;
03472 ii = irawCopyCache - HEAD_LEN;
03473 pCopyCacheServ->iCopyLen = htonl(ii);
03474 if (iDebug)
03475 printf(" send copy parameters to DM\n");
03476 }
03477 else if (iDebug)
03478 printf(" copy parameters already sent to DM\n");
03479 }
03480 else if (iDebug)
03481 printf(" data are only written to WC\n");
03482
03483 if (iDebug)
03484 {
03485 printf(" send command buffer to server %s: id: %d, action %d, bufsize %d",
03486 pcurAPIFile->cNodeMover,
03487 pCommAPI->iIdent,
03488 pCommAPI->iAction,
03489 pCommAPI->iBufsizeFile);
03490 if (iCopyBuffer)
03491 printf(", data len %d\n",
03492 pCommAPI->iCommLen + irawCopyCache);
03493 else
03494 printf(", data len %d\n", pCommAPI->iCommLen);
03495 }
03496
03497 iSockMover = pcurAPIFile->iSockMover;
03498 pcc = (char *) pCommServ;
03499 if (iCopyBuffer)
03500 pCommServ->iCommLen = htonl(pCommAPI->iCommLen + irawCopyCache);
03501
03502
03503 if ( (iRC = send(iSockMover, pcc, (unsigned) irawComm, 0 )) < 0 )
03504 {
03505 fprintf(fLogClient,
03506 "-E- %s: sending command buffer to server %s (rc = %d)\n",
03507 cModule, pcurAPIFile->cNodeMover, iRC);
03508 perror(" ");
03509 iError = -1;
03510 goto gEndNewFile;
03511 }
03512
03513 if (irawComm != iRC)
03514 {
03515 fprintf(fLogClient,
03516 "-E- %s: incomplete command buffer sent to server %s (%d of %d bytes)\n",
03517 cModule, pcurAPIFile->cNodeMover, iRC, irawComm);
03518
03519 iError = -1;
03520 goto gEndNewFile;
03521 }
03522
03523 if (iDebug) printf(
03524 " command buffer sent to server %s (%d byte)\n",
03525 pcurAPIFile->cNodeMover, irawComm);
03526
03527 if (iCopyBuffer)
03528 {
03529 pcc = (char *) pCopyCacheServ;
03530 if ( (iRC = send(iSockMover, pcc, (unsigned) irawCopyCache, 0 )) < 0 )
03531 {
03532 fprintf(fLogClient,
03533 "-E- %s: sending copy buffer to server %s (rc = %d)\n",
03534 cModule, pcurAPIFile->cNodeMover, iRC);
03535 perror(" ");
03536 iError = -1;
03537 goto gEndNewFile;
03538 }
03539
03540 if (irawCopyCache != iRC)
03541 {
03542 fprintf(fLogClient,
03543 "-E- %s: incomplete copy buffer sent to server %s (%d of %d bytes)\n",
03544 cModule, pcurAPIFile->cNodeMover, iRC, irawCopyCache);
03545
03546 iError = -1;
03547 goto gEndNewFile;
03548 }
03549
03550 if (iDebug) printf(
03551 " copy buffer sent to server %s (%d byte)\n",
03552 pcurAPIFile->cNodeMover, irawCopyCache);
03553
03554 pCommServ->iCommLen = htonl(pCommAPI->iCommLen);
03555
03556 }
03557
03558
03559
03560 pcc = (char *) &sStatus;
03561 iStatusOkay = 0;
03562 iStatusLoop = 0;
03563 while (iStatusOkay == 0)
03564 {
03565 iStatusLoop++;
03566
03567 memset(&sStatus, 0X00, sizeof(srawStatus));
03568 iRC = rawRecvStatus(iSockMover, pcc);
03569 iStatus = sStatus.iStatus;
03570 if (iDebug) printf(
03571 " status %d received (%d byte)\n", iStatus, iRC);
03572 if (iRC != HEAD_LEN)
03573 {
03574 if (iRC < HEAD_LEN) fprintf(fLogClient,
03575 "-E- %s: receiving status buffer from server\n",
03576 cModule);
03577 else
03578 {
03579 if (iStatus == STA_CACHE_FULL)
03580 {
03581 if ( (iStatusLoop < iStatusLoopMax) &&
03582 (iMassSto != 2) )
03583 {
03584 fprintf(fLogClient,
03585 "-W- %s: write cache currently full ... sleep %d s (%d of %d)\n",
03586 cModule, iSleepCacheFull,
03587 iStatusLoop, iStatusLoopMax);
03588 continue;
03589 }
03590 else
03591 {
03592 fprintf(fLogClient,
03593 "-W- %s: write cache currently full, archive to tape\n",
03594 cModule);
03595 pCommServ->iAction = htonl(ARCHIVE_RECORD);
03596 pCommServ->iArchDev = htonl(ARCH_TAPE);
03597 pCommAPI->iAction = ARCHIVE_RECORD;
03598 pCommAPI->iArchDev = ARCH_TAPE;
03599
03600
03601 iCopyMode = 0;
03602 pCopyCacheServ->iCopyMode = htonl(0);
03603
03604 goto gNextCmdNewFile;
03605 }
03606 }
03607 else if (iStatus == STA_SWITCH_SERVER)
03608 {
03609 strcpy(cNodeMover, sStatus.cStatus);
03610
03611 fprintf(fLogClient,
03612 "-W- write cache on DM %s full or too much load, switch to %s\n",
03613 pcurAPIFile->cNodeMover, cNodeMover);
03614
03615 if (iDebug) printf(
03616 " close connection %d to data mover %s\n",
03617 iSockMover, pcurAPIFile->cNodeMover);
03618 iRC = shutdown(iSockMover, 2);
03619 if (iDebug)
03620 printf(" rc shutdown = %d\n", iRC);
03621
03622 iRC = close(iSockMover);
03623 if (iDebug)
03624 printf(" rc close = %d\n", iRC);
03625 else if (iRC == 0)
03626 fprintf(fLogClient,
03627 "-I- connection to data mover %s closed\n",
03628 pcurAPIFile->cNodeMover);
03629
03630
03631
03632 if (iDebug) printf(
03633 " connecting to data mover %s:%d\n",
03634 cNodeMover, iPortMover);
03635
03636 iRC = rconnect(cNodeMover, iPortMover,
03637 &iMaxConnect, &iSockMover);
03638 if (iRC)
03639 {
03640 fprintf(fLogClient,
03641 "-E- %s: cannot connect to new data mover %s:%d (ATL server %d)\n",
03642 cModule, cNodeMover, iPortMover, iATLServer);
03643 iError = -2;
03644 }
03645
03646 fprintf(fLogClient,
03647 "-I- successfully connected to new data mover %s:%d (ATL server %d)",
03648 cNodeMover, iPortMover, iATLServer);
03649 if (iMaxConnect)
03650 fprintf(fLogClient, " after %ds", iMaxConnect);
03651 if (iDebug)
03652 printf(" (socket %d)\n", iSockMover);
03653 else
03654 fprintf(fLogClient, "\n");
03655
03656 strcpy(pcurAPIFile->cNodeMover, cNodeMover);
03657 pcurAPIFile->iSockMover = iSockMover;
03658
03659 pCopyCacheServ->iCopyLen = htonl(0);
03660
03661 goto gNextCmdNewFile;
03662
03663 }
03664 else
03665 {
03666 fprintf(fLogClient, "-E- message received from server:\n");
03667 fprintf(fLogClient, " %s\n", sStatus.cStatus);
03668
03669 if (iStatus == STA_ERROR_EOF)
03670 iError = 1;
03671 else
03672 iError = -2;
03673 }
03674
03675 }
03676
03677 goto gEndNewFile;
03678
03679 }
03680 iStatusOkay = 1;
03681
03682 }
03683
03684 if (iDebug)
03685 {
03686 printf(" status (%d) received from server (%d bytes",
03687 iStatus, iRC);
03688 if (iStatusLoop > 1)
03689 printf(", iter %d)\n", iStatusLoop);
03690 else
03691 printf(")\n");
03692 }
03693
03694 iError = 0;
03695
03696
03697
03698
03699
03700 gEndNewFile:
03701 if (iDebug)
03702 printf("-D- end %s\n\n", cModule);
03703
03704 return iError;
03705
03706 }
03707
03708
03709
03710
03711
03712
03713
03714
03715
03716
03717 int rfio_close(int iFileId)
03718 {
03719 char cModule[32] = "rfio_close";
03720 int iDebug = 0;
03721 int iRC;
03722 int iSockMaster;
03723 int iSockMover;
03724 int iStatus = STA_END_OF_SESSION;
03725 int ii = 0;
03726 char *pcc;
03727
03728 srawStatus sStatusRecv;
03729 srawComm *pCommAPI;
03730 srawAPIFile *pcurAPIFile;
03731
03732 if (iDebug) printf(
03733 "\n-D- begin %s: close remote file %d\n", cModule, iFileId);
03734
03735 if (iFileCount == 0)
03736 {
03737 fprintf(fLogClient,
03738 "-E- %s: no remote file available for close\n", cModule);
03739 return -1;
03740 }
03741
03742 while (ii < iFileMax)
03743 {
03744 if (pAPIFile[ii])
03745 {
03746 if (pAPIFile[ii]->iFileId == iFileId)
03747 break;
03748 }
03749 ii++;
03750 }
03751
03752 if (ii == iFileMax)
03753 {
03754 fprintf(fLogClient, "-E- %s: remote file %d cannot be closed: not found\n",
03755 cModule, iFileId);
03756 return -1;
03757 }
03758
03759 pcurAPIFile = pAPIFile[iFileId];
03760 pCommAPI = &(pcurAPIFile->sCommAPI);
03761 iStatus = STA_END_OF_SESSION;
03762 iSockMaster = pcurAPIFile->iSockMaster;
03763
03764 if ( (pcurAPIFile->iMassSto) &&
03765 (pcurAPIFile->iOpMode == 0) )
03766 fprintf(fLogClient, "-I- gStore file %s%s%s closed\n",
03767 pCommAPI->cNamefs, pCommAPI->cNamehl, pCommAPI->cNamell);
03768
03769 if (iSockMaster >= 0)
03770 {
03771
03772 iRC = rawSendStatus(iSockMaster, iStatus, NULL);
03773 if (iRC <= 0) fprintf(fLogClient,
03774 "-E- %s: sending status buffer (EOS) to master\n", cModule);
03775 else if (iDebug) printf(
03776 " status buffer (EOS) sent to master (%d bytes)\n", iRC);
03777
03778 if (iDebug)
03779 printf(" close connection %d to master\n", iSockMaster);
03780 iRC = shutdown(iSockMaster, 2);
03781 if (iDebug)
03782 printf(" rc shutdown = %d\n", iRC);
03783 iRC = close(iSockMaster);
03784 if (iDebug)
03785 printf(" rc close = %d\n", iRC);
03786
03787 }
03788
03789 iSockMover = pcurAPIFile->iSockMover;
03790 if (iSockMover >= 0)
03791 {
03792
03793 iRC = rawSendStatus(iSockMover, iStatus, NULL);
03794 if (iRC <= 0) fprintf(fLogClient,
03795 "-E- %s: sending status buffer (EOS) to data mover\n", cModule);
03796 else if (iDebug) printf(
03797 " status buffer (EOS) sent to data mover (%d bytes)\n", iRC);
03798
03799
03800 if ( (pCommAPI->iAction == ARCHIVE_RECORD) &&
03801 (pCommAPI->iArchDev == ARCH_TAPE) &&
03802 (pcurAPIFile->iOpMode == 0) )
03803 {
03804 memset(&sStatusRecv, 0X00, sizeof(srawStatus));
03805 pcc = (char *) &sStatusRecv;
03806 iRC = rawRecvStatus(iSockMover, pcc);
03807
03808 if (iRC < HEAD_LEN) fprintf(fLogClient,
03809 "-E- %s: receiving confirmation of status buffer (EOS)\n",
03810 cModule);
03811 else if (iDebug) printf(
03812 " status (%d) confirmed by server (%d bytes)\n",
03813 sStatusRecv.iStatus, iRC);
03814 }
03815
03816 if (iDebug)
03817 printf(" close connection %d to data mover\n", iSockMover);
03818 iRC = shutdown(iSockMover, 2);
03819 if (iDebug)
03820 printf(" rc shutdown = %d\n", iRC);
03821 iRC = close(iSockMover);
03822 if (iDebug)
03823 printf(" rc close = %d\n", iRC);
03824 else fprintf(fLogClient,
03825 "-I- connection to data mover %s closed\n",
03826 pcurAPIFile->cNodeMover);
03827
03828 }
03829
03830 free(pAPIFile[iFileId]);
03831 pAPIFile[iFileId] = NULL;
03832 iFileCount--;
03833
03834 if (iDebug)
03835 {
03836 printf(
03837 " remote file control block %d deleted (%d still active)\n",
03838 iFileId, iFileCount);
03839 printf("-D- end %s\n\n", cModule);
03840 }
03841
03842 return 0;
03843
03844 }
03845
03846 #ifdef __USE_LARGEFILE64
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856 int rfio_preseek64(
03857 int iFileId,
03858 const struct iovec64 *piov,
03859 int iBufferNumber)
03860 {
03861 char cModule[32] = "rfio_preseek64";
03862 int iDebug = 0;
03863 int iRC = 0;
03864
03865 if (iDebug) fprintf(fLogClient,
03866 "\n-D- begin %s: iFileId %d\n", cModule, iFileId);
03867
03868 ii = sizeof(long);
03869 if (ii < 8)
03870 {
03871 fprintf(fLogClient,
03872 "-E- 32 bit client: %s not supported\n", cModule);
03873
03874 return -1;
03875 }
03876
03877 fprintf(fLogClient,
03878 "-W- %s not yet implemented for gStore\n", cModule);
03879
03880 if (iDebug)
03881 fprintf(fLogClient, "-D- end %s\n\n", cModule);
03882
03883 return iRC;
03884
03885 }
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895 int64_t rfio_lseek64(
03896 int iFileId,
03897 int64_t i64locOffset,
03898 int ilocSeekMode)
03899 {
03900 char cModule[32] = "rfio_lseek64";
03901 int iDebug = 0;
03902 int iRC;
03903 int ilocOffset;
03904 int ii;
03905
03906 ii = sizeof(long);
03907 if (ii < 8)
03908 {
03909 fprintf(fLogClient,
03910 "-E- 32 bit client: %s not supported\n", cModule);
03911
03912 return -1;
03913 }
03914
03915 if (iDebug) fprintf(fLogClient,
03916 "\n-D- begin %s: iFileId %d, Offset %lld, SeekMode %d\n",
03917 cModule, iFileId, (unsigned long) i64locOffset, ilocSeekMode);
03918
03919 ilocOffset = (int) i64locOffset;
03920
03921 iRC = rfio_lseek(iFileId, ilocOffset, ilocSeekMode);
03922
03923 if (iDebug) fprintf(fLogClient,
03924 "-D- end %s: rc(rfio_lseek) = %d \n\n", cModule, iRC);
03925
03926 return (int64_t) iRC;
03927
03928 }
03929
03930 #endif
03931
03932
03933
03934
03935
03936
03937
03938
03939
03940 int rfio_lseek(int iFileId,
03941 int ilocOffset,
03942 int ilocSeekMode)
03943 {
03944 char cModule[32] = "rfio_lseek";
03945 int iDebug = 0;
03946 int iRC;
03947 int iSockMover;
03948 int iSeekMode;
03949 int iOffset;
03950
03951 srawAPIFile *pcurAPIFile;
03952
03953 if (iDebug)
03954 {
03955 printf("\n-D- begin %s: file %d\n", cModule, iFileId);
03956 if (ilocSeekMode == SEEK_SET)
03957 printf(" position to %d bytes, \n", ilocOffset);
03958 else if (ilocSeekMode == SEEK_CUR)
03959 printf(" position to current + %d bytes, \n", ilocOffset);
03960 else if (ilocSeekMode == SEEK_END)
03961 printf(" position to file size + %d bytes, \n", ilocOffset);
03962 else
03963 {
03964 fprintf(fLogClient, "-E- %s: unexpected offset (%d)\n",
03965 cModule, ilocSeekMode);
03966 return -1;
03967 }
03968 }
03969
03970 pcurAPIFile = pAPIFile[iFileId];
03971 iSeekMode = pcurAPIFile->iSeekMode;
03972
03973
03974 if (iSeekMode != -1)
03975 {
03976 iSockMover = pcurAPIFile->iSockMover;
03977 iOffset = pcurAPIFile->iOffset;
03978 iRC = rawSendRequest(iSockMover, iSeekMode, iOffset, 0);
03979 if (iRC != 0)
03980 {
03981 fprintf(fLogClient, "-E- %s: sending request for seek\n", cModule);
03982 return -1;
03983 }
03984 }
03985
03986 pcurAPIFile->iSeekMode = ilocSeekMode;
03987 pcurAPIFile->iOffset = ilocOffset;
03988
03989 if (iDebug)
03990 printf("-D- end %s\n\n", cModule);
03991
03992 return 0;
03993
03994 }
03995
03996
03997
03998
03999
04000
04001
04002
04003 RFILE *rfio_fopen(char *pcFile,
04004 char *pcOptions)
04005 {
04006 char cModule[32] = "rfio_fopen";
04007 int iDebug = 0;
04008 RFILE *fRemoteFile = NULL;
04009 int iCopyMode = 0;
04010 char *pcCopyPath = NULL;
04011 int iCopyFraction = 0;
04012 int iMaxFile = 0;
04013 int iPathConvention = 0;
04014
04015 if (iDebug)
04016 printf("\n-D- begin %s: calling rfio_fopen_gsidaq\n", cModule);
04017
04018 fRemoteFile = rfio_fopen_gsidaq(
04019 pcFile,
04020 pcOptions,
04021 iCopyMode,
04022 pcCopyPath,
04023 iCopyFraction,
04024 iMaxFile,
04025 iPathConvention);
04026
04027 if (iDebug)
04028 printf("-D- end %s\n\n", cModule);
04029
04030 return fRemoteFile;
04031
04032 }
04033
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043 RFILE *rfio_fopen_gsidaq_dm(
04044 char *pcFile,
04045 char *pcOptions,
04046 char *pcDataMover,
04047 int *piDataMover,
04048 int iCopyMode,
04049
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059 char *pcCopyPath,
04060
04061
04062
04063
04064
04065
04066
04067 int iCopyFraction,
04068
04069
04070
04071
04072 int iMaxFile,
04073
04074
04075
04076
04077
04078
04079
04080
04081 int iPathConvention)
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091 {
04092 char cModule[32] = "rfio_fopen_gsidaq_dm";
04093 int iDebug = 0;
04094 int iFileId = -1;
04095 int iDataMover = 0;
04096 int ilen;
04097 char *pcc;
04098
04099 if (iDebug)
04100 printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
04101
04102 if (*pcOptions == 'r')
04103 {
04104 iFileId = rfio_open_gsidaq(
04105 pcFile, O_RDONLY, 0,
04106 iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
04107 iPathConvention);
04108 }
04109 if (*pcOptions == 'w')
04110 {
04111 iFileId = rfio_open_gsidaq(
04112 pcFile, O_WRONLY | O_CREAT, 0,
04113 iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
04114 iPathConvention);
04115 }
04116
04117 if (iFileId >= 0)
04118 {
04119 ilen = strlen(pAPIFile[iFileId]->cNodeMover);
04120 strcpy(pcDataMover, pAPIFile[iFileId]->cNodeMover);
04121 if (iDebug) printf(
04122 " connected with data mover %s\n", pcDataMover);
04123
04124 pcc = pcDataMover;
04125 pcc += ilen - 2;
04126 iDataMover = atoi(pcc);
04127 *piDataMover = iDataMover;
04128
04129 if (iDebug) printf(
04130 " running number data mover: %d\n", iDataMover);
04131 }
04132
04133 if (iDebug) printf(
04134 "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
04135 cModule, iFileId);
04136
04137 if (iFileId < 0)
04138 return NULL;
04139
04140 return pAPIFile[iFileId];
04141
04142 }
04143
04144
04145
04146
04147
04148
04149
04150
04151
04152 RFILE *rfio_fopen_gsidaq(
04153 char *pcFile,
04154 char *pcOptions,
04155 int iCopyMode,
04156
04157
04158
04159
04160
04161
04162
04163
04164
04165
04166 char *pcCopyPath,
04167
04168
04169
04170
04171
04172
04173
04174 int iCopyFraction,
04175
04176
04177
04178
04179 int iMaxFile,
04180
04181
04182
04183
04184
04185
04186
04187
04188 int iPathConvention)
04189
04190
04191
04192
04193
04194
04195
04196
04197
04198 {
04199 char cModule[32] = "rfio_fopen_gsidaq";
04200 int iDebug = 0;
04201 int iFileId = -1;
04202
04203 if (iDebug)
04204 printf("\n-D- begin %s: calling rfio_open_gsidaq\n", cModule);
04205
04206 if (*pcOptions == 'r')
04207 {
04208 iFileId = rfio_open_gsidaq(
04209 pcFile, O_RDONLY, 0,
04210 iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
04211 iPathConvention);
04212 }
04213 if (*pcOptions == 'w')
04214 {
04215 iFileId = rfio_open_gsidaq(
04216 pcFile, O_WRONLY | O_CREAT, 0,
04217 iCopyMode, pcCopyPath, iCopyFraction, iMaxFile,
04218 iPathConvention);
04219 }
04220
04221 if (iDebug) printf(
04222 "-D- end %s: iFileId(rfio_open_gsidaq) = %d\n\n",
04223 cModule, iFileId);
04224
04225 if (iFileId < 0)
04226 return NULL;
04227
04228 return pAPIFile[iFileId];
04229
04230 }
04231
04232
04233
04234
04235
04236
04237
04238
04239 int rfio_fnewfile(RFILE *pRemFile,
04240 char *pcFile)
04241 {
04242 char cModule[32] = "rfio_fnewfile";
04243 int iDebug = 0;
04244 int iRC;
04245 int ii;
04246 int iFileId;
04247
04248 if (iDebug)
04249 {
04250 printf("\n-D- begin %s\n", cModule);
04251 fflush(stdout);
04252 }
04253
04254 if (iFileCount <= 0)
04255 {
04256 fprintf(fLogClient, "-E- %s: still no connection to server opened\n",
04257 cModule);
04258 return -1;
04259 }
04260
04261 if (pRemFile == NULL)
04262 {
04263 fprintf(fLogClient, "-E- %s: invalid file ptr (NULL) specified\n", cModule);
04264 return -1;
04265 }
04266
04267 if ( (pcFile == NULL) || (strlen(pcFile) < 5) )
04268 {
04269 fprintf(fLogClient, "-E- %s: invalid file '%s' specified\n",
04270 cModule, pcFile);
04271 return -1;
04272 }
04273
04274 ii = 0;
04275 while (ii < iFileMax)
04276 {
04277 if (pAPIFile[ii] == pRemFile)
04278 break;
04279 ii++;
04280 }
04281
04282 if (ii == iFileMax)
04283 {
04284 fprintf(fLogClient, "-E- %s: invalid file ptr specified\n", cModule);
04285 return -1;
04286 }
04287
04288 iFileId = pRemFile->iFileId;
04289 iRC = rfio_newfile(iFileId, pcFile);
04290
04291 if (iDebug)
04292 printf("-D- end %s\n\n", cModule);
04293
04294 if (iFileId < 0)
04295 return -1;
04296
04297 return iRC;
04298
04299 }
04300
04301
04302
04303
04304
04305
04306
04307
04308 size_t rfio_fread(char *pcBuffer,
04309 size_t iSize,
04310 size_t iItems,
04311 RFILE *pRemFile)
04312 {
04313 char cModule[32]="rfio_fread";
04314 int iDebug = 0;
04315 int iRC;
04316 int iFileId;
04317 size_t iBytes;
04318
04319 if (iDebug)
04320 printf("\n-D- begin %s\n", cModule);
04321
04322 if (pRemFile == NULL)
04323 {
04324 fprintf(fLogClient, "-E- %s: remote file not open for read\n", cModule);
04325 return 0;
04326 }
04327
04328 iFileId = pRemFile->iFileId;
04329 iBytes = iSize*iItems;
04330 iRC = (int) rfio_read(iFileId, pcBuffer, iBytes);
04331
04332 if (iDebug)
04333 printf("-D- end %s\n", cModule);
04334
04335 return (unsigned) iRC;
04336
04337 }
04338
04339
04340
04341
04342
04343
04344
04345
04346 size_t rfio_fwrite(const char *pcBuffer,
04347 size_t iSize,
04348 size_t iItems,
04349 RFILE *pRemFile)
04350 {
04351 char cModule[32]="rfio_fwrite";
04352 int iDebug = 0;
04353 int iFileId;
04354 size_t iBytes;
04355 int iRC;
04356
04357 if (iDebug)
04358 printf("\n-D- begin %s\n", cModule);
04359
04360 if (pRemFile == NULL)
04361 {
04362 fprintf(fLogClient, "-E- %s: remote file not open for write\n", cModule);
04363 return 0;
04364 }
04365
04366 iFileId = pRemFile->iFileId;
04367 iBytes = iSize*iItems;
04368 iRC = (int) rfio_write(iFileId, pcBuffer, iBytes);
04369
04370 if (iDebug)
04371 printf("-D- end %s\n", cModule);
04372
04373 return (unsigned) iRC;
04374
04375 }
04376
04377
04378
04379
04380
04381
04382
04383
04384
04385
04386 int rfio_fendfile(RFILE *pRemFile)
04387 {
04388 char cModule[32] = "rfio_fendfile";
04389 int iDebug = 0;
04390 int iFileId;
04391 int iRC;
04392
04393 if (iDebug)
04394 printf("\n-D- begin %s\n", cModule);
04395
04396 iFileId = pRemFile->iFileId;
04397 iRC = rfio_endfile(iFileId);
04398
04399 if (iDebug)
04400 printf("-D- end %s\n", cModule);
04401
04402 return iRC;
04403
04404 }
04405
04406
04407
04408
04409
04410
04411
04412
04413
04414
04415 int rfio_fclose(RFILE *pRemFile)
04416 {
04417 char cModule[32] = "rfio_fclose";
04418 int iDebug = 0;
04419 int iFileId;
04420 int iRC;
04421
04422 if (iDebug)
04423 printf("\n-D- begin %s\n", cModule);
04424
04425 iFileId = pRemFile->iFileId;
04426 iRC = rfio_close(iFileId);
04427
04428 if (iDebug)
04429 printf("-D- end %s\n", cModule);
04430
04431 return iRC;
04432
04433 }
04434
04435
04436
04437
04438
04439
04440
04441
04442
04443 int rfio_access(const char *pcFile,
04444 int iMode)
04445 {
04446 char cModule[32] = "rfio_access";
04447 int iDebug = 0;
04448 int iRC = 0;
04449
04450 int iFileId = -1;
04451
04452 if (iDebug)
04453 printf("\n-D- begin %s\n", cModule);
04454
04455
04456 if (iMode == X_OK)
04457 {
04458 if (iDebug)
04459 printf(" check if executable - not supported\n");
04460 iRC = 1;
04461 goto gEndAccess;
04462 }
04463
04464 if (iMode == F_OK)
04465 {
04466 if (iDebug)
04467 printf(" check for existence\n");
04468
04469 iFileId = rfio_open(pcFile, O_RDONLY, -1);
04470 if (iFileId >= 0)
04471 {
04472 iRC = rfio_close(iFileId);
04473 if (iRC)
04474 {
04475 printf("-E- closing remote file %s\n", pcFile);
04476 perror(" ");
04477 }
04478 else if (iDebug)
04479 printf("-D- remote file %s closed\n", pcFile);
04480
04481
04482
04483
04484 if (iMode == W_OK)
04485 {
04486 if (iDebug)
04487 printf(" file %s must not be overwritten\n",
04488 pcFile);
04489 iRC = 1;
04490 }
04491 else if (iMode == R_OK)
04492 {
04493 if (iDebug)
04494 printf(" file %s is readable\n", pcFile);
04495 iRC = 0;
04496 }
04497 else
04498 {
04499 if (iDebug)
04500 printf(" file %s exists\n", pcFile);
04501 iRC = 0;
04502 }
04503 }
04504 else
04505 {
04506
04507 if (iMode == W_OK)
04508 {
04509 if (iDebug)
04510 printf(" file %s may be written\n", pcFile);
04511 iRC = 0;
04512 }
04513 else
04514 {
04515 if (iDebug)
04516 printf(" file %s not existing\n", pcFile);
04517 iRC = 1;
04518 }
04519 }
04520 }
04521
04522
04523 if (iMode == R_OK)
04524 {
04525 if (iDebug)
04526 printf(" file %s is readable\n", pcFile);
04527 iRC = 0;
04528 }
04529 if (iMode == W_OK)
04530 {
04531 if (iDebug)
04532 printf(" file %s may be written\n", pcFile);
04533 iRC = 0;
04534 }
04535
04536 gEndAccess:
04537 if (iDebug)
04538 printf("-D- end %s\n", cModule);
04539
04540 return iRC;
04541
04542 }
04543
04544 #ifdef __USE_LARGEFILE64
04545
04546
04547
04548
04549
04550
04551
04552
04553
04554 int rfio_fstat64(int iFileId,
04555 struct stat64 *pStatBuf64)
04556 {
04557 char cModule[32] = "rfio_fstat64";
04558 int iDebug = 0;
04559 int iRC = 0;
04560 int ii;
04561
04562 unsigned long *plFileSizeC;
04563 srawComm *pComm;
04564
04565 if (iDebug)
04566 {
04567 fprintf(fLogClient, "\n-D- begin %s: file %d\n", cModule, iFileId);
04568 if (iFileCount)
04569 fprintf(fLogClient, ", %d remote files currently open\n", iFileCount);
04570 else
04571 fprintf(fLogClient, "\n");
04572 }
04573
04574 ii = sizeof(long);
04575 if (ii < 8)
04576 {
04577 fprintf(fLogClient,
04578 "-E- 32 bit client: %s not supported\n", cModule);
04579
04580 return -1;
04581 }
04582
04583 ii = 0;
04584 if (iFileCount > 0) while (ii <= iFileMax)
04585 {
04586 if (pAPIFile[ii] != NULL)
04587 {
04588 if (pAPIFile[ii]->iFileId == iFileId)
04589 break;
04590 }
04591
04592 ii++;
04593 }
04594
04595 if ( (ii > iFileMax) || (iFileCount == 0) )
04596 {
04597 fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
04598 cModule, iFileId);
04599 if (iDebug)
04600 fprintf(fLogClient, "-D- end %s\n\n", cModule);
04601
04602 return -1;
04603 }
04604
04605 pComm = &(pAPIFile[ii]->sCommAPI);
04606 plFileSizeC = (unsigned long *) &(pComm->iFileSize);
04607
04608 if (iDebug)
04609 {
04610 fprintf(fLogClient, " specified remote fileId %d found:\n", iFileId);
04611 fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
04612 pComm->cNamefs, pComm->cNamehl, pComm->cNamell, *plFileSizeC);
04613 }
04614
04615
04616 iRC = fstat64(0, pStatBuf64);
04617 if (iRC)
04618 {
04619 fprintf(fLogClient, "-E- %s: fstat64() failed, rc = %d\n", cModule, iRC);
04620 if (iDebug)
04621 printf("-D- end %s\n\n", cModule);
04622
04623 return -1;
04624 }
04625
04626
04627 pStatBuf64->st_size = *plFileSizeC;
04628
04629 if (iDebug) fprintf(fLogClient,
04630 "-D- end %s: irc(fstat64) = %d\n", cModule, iRC);
04631
04632 return iRC;
04633
04634 }
04635
04636 #endif
04637
04638
04639
04640
04641
04642
04643
04644
04645
04646 int rfio_fstat(int iFileId,
04647 struct stat *pStatBuf)
04648 {
04649 char cModule[32] = "rfio_fstat";
04650 int iDebug = 0;
04651 int iRC = 0;
04652 int ii = 0;
04653
04654 srawComm *pComm;
04655
04656 if (iDebug)
04657 {
04658 printf("\n-D- begin %s", cModule);
04659 if (iFileCount)
04660 printf(", %d remote files currently open\n", iFileCount);
04661 else
04662 printf("\n");
04663 }
04664
04665 ii = 0;
04666 if (iFileCount > 0) while (ii <= iFileMax)
04667 {
04668 if (pAPIFile[ii] != NULL)
04669 {
04670 if (pAPIFile[ii]->iFileId == iFileId)
04671 break;
04672 }
04673
04674 ii++;
04675 }
04676
04677 if ( (ii > iFileMax) || (iFileCount == 0) )
04678 {
04679 fprintf(fLogClient, "-E- %s: specified remote fileId %d not found\n",
04680 cModule, iFileId);
04681 if (iDebug)
04682 printf("-D- end %s\n\n", cModule);
04683
04684 return -1;
04685 }
04686
04687 pComm = &(pAPIFile[ii]->sCommAPI);
04688 if (iDebug)
04689 {
04690 printf(" specified remote fileId %d found:\n", iFileId);
04691 printf(" object %s%s%s, filesize %u byte\n",
04692 pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
04693 pComm->iFileSize);
04694 }
04695
04696
04697
04698
04699 iRC = fstat(0, pStatBuf);
04700 if (iRC)
04701 {
04702 fprintf(fLogClient, "-E- %s: fstat() failed, rc = %d\n", cModule, iRC);
04703 if (iDebug)
04704 printf("-D- end %s\n\n", cModule);
04705
04706 return -1;
04707 }
04708
04709
04710 pStatBuf->st_size = pComm->iFileSize;
04711
04712 if (iDebug)
04713 printf("-D- end %s\n\n", cModule);
04714
04715 return 0;
04716
04717 }
04718
04719
04720
04721
04722
04723
04724
04725
04726
04727 int rfio_parse(char *pcFile,
04728 char **pcNode,
04729 char **pcPath)
04730 {
04731 char cModule[32] = "rfio_parse";
04732 int iDebug = 0;
04733
04734 if (iDebug)
04735 printf("\n-D- begin %s\n", cModule);
04736
04737 if (iDebug)
04738 printf("-D- end %s\n", cModule);
04739
04740 return 0;
04741
04742 }
04743
04744
04745
04746
04747
04748
04749
04750
04751
04752 void rfio_perror(const char *pUMsg)
04753 {
04754 char cModule[32] = "rfio_perror";
04755 int iDebug = 0;
04756
04757 if (iDebug)
04758 printf("\n-D- begin %s\n", cModule);
04759
04760 if (strlen(rfio_errmsg) == 0)
04761 fprintf(stderr, "%s : No error message\n", pUMsg);
04762 else
04763 fprintf(stderr, "%s : %s\n", pUMsg, rfio_errmsg);
04764
04765 if (iDebug)
04766 printf("-D- end %s\n", cModule);
04767
04768 return;
04769
04770 }
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780 char * rfio_serror()
04781 {
04782 char cModule[32] = "rfio_serror";
04783 int iDebug = 0;
04784
04785 if (iDebug) printf(
04786 "\n-D- begin %s: error (len %d byte):\n",
04787 cModule, (int) strlen(rfio_errmsg));
04788
04789 printf(rfio_errmsg);
04790 fprintf(fLogClient, rfio_errmsg);
04791
04792 if (iDebug)
04793 printf("-D- end %s\n", cModule);
04794
04795 if (strlen(rfio_errmsg) == 0)
04796 return NULL;
04797
04798 return rfio_errmsg;
04799
04800 }
04801
04802
04803
04804
04805
04806
04807
04808
04809 int rfio_unlink(const char *pcFile)
04810 {
04811 char cModule[32] = "rfio_unlink";
04812 int iDebug = 0;
04813
04814 if (iDebug)
04815 printf("\n-D- begin %s\n", cModule);
04816
04817 fprintf(fLogClient,
04818 "-W- %s not yet implemented for gStore\n", cModule);
04819
04820 if (iDebug)
04821 printf("-D- end %s\n", cModule);
04822
04823 return 1;
04824
04825 }
04826
04827
04828
04829
04830
04831
04832
04833
04834 int rfiosetopt(int iopt, int *pival, int ilen)
04835 {
04836 char cModule[32] = "rfiosetopt";
04837 int iDebug = 0;
04838
04839 if (iDebug)
04840 printf("\n-D- begin %s\n", cModule);
04841
04842 if (iDebug)
04843 printf("-D- end %s\n", cModule);
04844
04845 return 0;
04846
04847 }
04848
04849
04850
04851
04852
04853
04854
04855
04856 int rfio_mkdir(const char *path, int mode)
04857 {
04858 char cModule[32] = "rfio_mkdir";
04859 int iDebug = 0;
04860
04861 if (iDebug)
04862 printf("\n-D- begin %s\n", cModule);
04863
04864 fprintf(fLogClient,
04865 "-W- %s not yet implemented for gStore\n", cModule);
04866
04867 if (iDebug)
04868 printf("-D- end %s\n", cModule);
04869
04870 return 0;
04871
04872 }
04873
04874
04875
04876
04877
04878
04879
04880
04881 void *rfio_opendir(const char *dirpath)
04882 {
04883 char cModule[32] = "rfio_opendir";
04884 int iDebug = 0;
04885
04886 if (iDebug)
04887 printf("\n-D- begin %s\n", cModule);
04888
04889 fprintf(fLogClient,
04890 "-W- %s not yet implemented for gStore\n", cModule);
04891
04892 if (iDebug)
04893 printf("-D- end %s\n", cModule);
04894
04895 return 0;
04896
04897 }
04898
04899
04900
04901
04902
04903
04904
04905
04906 void *rfio_readdir(void *dirp)
04907 {
04908 char cModule[32] = "rfio_readdir";
04909 int iDebug = 0;
04910
04911 if (iDebug)
04912 printf("\n-D- begin %s\n", cModule);
04913
04914 fprintf(fLogClient,
04915 "-W- %s not yet implemented for gStore\n", cModule);
04916
04917 if (iDebug)
04918 printf("-D- end %s\n", cModule);
04919
04920 return 0;
04921
04922 }
04923
04924
04925
04926
04927
04928
04929
04930
04931 int rfio_closedir(void *dirp)
04932 {
04933 char cModule[32] = "rfio_closedir";
04934 int iDebug = 0;
04935
04936 if (iDebug)
04937 printf("\n-D- begin %s\n", cModule);
04938
04939 fprintf(fLogClient,
04940 "-W- %s not yet implemented for gStore\n", cModule);
04941
04942 if (iDebug)
04943 printf("-D- end %s\n", cModule);
04944
04945 return 0;
04946
04947 }
04948
04949 #ifdef __USE_LARGEFILE64
04950
04951
04952
04953
04954
04955
04956
04957
04958
04959 int rfio_stat64(const char *pcFile, struct stat64 *pStatBuf64)
04960 {
04961 char cModule[32] = "rfio_stat64";
04962 int iDebug = 0;
04963 int iRC;
04964
04965 int iMapFound = 0;
04966 int iFileId = -1;
04967 int iRC;
04968 int ii;
04969 char *pcc;
04970 char cObject[MAX_FULL_FILE] = "";
04971
04972 srawComm *pComm;
04973 unsigned long *plFileSizeC;
04974
04975 if (iDebug)
04976 fprintf(fLogClient, "\n-D- begin %s: file %s\n", cModule, pcFile);
04977
04978 ii = sizeof(long);
04979 if (ii < 8)
04980 {
04981 fprintf(fLogClient,
04982 "-E- 32 bit client: %s not supported\n", cModule);
04983
04984 return -1;
04985 }
04986
04987 iOnlyQuery = 1;
04988 ii = 0;
04989 if (iFileCount > 0)
04990 while (ii <= iFileMax)
04991 {
04992 if (pAPIFile[ii] != NULL)
04993 {
04994 pComm = &(pAPIFile[ii]->sCommAPI);
04995 strcpy(cObject, pComm->cNamefs);
04996 strcat(cObject, pComm->cNamehl);
04997 strcat(cObject, pComm->cNamell);
04998
04999 if (iDebug) fprintf(fLogClient,
05000 " %d: %s already open\n", ii, cObject);
05001
05002 pcc = strstr(pcFile, cObject);
05003 if (pcc != NULL)
05004 {
05005 iMapFound = 1;
05006 if (iDebug)
05007 fprintf(fLogClient, " %d: %s maps\n", ii, cObject);
05008 break;
05009 }
05010 }
05011 else if (iDebug) fprintf(fLogClient,
05012 " %d: no (more) open file found\n", ii);
05013
05014 ii++;
05015 }
05016
05017 if (iMapFound == 0)
05018 {
05019 if (iDebug) fprintf(fLogClient,
05020 " remote file %s not yet open\n", pcFile);
05021
05022 iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
05023 if (iFileId < 0) fprintf(fLogClient,
05024 "-E- %s: open for remote file %s failed\n", cModule, pcFile);
05025 }
05026 else
05027 {
05028 iFileId = pAPIFile[ii]->iFileId;
05029 if (iFileId < 0) fprintf(fLogClient,
05030 "-E- %s: invalid handle (%d) for remote file %s found\n",
05031 cModule, iFileId, pcFile);
05032 }
05033
05034
05035 if (iFileId >= 0)
05036 {
05037 pComm = &(pAPIFile[ii]->sCommAPI);
05038 plFileSizeC = (unsigned long *) &(pComm->iFileSize);
05039
05040 if (iDebug)
05041 {
05042 fprintf(fLogClient, " remote fileId %d:\n", iFileId);
05043 fprintf(fLogClient, " object %s%s%s, filesize %lu byte\n",
05044 pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
05045 *plFileSizeC);
05046 }
05047
05048
05049 pStatBuf64->st_size = *plFileSizeC;
05050
05051 free(pAPIFile[iFileId]);
05052 pAPIFile[iFileId] = NULL;
05053 iFileCount--;
05054 }
05055
05056
05057 if (iDebug)
05058 fprintf(fLogClient, "-D- end %s\n\n", cModule);
05059
05060 return iRC;
05061
05062 }
05063
05064 #endif
05065
05066
05067
05068
05069
05070
05071
05072
05073
05074 int rfio_stat(const char *pcFile, struct stat *pStatBuf)
05075 {
05076 char cModule[32] = "rfio_stat";
05077 int iDebug = 0;
05078
05079 int iMapFound = 0;
05080 int iFileId = -1;
05081 int iRC;
05082 int ii;
05083 char *pcc;
05084 char cObject[MAX_FULL_FILE] = "";
05085
05086 srawComm *pComm;
05087
05088 if (iDebug)
05089 printf("\n-D- begin %s\n", cModule);
05090
05091 iOnlyQuery = 1;
05092 ii = 0;
05093 if (iFileCount > 0)
05094 while (ii <= iFileMax)
05095 {
05096 if (pAPIFile[ii] != NULL)
05097 {
05098 pComm = &(pAPIFile[ii]->sCommAPI);
05099 strcpy(cObject, pComm->cNamefs);
05100 strcat(cObject, pComm->cNamehl);
05101 strcat(cObject, pComm->cNamell);
05102
05103 if (iDebug)
05104 printf(" %d: %s already open\n", ii, cObject);
05105
05106 pcc = strstr(pcFile, cObject);
05107 if (pcc != NULL)
05108 {
05109 iMapFound = 1;
05110 if (iDebug)
05111 printf(" %d: %s maps\n", ii, cObject);
05112 break;
05113 }
05114 }
05115 else if (iDebug)
05116 printf(" %d: no (more) open file found\n", ii);
05117
05118 ii++;
05119 }
05120
05121 if (iMapFound == 0)
05122 {
05123 if (iDebug) printf(
05124 " remote file %s not yet open\n", pcFile);
05125
05126 iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
05127 if (iFileId < 0) fprintf(fLogClient,
05128 "-E- %s: open for remote file %s failed\n", cModule, pcFile);
05129 }
05130 else
05131 {
05132 iFileId = pAPIFile[ii]->iFileId;
05133 if (iFileId < 0) fprintf(fLogClient,
05134 "-E- %s: invalid handle (%d) for remote file %s found\n",
05135 cModule, iFileId, pcFile);
05136 }
05137
05138
05139 if (iFileId >= 0)
05140 {
05141 pComm = &(pAPIFile[ii]->sCommAPI);
05142 if (iDebug)
05143 {
05144 printf(" remote fileId %d:\n", iFileId);
05145 printf(" object %s%s%s, filesize %ld byte\n",
05146 pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
05147 pComm->iFileSize);
05148 }
05149
05150
05151 pStatBuf->st_size = pComm->iFileSize;
05152
05153 free(pAPIFile[iFileId]);
05154 pAPIFile[iFileId] = NULL;
05155 iFileCount--;
05156 }
05157
05158 if (iDebug)
05159 printf("-D- end %s\n\n", cModule);
05160
05161 if (iFileId >= 0)
05162 return 0;
05163 else
05164 return iFileId;
05165
05166 }
05167
05168
05169
05170
05171
05172
05173
05174
05175
05176
05177
05178
05179
05180
05181
05182
05183 int rfio_cache_stat(const char *pcFile)
05184 {
05185 char cModule[32] = "rfio_cache_stat";
05186 int iDebug = 0;
05187
05188 int iMapFound = 0;
05189 int iFileId = -1;
05190 int iRC;
05191 int iCache = 0;
05192 int ii;
05193 char *pcc;
05194 char cObject[MAX_FULL_FILE] = "";
05195
05196 srawComm *pComm;
05197
05198 if (iDebug)
05199 {
05200 printf("\n-D- begin %s: %d files open\n", cModule, iFileCount);
05201 printf(" get cache status of file %s\n", pcFile);
05202 }
05203
05204 iOnlyQuery = 1;
05205 ii = 0;
05206 if (iFileCount > 0)
05207 while (ii <= iFileMax)
05208 {
05209 if (pAPIFile[ii] != NULL)
05210 {
05211 pComm = &(pAPIFile[ii]->sCommAPI);
05212 strcpy(cObject, pComm->cNamefs);
05213 strcat(cObject, pComm->cNamehl);
05214 strcat(cObject, pComm->cNamell);
05215
05216 if (iDebug)
05217 printf(" %d: %s already open\n", ii, cObject);
05218
05219 pcc = strstr(pcFile, cObject);
05220 if (pcc != NULL)
05221 {
05222 iMapFound = 1;
05223 if (iDebug)
05224 printf(" %d: %s maps\n", ii, cObject);
05225 break;
05226 }
05227 }
05228 else if (iDebug)
05229 printf(" %d: no (more) open file found\n", ii);
05230
05231 ii++;
05232 }
05233
05234 if (iMapFound == 0)
05235 {
05236 if (iDebug) printf(
05237 " remote file %s not yet open\n", pcFile);
05238
05239 iFileId = rfio_open( (char *) pcFile, O_RDONLY, -1);
05240 if (iFileId < 0)
05241 {
05242 fprintf(fLogClient,
05243 "-E- remote file %s not in gStore or unavailable\n",
05244 pcFile);
05245
05246 iCache = -1;
05247 goto gEndCacheStat;
05248 }
05249
05250 if (iDebug) printf(
05251 " remote file %s successfully opened for query and closed\n", pcFile);
05252 }
05253 else
05254 {
05255 iFileId = pAPIFile[ii]->iFileId;
05256 if (iFileId < 0)
05257 {
05258 fprintf(fLogClient,
05259 "-E- %s: invalid handle (%d) for remote file %s found\n",
05260 cModule, iFileId, pcFile);
05261
05262 iCache = -1;
05263 goto gEndCacheStat;
05264 }
05265 }
05266
05267
05268 if (iFileId >= 0)
05269 {
05270 pComm = &(pAPIFile[ii]->sCommAPI);
05271 if (pComm->iStageFSid > 0)
05272 iCache = 1;
05273 else if (pComm->iFSidWC > 0)
05274 iCache = 2;
05275 else
05276 iCache = 0;
05277
05278 if (iDebug)
05279 {
05280 printf(" remote fileId %d:\n", iFileId);
05281 printf(" object %s%s%s, size %ld byte, cache status %d\n",
05282 pComm->cNamefs, pComm->cNamehl, pComm->cNamell,
05283 pComm->iFileSize, iCache);
05284 if (pComm->iStageFSid > 0)
05285 printf(" read cache FS %d\n", pComm->iStageFSid);
05286 else if (pComm->iFSidWC > 0)
05287 printf(" write cache FS %d\n", pComm->iFSidWC);
05288 }
05289
05290 free(pAPIFile[iFileId]);
05291 pAPIFile[iFileId] = NULL;
05292 iFileCount--;
05293 }
05294
05295 gEndCacheStat:
05296 iOnlyQuery = 0;
05297 if (iDebug)
05298 printf("-D- end %s\n\n", cModule);
05299
05300 return iCache;
05301
05302 }
05303
05304
05305
05306
05307
05308
05309
05310
05311 int rfio_gsi_query(int iFileId,
05312 int iFull,
05313 int iOut,
05314 char *pInfo)
05315 {
05316 char cModule[32] = "rfio_gsi_query";
05317 int iDebug = 0;
05318 int iRC = 0;
05319 int ii = 0;
05320
05321 srawAPIFile *pcurAPIFile;
05322 srawObjAttr *pQueryAPI;
05323
05324 if (iDebug)
05325 printf("\n-D- begin %s\n", cModule);
05326
05327 if (iFileCount == 0)
05328 {
05329 printf("-E- %s: no remote file available\n", cModule);
05330 iRC = -1;
05331 goto gEndQuery;
05332 }
05333
05334 while (ii < iFileMax)
05335 {
05336 if (pAPIFile[ii])
05337 {
05338 if (pAPIFile[ii]->iFileId == iFileId)
05339 break;
05340 }
05341 ii++;
05342 }
05343
05344 if (ii == iFileMax)
05345 {
05346 printf("-E- %s: remote file %d not found\n", cModule, iFileId);
05347 iRC = -1;
05348 goto gEndQuery;
05349 }
05350
05351 pcurAPIFile = pAPIFile[iFileId];
05352 pQueryAPI = &(pcurAPIFile->sQueryAPI);
05353 iRC = rawQueryString(pQueryAPI, iFull, iOut, pInfo);
05354 if (iDebug)
05355 {
05356 printf(" %s\n", pInfo);
05357 if (iRC != iOut) printf(
05358 " (used %d byte, avail %d byte)\n", iRC, iOut);
05359 }
05360
05361 gEndQuery:
05362 if (iDebug)
05363 printf("-D- end %s\n\n", cModule);
05364
05365 return iRC;
05366
05367 }
05368