|
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-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 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 00040 #include "Xrd/XrdObject.hh" 00041 #include "Xrd/XrdProtocol.hh" 00042 #include "XrdXrootd/XrdXrootdMonitor.hh" 00043 #include "XrdXrootd/XrdXrootdReqID.hh" 00044 #include "XrdXrootd/XrdXrootdResponse.hh" 00045 #include "XProtocol/XProtocol.hh" 00046 00047 /******************************************************************************/ 00048 /* D e f i n e s */ 00049 /******************************************************************************/ 00050 00051 #define ROOTD_PQ 2012 00052 00053 #define XRD_LOGGEDIN 1 00054 #define XRD_NEED_AUTH 2 00055 #define XRD_ADMINUSER 4 00056 #define XRD_BOUNDPATH 8 00057 00058 #ifndef __GNUC__ 00059 #define __attribute__(x) 00060 #endif 00061 00062 /******************************************************************************/ 00063 /* x r d _ P r o t o c o l _ X R o o t d */ 00064 /******************************************************************************/ 00065 00066 class XrdNetSocket; 00067 class XrdOucErrInfo; 00068 class XrdOucStream; 00069 class XrdOucTokenizer; 00070 class XrdOucTrace; 00071 class XrdSfsFileSystem; 00072 class XrdSecProtocol; 00073 class XrdBuffer; 00074 class XrdLink; 00075 class XrdXrootdAioReq; 00076 class XrdXrootdFile; 00077 class XrdXrootdFileLock; 00078 class XrdXrootdFileTable; 00079 class XrdXrootdJob; 00080 class XrdXrootdMonitor; 00081 class XrdXrootdPio; 00082 class XrdXrootdStats; 00083 class XrdXrootdXPath; 00084 00085 class XrdXrootdProtocol : public XrdProtocol 00086 { 00087 friend class XrdXrootdAdmin; 00088 friend class XrdXrootdAioReq; 00089 public: 00090 00091 static int Configure(char *parms, XrdProtocol_Config *pi); 00092 00093 void DoIt() {(*this.*Resume)();} 00094 00095 XrdProtocol *Match(XrdLink *lp); 00096 00097 int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process 00098 00099 void Recycle(XrdLink *lp, int consec, const char *reason); 00100 00101 int Stats(char *buff, int blen, int do_sync=0); 00102 00103 static int StatGen(struct stat &buf, char *xxBuff); 00104 00105 XrdXrootdProtocol operator =(const XrdXrootdProtocol &rhs); 00106 XrdXrootdProtocol(); 00107 ~XrdXrootdProtocol() {Cleanup();} 00108 00109 private: 00110 00111 // Note that Route[] structure (below) must have RD_Num elements! 00112 // 00113 enum RD_func {RD_chmod = 0, RD_chksum, RD_dirlist, RD_locate, RD_mkdir, 00114 RD_mv, RD_prepare, RD_prepstg, RD_rm, RD_rmdir, 00115 RD_stat, RD_trunc, 00116 RD_open1, RD_open2, RD_open3, RD_open4, RD_Num}; 00117 00118 int do_Admin(); 00119 int do_Auth(); 00120 int do_Bind(); 00121 int do_Chmod(); 00122 int do_CKsum(int canit); 00123 int do_CKsum(const char *Path, const char *Opaque); 00124 int do_Close(); 00125 int do_Dirlist(); 00126 int do_Endsess(); 00127 int do_Getfile(); 00128 int do_Login(); 00129 int do_Locate(); 00130 int do_Mkdir(); 00131 int do_Mv(); 00132 int do_Offload(int pathID, int isRead); 00133 int do_OffloadIO(); 00134 int do_Open(); 00135 int do_Ping(); 00136 int do_Prepare(); 00137 int do_Protocol(int retRole=0); 00138 int do_Putfile(); 00139 int do_Qconf(); 00140 int do_Qfh(); 00141 int do_Qopaque(short); 00142 int do_Qspace(); 00143 int do_Query(); 00144 int do_Qxattr(); 00145 int do_Read(); 00146 int do_ReadV(); 00147 int do_ReadAll(int asyncOK=1); 00148 int do_ReadNone(int &retc, int &pathID); 00149 int do_Rm(); 00150 int do_Rmdir(); 00151 int do_Set(); 00152 int do_Set_Mon(XrdOucTokenizer &setargs); 00153 int do_Stat(); 00154 int do_Statx(); 00155 int do_Sync(); 00156 int do_Truncate(); 00157 int do_Write(); 00158 int do_WriteAll(); 00159 int do_WriteCont(); 00160 int do_WriteNone(); 00161 00162 int aio_Error(const char *op, int ecode); 00163 int aio_Read(); 00164 int aio_Write(); 00165 int aio_WriteAll(); 00166 int aio_WriteCont(); 00167 00168 void Assign(const XrdXrootdProtocol &rhs); 00169 static int CheckSum(XrdOucStream *, char **, int); 00170 void Cleanup(); 00171 static int Config(const char *fn); 00172 int fsError(int rc, char opc, XrdOucErrInfo &myError, const char *Path); 00173 int getBuff(const int isRead, int Quantum); 00174 int getData(const char *dtype, char *buff, int blen); 00175 static int mapMode(int mode); 00176 void MonAuth(); 00177 static void PidFile(); 00178 int Process2(); 00179 void Reset(); 00180 static int rpCheck(char *fn, const char **opaque); 00181 int rpEmsg(const char *op, char *fn); 00182 int vpEmsg(const char *op, char *fn); 00183 static int Squash(char *); 00184 static int xapath(XrdOucStream &Config); 00185 static int xasync(XrdOucStream &Config); 00186 static int xcksum(XrdOucStream &Config); 00187 static int xexp(XrdOucStream &Config); 00188 static int xexpdo(char *path, int popt=0); 00189 static int xfsl(XrdOucStream &Config); 00190 static int xpidf(XrdOucStream &Config); 00191 static int xprep(XrdOucStream &Config); 00192 static int xlog(XrdOucStream &Config); 00193 static int xmon(XrdOucStream &Config); 00194 static int xred(XrdOucStream &Config); 00195 static void xred_set(RD_func func, const char *rHost, int rPort); 00196 static int xsecl(XrdOucStream &Config); 00197 static int xtrace(XrdOucStream &Config); 00198 00199 static XrdObjectQ<XrdXrootdProtocol> ProtStack; 00200 XrdObject<XrdXrootdProtocol> ProtLink; 00201 00202 protected: 00203 00204 static XrdXrootdXPath RPList; // Redirected paths 00205 static XrdXrootdXPath RQList; // Redirected paths for ENOENT 00206 static XrdXrootdXPath XPList; // Exported paths 00207 static XrdSfsFileSystem *osFS; // The filesystem 00208 static XrdSecService *CIA; // Authentication Server 00209 static XrdXrootdFileLock *Locker; // File lock handler 00210 static XrdScheduler *Sched; // System scheduler 00211 static XrdBuffManager *BPool; // Buffer manager 00212 static XrdSysError eDest; // Error message handler 00213 static const char *myInst; 00214 static const char *TraceID; 00215 static char *pidPath; 00216 static int RQLxist; // Something is present in RQList 00217 static int myPID; 00218 static int myRole; // Role for kXR_protocol (>= 2.9.7) 00219 static int myRolf; // Role for kXR_protocol (< 2.9.7) 00220 00221 // Admin control area 00222 // 00223 static XrdNetSocket *AdminSock; 00224 00225 // Processing configuration values 00226 // 00227 static int hailWait; 00228 static int readWait; 00229 static int Port; 00230 static int Window; 00231 static int WANPort; 00232 static int WANWindow; 00233 static char *SecLib; 00234 static char *FSLib; 00235 static char *Notify; 00236 static char isRedir; 00237 static char chkfsV; 00238 static char JobLCL; 00239 static XrdXrootdJob *JobCKS; 00240 static char *JobCKT; 00241 00242 // Static redirection 00243 // 00244 static struct RD_Table {char *Host; int Port;} Route[RD_Num]; 00245 00246 // async configuration values 00247 // 00248 static int as_maxperlnk; // Max async requests per link 00249 static int as_maxperreq; // Max async ops per request 00250 static int as_maxpersrv; // Max async ops per server 00251 static int as_miniosz; // Min async request size 00252 static int as_minsfsz; // Min sendf request size 00253 static int as_segsize; // Aio quantum (optimal) 00254 static int as_maxstalls; // Maximum stalls we will tolerate 00255 static int as_force; // aio to be forced 00256 static int as_noaio; // aio is disabled 00257 static int as_nosf; // sendfile is disabled 00258 static int as_syncw; // writes to be synchronous 00259 static int maxBuffsz; // Maximum buffer size we can have 00260 static int maxTransz; // Maximum transfer size we can have 00261 static const int maxRvecsz = 1024; // Maximum read vector size 00262 00263 // Statistical area 00264 // 00265 static XrdXrootdStats *SI; 00266 int numReads; // Count for kXR_read 00267 int numReadP; // Count for kXR_read pre-preads 00268 int numReadV; // Count for kR_readv 00269 int numSegsV; // Count for kR_readv segmens 00270 int numWrites; // Count 00271 int numFiles; // Count 00272 00273 int cumReads; // Count less numReads 00274 int cumReadP; // Count less numReadP 00275 int cumReadV; // Count less numReadV 00276 int cumSegsV; // Count less numSegsV 00277 int cumWrites; // Count less numWrites 00278 long long totReadP; // Bytes 00279 00280 // Data local to each protocol/link combination 00281 // 00282 XrdLink *Link; 00283 XrdBuffer *argp; 00284 XrdXrootdFileTable *FTab; 00285 XrdXrootdMonitor::User Monitor; 00286 int clientPV; 00287 char Status; 00288 unsigned char CapVer; 00289 00290 // Authentication area 00291 // 00292 XrdSecEntity *Client; 00293 XrdSecProtocol *AuthProt; 00294 XrdSecEntity Entity; 00295 00296 // Buffer information, used to drive DoIt(), getData(), and (*Resume)() 00297 // 00298 XrdXrootdAioReq *myAioReq; 00299 char *myBuff; 00300 int myBlen; 00301 int myBlast; 00302 int (XrdXrootdProtocol::*Resume)(); 00303 XrdXrootdFile *myFile; 00304 union { 00305 long long myOffset; 00306 int myEInfo[2]; 00307 }; 00308 int myIOLen; 00309 int myStalls; 00310 00311 // Buffer resize control area 00312 // 00313 static int hcMax; 00314 int hcPrev; 00315 int hcNext; 00316 int hcNow; 00317 int halfBSize; 00318 00319 // This area is used for parallel streams 00320 // 00321 static const int maxStreams = 16; 00322 XrdSysMutex streamMutex; 00323 XrdSysSemaphore *reTry; 00324 XrdXrootdProtocol *Stream[maxStreams]; 00325 unsigned int mySID; 00326 char isActive; 00327 char isDead; 00328 char isBound; 00329 char isNOP; 00330 00331 static const int maxPio = 4; 00332 XrdXrootdPio *pioFirst; 00333 XrdXrootdPio *pioLast; 00334 XrdXrootdPio *pioFree; 00335 00336 short PathID; 00337 char doWrite; 00338 char doWriteC; 00339 char rvSeq; 00340 00341 // Buffers to handle client requests 00342 // 00343 XrdXrootdReqID ReqID; 00344 ClientRequest Request; 00345 XrdXrootdResponse Response; 00346 }; 00347 #endif
1.7.6.1