xrootd
XrdXrootdProtocol.hh
Go to the documentation of this file.
1 #ifndef __XROOTD_PROTOCOL_H__
2 #define __XROOTD_PROTOCOL_H__
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d P r o t o c o l . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC03-76-SFO0515 with the Department of Energy */
10 /******************************************************************************/
11 
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <sys/types.h>
15 
16 #include "XrdSys/XrdSysError.hh"
17 #include "XrdSys/XrdSysPthread.hh"
19 
20 #include "Xrd/XrdObject.hh"
21 #include "Xrd/XrdProtocol.hh"
25 #include "XProtocol/XProtocol.hh"
26 
27 /******************************************************************************/
28 /* D e f i n e s */
29 /******************************************************************************/
30 
31 #define ROOTD_PQ 2012
32 
33 #define XRD_LOGGEDIN 1
34 #define XRD_NEED_AUTH 2
35 #define XRD_ADMINUSER 4
36 #define XRD_BOUNDPATH 8
37 
38 #ifndef __GNUC__
39 #define __attribute__(x)
40 #endif
41 
42 /******************************************************************************/
43 /* x r d _ P r o t o c o l _ X R o o t d */
44 /******************************************************************************/
45 
46 class XrdNetSocket;
47 class XrdOucErrInfo;
48 class XrdOucStream;
49 class XrdOucTokenizer;
50 class XrdOucTrace;
51 class XrdSfsFileSystem;
52 class XrdSecProtocol;
53 class XrdBuffer;
54 class XrdLink;
55 class XrdXrootdAioReq;
56 class XrdXrootdFile;
57 class XrdXrootdFileLock;
58 class XrdXrootdFileTable;
59 class XrdXrootdJob;
60 class XrdXrootdMonitor;
61 class XrdXrootdPio;
62 class XrdXrootdStats;
63 class XrdXrootdXPath;
64 
65 class XrdXrootdProtocol : public XrdProtocol
66 {
67 friend class XrdXrootdAdmin;
68 friend class XrdXrootdAioReq;
69 public:
70 
71 static int Configure(char *parms, XrdProtocol_Config *pi);
72 
73  void DoIt() {(*this.*Resume)();}
74 
76 
77  int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process
78 
79  void Recycle(XrdLink *lp, int consec, const char *reason);
80 
81  int Stats(char *buff, int blen, int do_sync=0);
82 
83 static int StatGen(struct stat &buf, char *xxBuff);
84 
88 
89 private:
90 
91 // Note that Route[] structure (below) must have RD_Num elements!
92 //
97 
98  int do_Admin();
99  int do_Auth();
100  int do_Bind();
101  int do_Chmod();
102  int do_CKsum(int canit);
103  int do_CKsum(const char *Path, const char *Opaque);
104  int do_Close();
105  int do_Dirlist();
106  int do_Endsess();
107  int do_Getfile();
108  int do_Login();
109  int do_Locate();
110  int do_Mkdir();
111  int do_Mv();
112  int do_Offload(int pathID, int isRead);
113  int do_OffloadIO();
114  int do_Open();
115  int do_Ping();
116  int do_Prepare();
117  int do_Protocol(int retRole=0);
118  int do_Putfile();
119  int do_Qconf();
120  int do_Qfh();
121  int do_Qopaque(short);
122  int do_Qspace();
123  int do_Query();
124  int do_Qxattr();
125  int do_Read();
126  int do_ReadV();
127  int do_ReadAll(int asyncOK=1);
128  int do_ReadNone(int &retc, int &pathID);
129  int do_Rm();
130  int do_Rmdir();
131  int do_Set();
132  int do_Set_Mon(XrdOucTokenizer &setargs);
133  int do_Stat();
134  int do_Statx();
135  int do_Sync();
136  int do_Truncate();
137  int do_Write();
138  int do_WriteAll();
139  int do_WriteCont();
140  int do_WriteNone();
141 
142  int aio_Error(const char *op, int ecode);
143  int aio_Read();
144  int aio_Write();
145  int aio_WriteAll();
146  int aio_WriteCont();
147 
148  void Assign(const XrdXrootdProtocol &rhs);
149 static int CheckSum(XrdOucStream *, char **, int);
150  void Cleanup();
151 static int Config(const char *fn);
152  int fsError(int rc, char opc, XrdOucErrInfo &myError, const char *Path);
153  int getBuff(const int isRead, int Quantum);
154  int getData(const char *dtype, char *buff, int blen);
155 static int mapMode(int mode);
156  void MonAuth();
157 static void PidFile();
158  int Process2();
159  void Reset();
160 static int rpCheck(char *fn, const char **opaque);
161  int rpEmsg(const char *op, char *fn);
162  int vpEmsg(const char *op, char *fn);
163 static int Squash(char *);
164 static int xapath(XrdOucStream &Config);
165 static int xasync(XrdOucStream &Config);
166 static int xcksum(XrdOucStream &Config);
167 static int xexp(XrdOucStream &Config);
168 static int xexpdo(char *path, int popt=0);
169 static int xfsl(XrdOucStream &Config);
170 static int xpidf(XrdOucStream &Config);
171 static int xprep(XrdOucStream &Config);
172 static int xlog(XrdOucStream &Config);
173 static int xmon(XrdOucStream &Config);
174 static int xred(XrdOucStream &Config);
175 static void xred_set(RD_func func, const char *rHost, int rPort);
176 static int xsecl(XrdOucStream &Config);
177 static int xtrace(XrdOucStream &Config);
178 
181 
182 protected:
183 
184 static XrdXrootdXPath RPList; // Redirected paths
185 static XrdXrootdXPath RQList; // Redirected paths for ENOENT
186 static XrdXrootdXPath XPList; // Exported paths
187 static XrdSfsFileSystem *osFS; // The filesystem
188 static XrdSecService *CIA; // Authentication Server
189 static XrdXrootdFileLock *Locker; // File lock handler
190 static XrdScheduler *Sched; // System scheduler
191 static XrdBuffManager *BPool; // Buffer manager
192 static XrdSysError eDest; // Error message handler
193 static const char *myInst;
194 static const char *TraceID;
195 static char *pidPath;
196 static int RQLxist; // Something is present in RQList
197 static int myPID;
198 static int myRole; // Role for kXR_protocol (>= 2.9.7)
199 static int myRolf; // Role for kXR_protocol (< 2.9.7)
200 
201 // Admin control area
202 //
204 
205 // Processing configuration values
206 //
207 static int hailWait;
208 static int readWait;
209 static int Port;
210 static int Window;
211 static int WANPort;
212 static int WANWindow;
213 static char *SecLib;
214 static char *FSLib;
215 static char *Notify;
216 static char isRedir;
217 static char chkfsV;
218 static char JobLCL;
219 static char JobQCS;
221 static char *JobCKT;
222 
223 // Static redirection
224 //
225 static struct RD_Table {char *Host; int Port;} Route[RD_Num];
226 
227 // async configuration values
228 //
229 static int as_maxperlnk; // Max async requests per link
230 static int as_maxperreq; // Max async ops per request
231 static int as_maxpersrv; // Max async ops per server
232 static int as_miniosz; // Min async request size
233 static int as_minsfsz; // Min sendf request size
234 static int as_segsize; // Aio quantum (optimal)
235 static int as_maxstalls; // Maximum stalls we will tolerate
236 static int as_force; // aio to be forced
237 static int as_noaio; // aio is disabled
238 static int as_nosf; // sendfile is disabled
239 static int as_syncw; // writes to be synchronous
240 static int maxBuffsz; // Maximum buffer size we can have
241 static int maxTransz; // Maximum transfer size we can have
242 static const int maxRvecsz = 1024; // Maximum read vector size
243 
244 // Statistical area
245 //
247 int numReads; // Count
248 int numReadP; // Count
249 int numWrites; // Count
250 int numFiles; // Count
251 
252 int cumReads; // Count less numReads
253 int cumReadP; // Count less numReadP
254 int cumWrites; // Count less numWrites
255 long long totReadP; // Bytes
256 
257 // Data local to each protocol/link combination
258 //
264 char Status;
265 unsigned char CapVer;
266 
267 // Authentication area
268 //
272 
273 // Buffer information, used to drive DoIt(), getData(), and (*Resume)()
274 //
276 char *myBuff;
277 int myBlen;
281 union {
282 long long myOffset;
283 int myEInfo[2];
284  };
287 
288 // Buffer resize control area
289 //
290 static int hcMax;
291  int hcPrev;
292  int hcNext;
293  int hcNow;
295 
296 // This area is used for parallel streams
297 //
298 static const int maxStreams = 16;
302 unsigned int mySID;
303 char isActive;
304 char isDead;
305 char isBound;
306 char isNOP;
307 
308 static const int maxPio = 4;
312 
313 short PathID;
314 char doWrite;
315 char doWriteC;
316 char rvSeq;
317 
318 // Buffers to handle client requests
319 //
323 };
324 #endif