00001 #ifndef __XROOTD_PROTOCOL_H__
00002 #define __XROOTD_PROTOCOL_H__
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 #include <stdlib.h>
00033 #include <unistd.h>
00034 #include <sys/types.h>
00035
00036 #include "XrdSys/XrdSysError.hh"
00037 #include "XrdSys/XrdSysPthread.hh"
00038 #include "XrdSec/XrdSecInterface.hh"
00039 #include "XrdSfs/XrdSfsDio.hh"
00040 #include "XrdSfs/XrdSfsXioImpl.hh"
00041
00042 #include "Xrd/XrdObject.hh"
00043 #include "Xrd/XrdProtocol.hh"
00044 #include "XrdXrootd/XrdXrootdMonitor.hh"
00045 #include "XrdXrootd/XrdXrootdReqID.hh"
00046 #include "XrdXrootd/XrdXrootdResponse.hh"
00047 #include "XProtocol/XProtocol.hh"
00048
00049
00050
00051
00052
00053 #define ROOTD_PQ 2012
00054
00055 #define XRD_LOGGEDIN 1
00056 #define XRD_NEED_AUTH 2
00057 #define XRD_BOUNDPATH 8
00058
00059 #ifndef __GNUC__
00060 #define __attribute__(x)
00061 #endif
00062
00063
00064
00065
00066
00067 class XrdNetSocket;
00068 class XrdOucEnv;
00069 class XrdOucErrInfo;
00070 class XrdOucReqID;
00071 class XrdOucStream;
00072 class XrdOucTList;
00073 class XrdOucTokenizer;
00074 class XrdOucTrace;
00075 class XrdSecProtect;
00076 class XrdSecProtector;
00077 class XrdSfsDirectory;
00078 class XrdSfsFACtl;
00079 class XrdSfsFileSystem;
00080 class XrdSecProtocol;
00081 class XrdBuffer;
00082 class XrdLink;
00083 class XrdTlsContext;
00084 class XrdXrootdAioReq;
00085 class XrdXrootdFile;
00086 class XrdXrootdFileLock;
00087 class XrdXrootdFileTable;
00088 class XrdXrootdJob;
00089 class XrdXrootdMonitor;
00090 class XrdXrootdPio;
00091 class XrdXrootdStats;
00092 class XrdXrootdWVInfo;
00093 class XrdXrootdXPath;
00094
00095 class XrdXrootdProtocol : public XrdProtocol, public XrdSfsDio, public XrdSfsXio
00096 {
00097 friend class XrdXrootdAdmin;
00098 friend class XrdXrootdAioReq;
00099 public:
00100
00101 static char *Buffer(XrdSfsXioHandle h, int *bsz);
00102
00103 XrdSfsXioHandle Claim(const char *buff, int datasz, int minasz=0);
00104
00105 static int Configure(char *parms, XrdProtocol_Config *pi);
00106
00107 void DoIt() {(*this.*Resume)();}
00108
00109 int do_WriteSpan();
00110
00111 XrdProtocol *Match(XrdLink *lp);
00112
00113 int Process(XrdLink *lp);
00114
00115 int Process2();
00116
00117 int ProcSig();
00118
00119 void Recycle(XrdLink *lp, int consec, const char *reason);
00120
00121 static void Reclaim(XrdSfsXioHandle h);
00122
00123 int SendFile(int fildes);
00124
00125 int SendFile(XrdOucSFVec *sfvec, int sfvnum);
00126
00127 void SetFD(int fildes);
00128
00129 int Stats(char *buff, int blen, int do_sync=0);
00130
00131 XrdSfsXioHandle Swap(const char *buff, XrdSfsXioHandle h=0);
00132
00133 XrdXrootdProtocol operator =(const XrdXrootdProtocol &rhs) = delete;
00134 XrdXrootdProtocol();
00135 ~XrdXrootdProtocol() {Cleanup();}
00136
00137 private:
00138
00139
00140
00141 enum RD_func {RD_chmod = 0, RD_chksum, RD_dirlist, RD_locate, RD_mkdir,
00142 RD_mv, RD_prepare, RD_prepstg, RD_rm, RD_rmdir,
00143 RD_stat, RD_trunc, RD_ovld,
00144 RD_open1, RD_open2, RD_open3, RD_open4, RD_Num};
00145
00146 int do_Auth();
00147 int do_Bind();
00148 int do_Chmod();
00149 int do_CKsum(int canit);
00150 int do_CKsum(char *algT, const char *Path, char *Opaque);
00151 int do_Close();
00152 int do_Dirlist();
00153 int do_DirStat(XrdSfsDirectory *dp, char *pbuff, char *opaque);
00154 int do_Endsess();
00155 int do_FAttr();
00156 int do_gpFile();
00157 int do_Login();
00158 int do_Locate();
00159 int do_Mkdir();
00160 int do_Mv();
00161 int do_Offload(int pathID, bool isWrite, bool ispgio=false);
00162 int do_OffloadIO();
00163 int do_Open();
00164 int do_PgRead();
00165 int do_PgRIO();
00166 int do_PgWrite();
00167 int do_PgWIO();
00168 int do_Ping();
00169 int do_Prepare(bool isQuery=false);
00170 int do_Protocol();
00171 int do_Qconf();
00172 int do_QconfCX(XrdOucTokenizer &qcargs, char *val);
00173 int do_Qfh();
00174 int do_Qopaque(short);
00175 int do_Qspace();
00176 int do_Query();
00177 int do_Qxattr();
00178 int do_Read();
00179 int do_ReadV();
00180 int do_ReadAll(int asyncOK=1);
00181 int do_ReadNone(int &retc, int &pathID);
00182 int do_Rm();
00183 int do_Rmdir();
00184 int do_Set();
00185 int do_Set_Mon(XrdOucTokenizer &setargs);
00186 int do_Stat();
00187 int do_Statx();
00188 int do_Sync();
00189 int do_Truncate();
00190 int do_Write();
00191 int do_WriteAll();
00192 int do_WriteCont();
00193 int do_WriteNone();
00194 int do_WriteV();
00195 int do_WriteVec();
00196
00197 int aio_Error(const char *op, int ecode);
00198 int aio_Read();
00199 int aio_Write();
00200 int aio_WriteAll();
00201 int aio_WriteCont();
00202
00203 void Assign(const XrdXrootdProtocol &rhs);
00204 static int CheckSum(XrdOucStream *, char **, int);
00205 void Cleanup();
00206 static int Config(const char *fn);
00207 static int ConfigSecurity(XrdOucEnv &xEnv, const char *cfn);
00208 int fsError(int rc, char opc, XrdOucErrInfo &myError,
00209 const char *Path, char *Cgi);
00210 int fsOvrld(char opc, const char *Path, char *Cgi);
00211 int fsRedirNoEnt(const char *eMsg, char *Cgi, int popt);
00212 int getBuff(const int isRead, int Quantum);
00213 int getData(const char *dtype, char *buff, int blen);
00214 int getPathID(bool isRead);
00215 bool logLogin(bool xauth=false);
00216 static int mapMode(int mode);
00217 void Reset();
00218 static int rpCheck(char *fn, char **opaque);
00219 int rpEmsg(const char *op, char *fn);
00220 int vpEmsg(const char *op, char *fn);
00221 static int CheckTLS(const char *tlsProt);
00222 static bool ConfigFS(XrdOucEnv &xEnv, const char *cfn);
00223 static bool ConfigFS(const char *path, XrdOucEnv &xEnv, const char *cfn);
00224 static void ConfigGStream(XrdOucEnv &myEnv, XrdOucEnv *urEnv);
00225 static int Squash(char *);
00226 int StatGen(struct stat &buf, char *xxBuff, int xxLen, bool xa=false);
00227 static int xapath(XrdOucStream &Config);
00228 static int xasync(XrdOucStream &Config);
00229 static int xcksum(XrdOucStream &Config);
00230 static int xdig(XrdOucStream &Config);
00231 static int xexp(XrdOucStream &Config);
00232 static int xexpdo(char *path, int popt=0);
00233 static int xfsl(XrdOucStream &Config);
00234 static int xfsL(XrdOucStream &Config, char *val, int lix);
00235 static int xfso(XrdOucStream &Config);
00236 static int xgpf(XrdOucStream &Config);
00237 static int xprep(XrdOucStream &Config);
00238 static int xlog(XrdOucStream &Config);
00239 static int xmon(XrdOucStream &Config);
00240 static int xred(XrdOucStream &Config);
00241 static bool xred_php(char *val, char *hP[2], int rPort[2]);
00242 static void xred_set(RD_func func, char *rHost[2], int rPort[2]);
00243 static bool xred_xok(int func, char *rHost[2], int rPort[2]);
00244 static int xsecl(XrdOucStream &Config);
00245 static int xtls(XrdOucStream &Config);
00246 static int xtlsr(XrdOucStream &Config);
00247 static int xtrace(XrdOucStream &Config);
00248 static int xlimit(XrdOucStream &Config);
00249
00250 int ProcFAttr(char *faPath, char *faCgi, char *faArgs,
00251 int faALen, int faCode, bool doAChk);
00252 int XeqFADel(XrdSfsFACtl &ctl, char *faVars, int faVLen);
00253 int XeqFAGet(XrdSfsFACtl &ctl, char *faVars, int faVLen);
00254 int XeqFALsd(XrdSfsFACtl &ctl);
00255 int XeqFALst(XrdSfsFACtl &ctl);
00256 int XeqFASet(XrdSfsFACtl &ctl, char *faVars, int faVLen);
00257
00258 static XrdObjectQ<XrdXrootdProtocol> ProtStack;
00259 XrdObject<XrdXrootdProtocol> ProtLink;
00260
00261 protected:
00262
00263 static unsigned int getSID();
00264
00265 void MonAuth();
00266 int SetSF(kXR_char *fhandle, bool seton=false);
00267
00268 static XrdXrootdXPath RPList;
00269 static XrdXrootdXPath RQList;
00270 static XrdXrootdXPath XPList;
00271 static XrdSfsFileSystem *osFS;
00272 static XrdSfsFileSystem *digFS;
00273 static XrdSecService *CIA;
00274 static XrdSecProtector *DHS;
00275 static XrdTlsContext *tlsCtx;
00276 static XrdXrootdFileLock *Locker;
00277 static XrdScheduler *Sched;
00278 static XrdBuffManager *BPool;
00279 static XrdSysError eDest;
00280 static const char *myInst;
00281 static const char *TraceID;
00282 static int RQLxist;
00283 static int myPID;
00284 static int myRole;
00285 static int myRolf;
00286
00287 static gid_t myGID;
00288 static uid_t myUID;
00289 static int myGNLen;
00290 static int myUNLen;
00291 static const char *myGName;
00292 static const char *myUName;
00293 static time_t keepT;
00294
00295
00296
00297 static XrdNetSocket *AdminSock;
00298
00299
00300
00301 static int hailWait;
00302 static int readWait;
00303 static int Port;
00304 static int Window;
00305 static int tlsPort;
00306 static char *Notify;
00307 static const char *myCName;
00308 static int myCNlen;
00309 static char isRedir;
00310 static char JobLCL;
00311 static char JobCKCGI;
00312 static XrdXrootdJob *JobCKS;
00313 static char *JobCKT;
00314 static XrdOucTList *JobCKTLST;
00315 static XrdOucReqID *PrepID;
00316 static uint64_t fsFeatures;
00317
00318
00319
00320 static struct RD_Table {char *Host[2];
00321 unsigned short Port[2];
00322 short RDSz[2];} Route[RD_Num];
00323 static int OD_Stall;
00324 static bool OD_Bypass;
00325 static bool OD_Redir;
00326
00327
00328
00329 static int usxMaxNsz;
00330 static int usxMaxVsz;
00331 static char *usxParms;
00332
00333 static const char Req_TLSData = 0x01;
00334 static const char Req_TLSGPFile= 0x02;
00335 static const char Req_TLSLogin = 0x04;
00336 static const char Req_TLSSess = 0x08;
00337 static const char Req_TLSTPC = 0x10;
00338
00339 static char tlsCap;
00340 static char tlsNot;
00341
00342
00343
00344 static int as_maxperlnk;
00345 static int as_maxperreq;
00346 static int as_maxpersrv;
00347 static int as_miniosz;
00348 static int as_minsfsz;
00349 static int as_segsize;
00350 static int as_maxstalls;
00351 static int as_force;
00352 static int as_noaio;
00353 static int as_nosf;
00354 static int as_syncw;
00355 static int maxBuffsz;
00356 static int maxTransz;
00357 static const int maxRvecsz = 1024;
00358 static const int maxWvecsz = 1024;
00359
00360
00361
00362 static XrdXrootdStats *SI;
00363 int numReads;
00364 int numReadP;
00365 int numReadV;
00366 int numSegsV;
00367 int numWritV;
00368 int numSegsW;
00369 int numWrites;
00370 int numFiles;
00371
00372 int cumReads;
00373 int cumReadP;
00374 int cumReadV;
00375 int cumSegsV;
00376 int cumWritV;
00377 int cumSegsW;
00378 int cumWrites;
00379 long long totReadP;
00380
00381
00382
00383 XrdLink *Link;
00384 XrdBuffer *argp;
00385 XrdXrootdFileTable *FTab;
00386 XrdXrootdMonitor::User Monitor;
00387 int clientPV;
00388 int clientRN;
00389 int reserved;
00390 short rdType;
00391 char Status;
00392 unsigned char CapVer;
00393
00394
00395
00396 XrdSecEntity *Client;
00397 XrdSecProtocol *AuthProt;
00398 XrdSecEntity Entity;
00399 XrdSecProtect *Protect;
00400 char *AppName;
00401
00402 ClientRequest sigReq2Ver;
00403 SecurityRequest sigReq;
00404 char sigBuff[64];
00405 bool sigNeed;
00406 bool sigHere;
00407 bool sigRead;
00408 bool sigWarn;
00409
00410
00411
00412 XrdXrootdAioReq *myAioReq;
00413 char *myBuff;
00414 int myBlen;
00415 int myBlast;
00416 int (XrdXrootdProtocol::*Resume)();
00417 XrdXrootdFile *myFile;
00418 XrdXrootdWVInfo *wvInfo;
00419 union {
00420 long long myOffset;
00421 long long myWVBytes;
00422 int myEInfo[2];
00423 };
00424 int myIOLen;
00425 int myStalls;
00426
00427
00428
00429 static int hcMax;
00430 int hcPrev;
00431 int hcNext;
00432 int hcNow;
00433 int halfBSize;
00434
00435
00436
00437 static const int maxStreams = 16;
00438 XrdSysMutex streamMutex;
00439 XrdSysSemaphore *reTry;
00440 XrdXrootdProtocol *Stream[maxStreams];
00441 unsigned int mySID;
00442 bool isActive;
00443 bool isDead;
00444 bool isBound;
00445 bool isNOP;
00446
00447 static const int maxPio = 4;
00448 XrdXrootdPio *pioFirst;
00449 XrdXrootdPio *pioLast;
00450 XrdXrootdPio *pioFree;
00451 long long bytes2recv;
00452 long long bytes2send;
00453
00454 short PathID;
00455 unsigned short myFlags;
00456 bool doPgIO;
00457 bool doWrite;
00458 bool doWriteC;
00459 unsigned char rvSeq;
00460 unsigned char wvSeq;
00461
00462 char doTLS;
00463 bool ableTLS;
00464 bool isTLS;
00465
00466
00467
00468 static bool PrepareAlt;
00469 static bool LimitError;
00470
00471 int PrepareCount;
00472 static int PrepareLimit;
00473
00474
00475
00476 XrdXrootdReqID ReqID;
00477 ClientRequest Request;
00478 XrdXrootdResponse Response;
00479 };
00480 #endif