|
xrootd
|
00001 #ifndef __XROOTD_PROTOCOL_H__ 00002 #define __XROOTD_PROTOCOL_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d X r o o t d P r o t o c o l . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00010 /******************************************************************************/ 00011 00012 #include <stdlib.h> 00013 #include <unistd.h> 00014 #include <sys/types.h> 00015 00016 #include "XrdSys/XrdSysError.hh" 00017 #include "XrdSys/XrdSysPthread.hh" 00018 #include "XrdSec/XrdSecInterface.hh" 00019 00020 #include "Xrd/XrdObject.hh" 00021 #include "Xrd/XrdProtocol.hh" 00022 #include "XrdXrootd/XrdXrootdReqID.hh" 00023 #include "XrdXrootd/XrdXrootdResponse.hh" 00024 #include "XProtocol/XProtocol.hh" 00025 00026 /******************************************************************************/ 00027 /* D e f i n e s */ 00028 /******************************************************************************/ 00029 00030 #define ROOTD_PQ 2012 00031 00032 #define XRD_LOGGEDIN 1 00033 #define XRD_NEED_AUTH 2 00034 #define XRD_ADMINUSER 4 00035 #define XRD_BOUNDPATH 8 00036 00037 #ifndef __GNUC__ 00038 #define __attribute__(x) 00039 #endif 00040 00041 /******************************************************************************/ 00042 /* x r d _ P r o t o c o l _ X R o o t d */ 00043 /******************************************************************************/ 00044 00045 class XrdNetSocket; 00046 class XrdOucErrInfo; 00047 class XrdOucStream; 00048 class XrdOucTokenizer; 00049 class XrdOucTrace; 00050 class XrdSfsFileSystem; 00051 class XrdSecProtocol; 00052 class XrdBuffer; 00053 class XrdLink; 00054 class XrdXrootdAioReq; 00055 class XrdXrootdFile; 00056 class XrdXrootdFileLock; 00057 class XrdXrootdFileTable; 00058 class XrdXrootdJob; 00059 class XrdXrootdMonitor; 00060 class XrdXrootdPio; 00061 class XrdXrootdStats; 00062 class XrdXrootdXPath; 00063 00064 class XrdXrootdProtocol : public XrdProtocol 00065 { 00066 friend class XrdXrootdAdmin; 00067 friend class XrdXrootdAioReq; 00068 public: 00069 00070 static int Configure(char *parms, XrdProtocol_Config *pi); 00071 00072 void DoIt() {(*this.*Resume)();} 00073 00074 XrdProtocol *Match(XrdLink *lp); 00075 00076 int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process 00077 00078 void Recycle(XrdLink *lp, int consec, const char *reason); 00079 00080 int Stats(char *buff, int blen, int do_sync=0); 00081 00082 static int StatGen(struct stat &buf, char *xxBuff); 00083 00084 XrdXrootdProtocol operator =(const XrdXrootdProtocol &rhs); 00085 XrdXrootdProtocol(); 00086 ~XrdXrootdProtocol() {Cleanup();} 00087 00088 private: 00089 00090 // Note that Route[] structure (below) must have RD_Num elements! 00091 // 00092 enum RD_func {RD_chmod = 0, RD_dirlist, RD_locate,RD_mkdir, RD_mv, 00093 RD_prepare, RD_prepstg, RD_rm, RD_rmdir, RD_stat, 00094 RD_open1, RD_open2, RD_open3, RD_open4, RD_Num}; 00095 00096 int do_Admin(); 00097 int do_Auth(); 00098 int do_Bind(); 00099 int do_Chmod(); 00100 int do_CKsum(int canit); 00101 int do_CKsum(const char *Path, const char *Opaque); 00102 int do_Close(); 00103 int do_Dirlist(); 00104 int do_Endsess(); 00105 int do_Getfile(); 00106 int do_Login(); 00107 int do_Locate(); 00108 int do_Mkdir(); 00109 int do_Mv(); 00110 int do_Offload(int pathID, int isRead); 00111 int do_OffloadIO(); 00112 int do_Open(); 00113 int do_Ping(); 00114 int do_Prepare(); 00115 int do_Protocol(int retRole=0); 00116 int do_Putfile(); 00117 int do_Qconf(); 00118 int do_Qfh(); 00119 int do_Qopaque(short); 00120 int do_Qspace(); 00121 int do_Query(); 00122 int do_Qxattr(); 00123 int do_Read(); 00124 int do_ReadV(); 00125 int do_ReadAll(int asyncOK=1); 00126 int do_ReadNone(int &retc, int &pathID); 00127 int do_Rm(); 00128 int do_Rmdir(); 00129 int do_Set(); 00130 int do_Set_Mon(XrdOucTokenizer &setargs); 00131 int do_Stat(); 00132 int do_Statx(); 00133 int do_Sync(); 00134 int do_Truncate(); 00135 int do_Write(); 00136 int do_WriteAll(); 00137 int do_WriteCont(); 00138 int do_WriteNone(); 00139 00140 int aio_Error(const char *op, int ecode); 00141 int aio_Read(); 00142 int aio_Write(); 00143 int aio_WriteAll(); 00144 int aio_WriteCont(); 00145 00146 void Assign(const XrdXrootdProtocol &rhs); 00147 static int CheckSum(XrdOucStream *, char **, int); 00148 void Cleanup(); 00149 static int Config(const char *fn); 00150 int fsError(int rc, XrdOucErrInfo &myError); 00151 int getBuff(const int isRead, int Quantum); 00152 int getData(const char *dtype, char *buff, int blen); 00153 static int mapMode(int mode); 00154 void MonAuth(); 00155 static void PidFile(); 00156 int Process2(); 00157 void Reset(); 00158 static int rpCheck(char *fn, const char **opaque); 00159 int rpEmsg(const char *op, char *fn); 00160 int vpEmsg(const char *op, char *fn); 00161 static int Squash(char *); 00162 static int xapath(XrdOucStream &Config); 00163 static int xasync(XrdOucStream &Config); 00164 static int xcksum(XrdOucStream &Config); 00165 static int xexp(XrdOucStream &Config); 00166 static int xexpdo(char *path, int popt=0); 00167 static int xfsl(XrdOucStream &Config); 00168 static int xpidf(XrdOucStream &Config); 00169 static int xprep(XrdOucStream &Config); 00170 static int xlog(XrdOucStream &Config); 00171 static int xmon(XrdOucStream &Config); 00172 static int xred(XrdOucStream &Config); 00173 static void xred_set(RD_func func, const char *rHost, int rPort); 00174 static int xsecl(XrdOucStream &Config); 00175 static int xtrace(XrdOucStream &Config); 00176 00177 static XrdObjectQ<XrdXrootdProtocol> ProtStack; 00178 XrdObject<XrdXrootdProtocol> ProtLink; 00179 00180 protected: 00181 00182 static XrdXrootdXPath RPList; // Redirected paths 00183 static XrdXrootdXPath XPList; // Exported paths 00184 static XrdSfsFileSystem *osFS; // The filesystem 00185 static XrdSecService *CIA; // Authentication Server 00186 static XrdXrootdFileLock *Locker; // File lock handler 00187 static XrdScheduler *Sched; // System scheduler 00188 static XrdBuffManager *BPool; // Buffer manager 00189 static XrdSysError eDest; // Error message handler 00190 static const char *myInst; 00191 static const char *TraceID; 00192 static char *pidPath; 00193 static int myPID; 00194 static int myRole; // Role for kXR_protocol (>= 2.9.7) 00195 static int myRolf; // Role for kXR_protocol (< 2.9.7) 00196 00197 // Admin control area 00198 // 00199 static XrdNetSocket *AdminSock; 00200 00201 // Processing configuration values 00202 // 00203 static int hailWait; 00204 static int readWait; 00205 static int Port; 00206 static int Window; 00207 static int WANPort; 00208 static int WANWindow; 00209 static char *SecLib; 00210 static char *FSLib; 00211 static char *Notify; 00212 static char isRedir; 00213 static char chkfsV; 00214 static char JobLCL; 00215 static char JobQCS; 00216 static XrdXrootdJob *JobCKS; 00217 static char *JobCKT; 00218 00219 // Static redirection 00220 // 00221 static struct RD_Table {char *Host; int Port;} Route[RD_Num]; 00222 00223 // async configuration values 00224 // 00225 static int as_maxperlnk; // Max async requests per link 00226 static int as_maxperreq; // Max async ops per request 00227 static int as_maxpersrv; // Max async ops per server 00228 static int as_miniosz; // Min async request size 00229 static int as_minsfsz; // Min sendf request size 00230 static int as_segsize; // Aio quantum (optimal) 00231 static int as_maxstalls; // Maximum stalls we will tolerate 00232 static int as_force; // aio to be forced 00233 static int as_noaio; // aio is disabled 00234 static int as_nosf; // sendfile is disabled 00235 static int as_syncw; // writes to be synchronous 00236 static int maxBuffsz; // Maximum buffer size we can have 00237 static int maxTransz; // Maximum transfer size we can have 00238 static const int maxRvecsz = 1024; // Maximum read vector size 00239 00240 // Statistical area 00241 // 00242 static XrdXrootdStats *SI; 00243 int numReads; // Count 00244 int numReadP; // Count 00245 int numWrites; // Count 00246 int numFiles; // Count 00247 00248 int cumReads; // Count less numReads 00249 int cumReadP; // Count less numReadP 00250 int cumWrites; // Count less numWrites 00251 long long totReadP; // Bytes 00252 00253 // Data local to each protocol/link combination 00254 // 00255 XrdLink *Link; 00256 XrdBuffer *argp; 00257 XrdXrootdFileTable *FTab; 00258 XrdXrootdMonitor *Monitor; 00259 kXR_unt32 monUID; 00260 char monFILE; 00261 char monIO; 00262 char Status; 00263 unsigned char CapVer; 00264 int clientPV; 00265 00266 // Authentication area 00267 // 00268 XrdSecEntity *Client; 00269 XrdSecProtocol *AuthProt; 00270 XrdSecEntity Entity; 00271 00272 // Buffer information, used to drive DoIt(), getData(), and (*Resume)() 00273 // 00274 XrdXrootdAioReq *myAioReq; 00275 char *myBuff; 00276 int myBlen; 00277 int myBlast; 00278 int (XrdXrootdProtocol::*Resume)(); 00279 XrdXrootdFile *myFile; 00280 long long myOffset; 00281 int myIOLen; 00282 int myStalls; 00283 00284 // Buffer resize control area 00285 // 00286 static int hcMax; 00287 int hcPrev; 00288 int hcNext; 00289 int hcNow; 00290 int halfBSize; 00291 00292 // This area is used for parallel streams 00293 // 00294 static const int maxStreams = 16; 00295 XrdSysMutex streamMutex; 00296 XrdSysSemaphore *reTry; 00297 XrdXrootdProtocol *Stream[maxStreams]; 00298 unsigned int mySID; 00299 char isActive; 00300 char isDead; 00301 char isBound; 00302 char isNOP; 00303 00304 static const int maxPio = 4; 00305 XrdXrootdPio *pioFirst; 00306 XrdXrootdPio *pioLast; 00307 XrdXrootdPio *pioFree; 00308 00309 short PathID; 00310 char doWrite; 00311 char doWriteC; 00312 char rvSeq; 00313 00314 // Buffers to handle client requests 00315 // 00316 XrdXrootdReqID ReqID; 00317 ClientRequest Request; 00318 XrdXrootdResponse Response; 00319 }; 00320 #endif
1.7.5