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-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 
36 #include "XrdSys/XrdSysError.hh"
37 #include "XrdSys/XrdSysPthread.hh"
39 
40 #include "Xrd/XrdObject.hh"
41 #include "Xrd/XrdProtocol.hh"
45 #include "XProtocol/XProtocol.hh"
46 
47 /******************************************************************************/
48 /* D e f i n e s */
49 /******************************************************************************/
50 
51 #define ROOTD_PQ 2012
52 
53 #define XRD_LOGGEDIN 1
54 #define XRD_NEED_AUTH 2
55 #define XRD_ADMINUSER 4
56 #define XRD_BOUNDPATH 8
57 
58 #ifndef __GNUC__
59 #define __attribute__(x)
60 #endif
61 
62 /******************************************************************************/
63 /* x r d _ P r o t o c o l _ X R o o t d */
64 /******************************************************************************/
65 
66 class XrdNetSocket;
67 class XrdOucErrInfo;
68 class XrdOucStream;
69 class XrdOucTokenizer;
70 class XrdOucTrace;
71 class XrdSfsFileSystem;
72 class XrdSecProtocol;
73 class XrdBuffer;
74 class XrdLink;
75 class XrdXrootdAioReq;
76 class XrdXrootdFile;
77 class XrdXrootdFileLock;
78 class XrdXrootdFileTable;
79 class XrdXrootdJob;
80 class XrdXrootdMonitor;
81 class XrdXrootdPio;
82 class XrdXrootdStats;
83 class XrdXrootdXPath;
84 
85 class XrdXrootdProtocol : public XrdProtocol
86 {
87 friend class XrdXrootdAdmin;
88 friend class XrdXrootdAioReq;
89 public:
90 
91 static int Configure(char *parms, XrdProtocol_Config *pi);
92 
93  void DoIt() {(*this.*Resume)();}
94 
96 
97  int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process
98 
99  void Recycle(XrdLink *lp, int consec, const char *reason);
100 
101  int Stats(char *buff, int blen, int do_sync=0);
102 
103 static int StatGen(struct stat &buf, char *xxBuff);
104 
108 
109 private:
110 
111 // Note that Route[] structure (below) must have RD_Num elements!
112 //
117 
118  int do_Admin();
119  int do_Auth();
120  int do_Bind();
121  int do_Chmod();
122  int do_CKsum(int canit);
123  int do_CKsum(const char *Path, const char *Opaque);
124  int do_Close();
125  int do_Dirlist();
126  int do_Endsess();
127  int do_Getfile();
128  int do_Login();
129  int do_Locate();
130  int do_Mkdir();
131  int do_Mv();
132  int do_Offload(int pathID, int isRead);
133  int do_OffloadIO();
134  int do_Open();
135  int do_Ping();
136  int do_Prepare();
137  int do_Protocol(int retRole=0);
138  int do_Putfile();
139  int do_Qconf();
140  int do_Qfh();
141  int do_Qopaque(short);
142  int do_Qspace();
143  int do_Query();
144  int do_Qxattr();
145  int do_Read();
146  int do_ReadV();
147  int do_ReadAll(int asyncOK=1);
148  int do_ReadNone(int &retc, int &pathID);
149  int do_Rm();
150  int do_Rmdir();
151  int do_Set();
152  int do_Set_Mon(XrdOucTokenizer &setargs);
153  int do_Stat();
154  int do_Statx();
155  int do_Sync();
156  int do_Truncate();
157  int do_Write();
158  int do_WriteAll();
159  int do_WriteCont();
160  int do_WriteNone();
161 
162  int aio_Error(const char *op, int ecode);
163  int aio_Read();
164  int aio_Write();
165  int aio_WriteAll();
166  int aio_WriteCont();
167 
168  void Assign(const XrdXrootdProtocol &rhs);
169 static int CheckSum(XrdOucStream *, char **, int);
170  void Cleanup();
171 static int Config(const char *fn);
172  int fsError(int rc, char opc, XrdOucErrInfo &myError, const char *Path);
173  int getBuff(const int isRead, int Quantum);
174  int getData(const char *dtype, char *buff, int blen);
175 static int mapMode(int mode);
176  void MonAuth();
177 static void PidFile();
178  int Process2();
179  void Reset();
180 static int rpCheck(char *fn, const char **opaque);
181  int rpEmsg(const char *op, char *fn);
182  int vpEmsg(const char *op, char *fn);
183 static int Squash(char *);
184 static int xapath(XrdOucStream &Config);
185 static int xasync(XrdOucStream &Config);
186 static int xcksum(XrdOucStream &Config);
187 static int xexp(XrdOucStream &Config);
188 static int xexpdo(char *path, int popt=0);
189 static int xfsl(XrdOucStream &Config);
190 static int xpidf(XrdOucStream &Config);
191 static int xprep(XrdOucStream &Config);
192 static int xlog(XrdOucStream &Config);
193 static int xmon(XrdOucStream &Config);
194 static int xred(XrdOucStream &Config);
195 static void xred_set(RD_func func, const char *rHost, int rPort);
196 static int xsecl(XrdOucStream &Config);
197 static int xtrace(XrdOucStream &Config);
198 
201 
202 protected:
203 
204 static XrdXrootdXPath RPList; // Redirected paths
205 static XrdXrootdXPath RQList; // Redirected paths for ENOENT
206 static XrdXrootdXPath XPList; // Exported paths
207 static XrdSfsFileSystem *osFS; // The filesystem
208 static XrdSecService *CIA; // Authentication Server
209 static XrdXrootdFileLock *Locker; // File lock handler
210 static XrdScheduler *Sched; // System scheduler
211 static XrdBuffManager *BPool; // Buffer manager
212 static XrdSysError eDest; // Error message handler
213 static const char *myInst;
214 static const char *TraceID;
215 static char *pidPath;
216 static int RQLxist; // Something is present in RQList
217 static int myPID;
218 static int myRole; // Role for kXR_protocol (>= 2.9.7)
219 static int myRolf; // Role for kXR_protocol (< 2.9.7)
220 
221 // Admin control area
222 //
224 
225 // Processing configuration values
226 //
227 static int hailWait;
228 static int readWait;
229 static int Port;
230 static int Window;
231 static int WANPort;
232 static int WANWindow;
233 static char *SecLib;
234 static char *FSLib;
235 static char *Notify;
236 static char isRedir;
237 static char chkfsV;
238 static char JobLCL;
240 static char *JobCKT;
241 
242 // Static redirection
243 //
244 static struct RD_Table {char *Host; int Port;} Route[RD_Num];
245 
246 // async configuration values
247 //
248 static int as_maxperlnk; // Max async requests per link
249 static int as_maxperreq; // Max async ops per request
250 static int as_maxpersrv; // Max async ops per server
251 static int as_miniosz; // Min async request size
252 static int as_minsfsz; // Min sendf request size
253 static int as_segsize; // Aio quantum (optimal)
254 static int as_maxstalls; // Maximum stalls we will tolerate
255 static int as_force; // aio to be forced
256 static int as_noaio; // aio is disabled
257 static int as_nosf; // sendfile is disabled
258 static int as_syncw; // writes to be synchronous
259 static int maxBuffsz; // Maximum buffer size we can have
260 static int maxTransz; // Maximum transfer size we can have
261 static const int maxRvecsz = 1024; // Maximum read vector size
262 
263 // Statistical area
264 //
266 int numReads; // Count for kXR_read
267 int numReadP; // Count for kXR_read pre-preads
268 int numReadV; // Count for kR_readv
269 int numSegsV; // Count for kR_readv segmens
270 int numWrites; // Count
271 int numFiles; // Count
272 
273 int cumReads; // Count less numReads
274 int cumReadP; // Count less numReadP
275 int cumReadV; // Count less numReadV
276 int cumSegsV; // Count less numSegsV
277 int cumWrites; // Count less numWrites
278 long long totReadP; // Bytes
279 
280 // Data local to each protocol/link combination
281 //
287 char Status;
288 unsigned char CapVer;
289 
290 // Authentication area
291 //
295 
296 // Buffer information, used to drive DoIt(), getData(), and (*Resume)()
297 //
299 char *myBuff;
300 int myBlen;
304 union {
305 long long myOffset;
306 int myEInfo[2];
307  };
310 
311 // Buffer resize control area
312 //
313 static int hcMax;
314  int hcPrev;
315  int hcNext;
316  int hcNow;
318 
319 // This area is used for parallel streams
320 //
321 static const int maxStreams = 16;
325 unsigned int mySID;
326 char isActive;
327 char isDead;
328 char isBound;
329 char isNOP;
330 
331 static const int maxPio = 4;
335 
336 short PathID;
337 char doWrite;
338 char doWriteC;
339 char rvSeq;
340 
341 // Buffers to handle client requests
342 //
346 };
347 #endif