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