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
00041 #include "Xrd/XrdObject.hh"
00042 #include "Xrd/XrdProtocol.hh"
00043 #include "XrdXrootd/XrdXrootdMonitor.hh"
00044 #include "XrdXrootd/XrdXrootdReqID.hh"
00045 #include "XrdXrootd/XrdXrootdResponse.hh"
00046 #include "XProtocol/XProtocol.hh"
00047
00048
00049
00050
00051
00052 #define ROOTD_PQ 2012
00053
00054 #define XRD_LOGGEDIN 1
00055 #define XRD_NEED_AUTH 2
00056 #define XRD_ADMINUSER 4
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 XrdSfsFileSystem;
00079 class XrdSecProtocol;
00080 class XrdBuffer;
00081 class XrdLink;
00082 class XrdXrootdAioReq;
00083 class XrdXrootdFile;
00084 class XrdXrootdFileLock;
00085 class XrdXrootdFileTable;
00086 class XrdXrootdJob;
00087 class XrdXrootdMonitor;
00088 class XrdXrootdPio;
00089 class XrdXrootdStats;
00090 class XrdXrootdWVInfo;
00091 class XrdXrootdXPath;
00092
00093 class XrdXrootdProtocol : public XrdProtocol, public XrdSfsDio
00094 {
00095 friend class XrdXrootdAdmin;
00096 friend class XrdXrootdAioReq;
00097 public:
00098
00099 static int Configure(char *parms, XrdProtocol_Config *pi);
00100
00101 void DoIt() {(*this.*Resume)();}
00102
00103 int do_WriteSpan();
00104
00105 XrdProtocol *Match(XrdLink *lp);
00106
00107 int Process(XrdLink *lp);
00108
00109 int Process2();
00110
00111 int ProcSig();
00112
00113 void Recycle(XrdLink *lp, int consec, const char *reason);
00114
00115 int SendFile(int fildes);
00116
00117 int SendFile(XrdOucSFVec *sfvec, int sfvnum);
00118
00119 void SetFD(int fildes);
00120
00121 int Stats(char *buff, int blen, int do_sync=0);
00122
00123 static int StatGen(struct stat &buf, char *xxBuff);
00124
00125
00126 XrdXrootdProtocol& operator =(const XrdXrootdProtocol &rhs);
00127 XrdXrootdProtocol();
00128 ~XrdXrootdProtocol() {Cleanup();}
00129
00130 private:
00131
00132
00133
00134 enum RD_func {RD_chmod = 0, RD_chksum, RD_dirlist, RD_locate, RD_mkdir,
00135 RD_mv, RD_prepare, RD_prepstg, RD_rm, RD_rmdir,
00136 RD_stat, RD_trunc, RD_ovld,
00137 RD_open1, RD_open2, RD_open3, RD_open4, RD_Num};
00138
00139 int do_Admin();
00140 int do_Auth();
00141 int do_Bind();
00142 int do_Chmod();
00143 int do_CKsum(int canit);
00144 int do_CKsum(char *algT, const char *Path, char *Opaque);
00145 int do_Close();
00146 int do_Dirlist();
00147 int do_DirStat(XrdSfsDirectory *dp, char *pbuff, char *opaque);
00148 int do_Endsess();
00149 int do_Getfile();
00150 int do_Login();
00151 int do_Locate();
00152 int do_Mkdir();
00153 int do_Mv();
00154 int do_Offload(int pathID, int isRead);
00155 int do_OffloadIO();
00156 int do_Open();
00157 int do_Ping();
00158 int do_Prepare(bool isQuery=false);
00159 int do_Protocol(ServerResponseBody_Protocol *rsp=0);
00160 int do_Putfile();
00161 int do_Qconf();
00162 int do_Qfh();
00163 int do_Qopaque(short);
00164 int do_Qspace();
00165 int do_Query();
00166 int do_Qxattr();
00167 int do_Read();
00168 int do_ReadV();
00169 int do_ReadAll(int asyncOK=1);
00170 int do_ReadNone(int &retc, int &pathID);
00171 int do_Rm();
00172 int do_Rmdir();
00173 int do_Set();
00174 int do_Set_Mon(XrdOucTokenizer &setargs);
00175 int do_Stat();
00176 int do_Statx();
00177 int do_Sync();
00178 int do_Truncate();
00179 int do_Write();
00180 int do_WriteAll();
00181 int do_WriteCont();
00182 int do_WriteNone();
00183 int do_WriteV();
00184 int do_WriteVec();
00185
00186 int aio_Error(const char *op, int ecode);
00187 int aio_Read();
00188 int aio_Write();
00189 int aio_WriteAll();
00190 int aio_WriteCont();
00191
00192 void Assign(const XrdXrootdProtocol &rhs);
00193 static int CheckSum(XrdOucStream *, char **, int);
00194 void Cleanup();
00195 static int Config(const char *fn);
00196 static int ConfigSecurity(XrdOucEnv &xEnv, const char *cfn);
00197 int fsError(int rc, char opc, XrdOucErrInfo &myError,
00198 const char *Path, char *Cgi);
00199 int fsOvrld(char opc, const char *Path, char *Cgi);
00200 int fsRedirNoEnt(const char *eMsg, char *Cgi, int popt);
00201 int getBuff(const int isRead, int Quantum);
00202 int getData(const char *dtype, char *buff, int blen);
00203 void logLogin(bool xauth=false);
00204 static int mapMode(int mode);
00205 static void PidFile();
00206 void Reset();
00207 static int rpCheck(char *fn, char **opaque);
00208 int rpEmsg(const char *op, char *fn);
00209 int vpEmsg(const char *op, char *fn);
00210 static int Squash(char *);
00211 static int xapath(XrdOucStream &Config);
00212 static int xasync(XrdOucStream &Config);
00213 static int xcksum(XrdOucStream &Config);
00214 static int xdig(XrdOucStream &Config);
00215 static int xexp(XrdOucStream &Config);
00216 static int xexpdo(char *path, int popt=0);
00217 static int xfsl(XrdOucStream &Config);
00218 static int xfsL(XrdOucStream &Config, char *val, int lix);
00219 static int xfso(XrdOucStream &Config);
00220 static int xpidf(XrdOucStream &Config);
00221 static int xprep(XrdOucStream &Config);
00222 static int xlog(XrdOucStream &Config);
00223 static int xmon(XrdOucStream &Config);
00224 static int xred(XrdOucStream &Config);
00225 static bool xred_php(char *val, char *hP[2], int rPort[2]);
00226 static void xred_set(RD_func func, char *rHost[2], int rPort[2]);
00227 static bool xred_xok(int func, char *rHost[2], int rPort[2]);
00228 static int xsecl(XrdOucStream &Config);
00229 static int xtrace(XrdOucStream &Config);
00230 static int xlimit(XrdOucStream &Config);
00231
00232 static XrdObjectQ<XrdXrootdProtocol> ProtStack;
00233 XrdObject<XrdXrootdProtocol> ProtLink;
00234
00235 protected:
00236
00237 void MonAuth();
00238 int SetSF(kXR_char *fhandle, bool seton=false);
00239
00240 static XrdXrootdXPath RPList;
00241 static XrdXrootdXPath RQList;
00242 static XrdXrootdXPath XPList;
00243 static XrdSfsFileSystem *osFS;
00244 static XrdSfsFileSystem *digFS;
00245 static XrdSecService *CIA;
00246 static XrdSecProtector *DHS;
00247 static XrdXrootdFileLock *Locker;
00248 static XrdScheduler *Sched;
00249 static XrdBuffManager *BPool;
00250 static XrdSysError eDest;
00251 static const char *myInst;
00252 static const char *TraceID;
00253 static char *pidPath;
00254 static int RQLxist;
00255 static int myPID;
00256 static int myRole;
00257 static int myRolf;
00258
00259
00260
00261 static XrdNetSocket *AdminSock;
00262
00263
00264
00265 static int hailWait;
00266 static int readWait;
00267 static int Port;
00268 static int Window;
00269 static int WANPort;
00270 static int WANWindow;
00271 static char *SecLib;
00272 static char *FSLib[2];
00273 static int FSLvn[2];
00274 static char *digLib;
00275 static char *digParm;
00276 static char *Notify;
00277 static const char *myCName;
00278 static int myCNlen;
00279 static char isRedir;
00280 static char JobLCL;
00281 static char JobCKCGI;
00282 static XrdXrootdJob *JobCKS;
00283 static char *JobCKT;
00284 static XrdOucTList *JobCKTLST;
00285 static XrdOucReqID *PrepID;
00286
00287
00288
00289 static struct RD_Table {char *Host[2];
00290 unsigned short Port[2];
00291 short RDSz[2];} Route[RD_Num];
00292 static int OD_Stall;
00293 static bool OD_Bypass;
00294 static bool OD_Redir;
00295
00296
00297
00298 static int as_maxperlnk;
00299 static int as_maxperreq;
00300 static int as_maxpersrv;
00301 static int as_miniosz;
00302 static int as_minsfsz;
00303 static int as_segsize;
00304 static int as_maxstalls;
00305 static int as_force;
00306 static int as_noaio;
00307 static int as_nosf;
00308 static int as_syncw;
00309 static int maxBuffsz;
00310 static int maxTransz;
00311 static const int maxRvecsz = 1024;
00312 static const int maxWvecsz = 1024;
00313
00314
00315
00316 static XrdXrootdStats *SI;
00317 int numReads;
00318 int numReadP;
00319 int numReadV;
00320 int numSegsV;
00321 int numWritV;
00322 int numSegsW;
00323 int numWrites;
00324 int numFiles;
00325
00326 int cumReads;
00327 int cumReadP;
00328 int cumReadV;
00329 int cumSegsV;
00330 int cumWritV;
00331 int cumSegsW;
00332 int cumWrites;
00333 long long totReadP;
00334
00335
00336
00337 XrdLink *Link;
00338 XrdBuffer *argp;
00339 XrdXrootdFileTable *FTab;
00340 XrdXrootdMonitor::User Monitor;
00341 int clientPV;
00342 int clientRN;
00343 int reserved;
00344 short rdType;
00345 char Status;
00346 unsigned char CapVer;
00347
00348
00349
00350 XrdSecEntity *Client;
00351 XrdSecProtocol *AuthProt;
00352 XrdSecEntity Entity;
00353 XrdSecProtect *Protect;
00354
00355 ClientRequest sigReq2Ver;
00356 SecurityRequest sigReq;
00357 char sigBuff[64];
00358 bool sigNeed;
00359 bool sigHere;
00360 bool sigRead;
00361 bool sigWarn;
00362
00363
00364
00365 XrdXrootdAioReq *myAioReq;
00366 char *myBuff;
00367 int myBlen;
00368 int myBlast;
00369 int (XrdXrootdProtocol::*Resume)();
00370 XrdXrootdFile *myFile;
00371 XrdXrootdWVInfo *wvInfo;
00372 union {
00373 long long myOffset;
00374 long long myWVBytes;
00375 int myEInfo[2];
00376 };
00377 int myIOLen;
00378 int myStalls;
00379
00380
00381
00382 static int hcMax;
00383 int hcPrev;
00384 int hcNext;
00385 int hcNow;
00386 int halfBSize;
00387
00388
00389
00390 static const int maxStreams = 16;
00391 XrdSysMutex streamMutex;
00392 XrdSysSemaphore *reTry;
00393 XrdXrootdProtocol *Stream[maxStreams];
00394 unsigned int mySID;
00395 char isActive;
00396 char isDead;
00397 char isBound;
00398 char isNOP;
00399
00400 static const int maxPio = 4;
00401 XrdXrootdPio *pioFirst;
00402 XrdXrootdPio *pioLast;
00403 XrdXrootdPio *pioFree;
00404
00405 short PathID;
00406 char doWrite;
00407 char doWriteC;
00408 unsigned char rvSeq;
00409 unsigned char wvSeq;
00410
00411
00412
00413 static bool PrepareAlt;
00414 static bool LimitError;
00415
00416 int PrepareCount;
00417 static int PrepareLimit;
00418
00419
00420
00421 XrdXrootdReqID ReqID;
00422 ClientRequest Request;
00423 XrdXrootdResponse Response;
00424 };
00425 #endif