XRootD
Loading...
Searching...
No Matches
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 <cstdlib>
33#include <unistd.h>
34#include <sys/types.h>
35
36#include "XrdNet/XrdNetPMark.hh"
37#include "XrdSys/XrdSysError.hh"
41#include "XrdSfs/XrdSfsDio.hh"
43
44#include "Xrd/XrdObject.hh"
45#include "Xrd/XrdProtocol.hh"
50
51/******************************************************************************/
52/* D e f i n e s */
53/******************************************************************************/
54
55#define ROOTD_PQ 2012
56
57#define XRD_LOGGEDIN 1
58#define XRD_NEED_AUTH 2
59#define XRD_BOUNDPATH 8
60
61#ifndef __GNUC__
62#define __attribute__(x)
63#endif
64
65/******************************************************************************/
66/* x r d _ P r o t o c o l _ X R o o t d */
67/******************************************************************************/
68
69class XrdNetSocket;
70class XrdOucEnv;
71class XrdOucErrInfo;
72class XrdOucReqID;
73class XrdOucStream;
74class XrdOucTList;
75class XrdOucTokenizer;
76class XrdSecProtect;
77class XrdSecProtector;
78class XrdSfsDirectory;
80class XrdSecProtocol;
81class XrdBuffer;
82class XrdLink;
83class XrdTlsContext;
84class XrdXrootdFile;
87class XrdXrootdJob;
89class XrdXrootdPgwCtl;
90class XrdXrootdPio;
91class XrdXrootdStats;
92class XrdXrootdXPath;
93
94struct XrdSfsFACtl;
95struct XrdXrootdWVInfo;
96
97/******************************************************************************/
98/* N a m e s p a c e X r d X r o o t d */
99/******************************************************************************/
100
101namespace XrdXrootd
102{
103/******************************************************************************/
104/* g d C a l l B a c k */
105/******************************************************************************/
106
107class gdCallBack // Used for new style getData() with callback
108{
109public:
110
111// Called when getData with a buffer successfully completed with a suspension.
112// A direct return is made if there was no suspension. Return values and action:
113// >1 If getData with a buffer was called while in the callback, the operation
114// is performed with a subsequent callback. Otherwise, a fatal error results.
115// =0 Variable discard holds the number of bytes to be discarded from the
116// from the socket (default 0). Return is made to link-level.
117// <0 Considered a fatal link error.
118//
119virtual int gdDone() = 0;
120
121// Called when a fatal link error occurs during reading.
122//
123virtual void gdFail() {} // Called when a link failure occurs
124
126virtual ~gdCallBack() {}
127};
128
129/******************************************************************************/
130/* I O P a r m s */
131/******************************************************************************/
132
134{
136union {
137long long Offset;
138long long WVBytes;
139int EInfo[2];
140 };
142unsigned short Flags;
144char Mode;
145static const int useBasic = 0;
146static const int useMMap = 1;
147static const int useSF = 2;
148};
149}
150
151/******************************************************************************/
152/* C l a s s X r d X r o o t d P r o t o c o l */
153/******************************************************************************/
154
156 public XrdSfsDio, public XrdSfsXio
157{
158friend class XrdXrootdAdmin;
159public:
160
161 void aioUpdate(int val) {srvrAioOps += val;}
162
163 void aioUpdReq(int val) {linkAioReq += val;}
164
165static char *Buffer(XrdSfsXioHandle h, int *bsz); // XrdSfsXio
166
167XrdSfsXioHandle Claim(const char *buff, int datasz, int minasz=0) override;// XrdSfsXio
168
169static int Configure(char *parms, XrdProtocol_Config *pi);
170
171 void DoIt() override {(*this.*Resume)();}
172
173 int do_WriteSpan();
175 int getData(gdCallBack *gdcbP, const char *dtype,
176 char *buff, int blen);
177
178 int getData(gdCallBack *gdcbP, const char *dtype,
179 struct iovec *iov, int iovn);
180
181 int getDump(const char *dtype, int dlen);
182
183 int getPathID() {return PathID;}
184
185 XrdProtocol *Match(XrdLink *lp) override;
186
187 int Process(XrdLink *lp) override; // Sync: Job->Link.DoIt->Process
188
189 int Process2();
190
191 int ProcSig();
192
193 void Recycle(XrdLink *lp, int consec, const char *reason) override;
194
195static void Reclaim(XrdSfsXioHandle h); // XrdSfsXio
196
197 int SendFile(int fildes) override; // XrdSfsDio
198
199 int SendFile(XrdOucSFVec *sfvec, int sfvnum) override; // XrdSfsDio
200
201 void SetFD(int fildes) override; // XrdSfsDio
202
203 int Stats(char *buff, int blen, int do_sync=0) override;
204
205 void StreamNOP();
206
207XrdSfsXioHandle Swap(const char *buff, XrdSfsXioHandle h=0) override; // XrdSfsXio
208
209XrdXrootdProtocol *VerifyStream(int &rc, int pID, bool lok=true);
210
213 ~XrdXrootdProtocol() {Cleanup();}
214
215static const int maxStreams = 16;
216
217// async configuration values (referenced outside this class)
218//
219static int as_maxperlnk; // Max async requests per link
220static int as_maxperreq; // Max async ops per request
221static int as_maxpersrv; // Max async ops per server
222static int as_miniosz; // Min async request size
223static int as_minsfsz; // Min sendf request size
224static int as_seghalf;
225static int as_segsize; // Aio quantum (optimal)
226static int as_maxstalls; // Maximum stalls we will tolerate
227static short as_okstutter; // Allowable stutters per transfer unit
228static short as_timeout; // request timeout (usually < stream timeout)
229static bool as_force; // aio to be forced
230static bool as_aioOK; // aio is enabled
231static bool as_nosf; // sendfile is disabled
232static bool as_syncw; // writes to be synchronous
233
234private:
235
236// Note that Route[] structure (below) must have RD_Num elements!
237//
238enum RD_func {RD_chmod = 0, RD_chksum, RD_dirlist, RD_locate, RD_mkdir,
239 RD_mv, RD_prepare, RD_prepstg, RD_rm, RD_rmdir,
240 RD_stat, RD_trunc, RD_ovld, RD_client,
241 RD_open1, RD_open2, RD_open3, RD_open4, RD_Num};
242
243 int do_Auth();
244 int do_Bind();
245 int do_ChkPnt();
246 int do_ChkPntXeq();
247 int do_Chmod();
248 int do_CKsum(int canit);
249 int do_CKsum(char *algT, const char *Path, char *Opaque);
250 int do_Close();
251 int do_Dirlist();
252 int do_DirStat(XrdSfsDirectory *dp, char *pbuff, char *opaque);
253 int do_Endsess();
254 int do_FAttr();
255 int do_gpFile();
256 int do_Login();
257 int do_Locate();
258 int do_Mkdir();
259 int do_Mv();
260 int do_Offload(int (XrdXrootdProtocol::*Invoke)(), int pathID);
261 int do_OffloadIO();
262 int do_Open();
263 bool do_PgClose(XrdXrootdFile *fP, int &rc);
264 int do_PgRead();
265 int do_PgRIO();
266 int do_PgWrite();
267 bool do_PgWAIO(int &rc);
268 int do_PgWIO();
269 int do_PgWIO(bool isFresh);
270 bool do_PgWIORetry(int &rc);
271 bool do_PgWIOSetup(XrdXrootdPgwCtl *pgwCtl);
272 int do_Ping();
273 int do_Prepare(bool isQuery=false);
274 int do_Protocol();
275 int do_Qconf();
276 int do_QconfCX(XrdOucTokenizer &qcargs, char *val);
277 int do_Qfh();
278 int do_Qopaque(short);
279 int do_Qspace();
280 int do_Query();
281 int do_Qxattr();
282 int do_Read();
283 int do_ReadV();
284 int do_ReadAll();
285 int do_ReadNone(int &retc, int &pathID);
286 int do_Rm();
287 int do_Rmdir();
288 int do_Set();
289 int do_Set_Cache(XrdOucTokenizer &setargs);
290 int do_Set_Mon(XrdOucTokenizer &setargs);
291 int do_Stat();
292 int do_Statx();
293 int do_Sync();
294 int do_Truncate();
295 int do_Write();
296 int do_WriteAio();
297 int do_WriteAll();
298 int do_WriteCont();
299 int do_WriteNone();
300 int do_WriteNone(int pathid, XErrorCode ec=kXR_noErrorYet,
301 const char *emsg=0);
302 int do_WriteNoneMsg();
303 int do_WriteV();
304 int do_WriteVec();
305
306 int gdDone() override {return do_PgWIO(false);}
307
308 void Assign(const XrdXrootdProtocol &rhs);
309static int CheckSum(XrdOucStream *, char **, int);
310 void Cleanup();
311static int Config(const char *fn);
312static bool ConfigMon(XrdProtocol_Config *pi, XrdOucEnv &xrootdEnv);
313static int ConfigSecurity(XrdOucEnv &xEnv, const char *cfn);
314 int fsError(int rc, char opc, XrdOucErrInfo &myError,
315 const char *Path, char *Cgi);
316 int fsOvrld(char opc, const char *Path, char *Cgi);
317 int fsRedirNoEnt(const char *eMsg, char *Cgi, int popt);
318 int getBuff(const int isRead, int Quantum);
319 char *getCksType(char *opaque, char *cspec=0, int cslen=0);
320 int getData(const char *dtype, char *buff, int blen);
321 int getDataCont();
322 int getDataIovCont();
323 int getDumpCont();
324 bool logLogin(bool xauth=false);
325static int mapMode(int mode);
326 void Reset();
327static int rpCheck(char *fn, char **opaque);
328 int rpEmsg(const char *op, char *fn);
329 int vpEmsg(const char *op, char *fn);
330static int CheckTLS(const char *tlsProt);
331static bool ConfigFS(XrdOucEnv &xEnv, const char *cfn);
332static bool ConfigFS(const char *path, XrdOucEnv &xEnv, const char *cfn);
333static bool ConfigGStream(XrdOucEnv &myEnv, XrdOucEnv *urEnv);
334static int Squash(char *);
335 int StatGen(struct stat &buf, char *xxBuff, int xxLen, bool xa=false);
336static int xapath(XrdOucStream &Config);
337static int xasync(XrdOucStream &Config);
338static int xcksum(XrdOucStream &Config);
339static int xbif(XrdOucStream &Config);
340static int xdig(XrdOucStream &Config);
341static int xexp(XrdOucStream &Config);
342static int xexpdo(char *path, int popt=0);
343static int xfsl(XrdOucStream &Config);
344static int xfsL(XrdOucStream &Config, char *val, int lix);
345static int xfso(XrdOucStream &Config);
346static int xgpf(XrdOucStream &Config);
347static int xprep(XrdOucStream &Config);
348static int xlog(XrdOucStream &Config);
349static int xmon(XrdOucStream &Config);
350static char *xmondest(const char *what, char *val);
351static int xmongs(XrdOucStream &Config);
352static bool xmongsend(XrdOucStream &Config, char *val, char *&dest,
353 int &opt, int &fmt, int &hdr);
354static int xred(XrdOucStream &Config);
355static int xred_clnt(XrdOucStream &Config, char *hP[2], int rPort[2]);
356static bool xred_php(char *val, char *hP[2], int rPort[2], const char *what,
357 bool optport=false);
358static void xred_set(RD_func func, char *rHost[2], int rPort[2]);
359static bool xred_xok(int func, char *rHost[2], int rPort[2]);
360static int xsecl(XrdOucStream &Config);
361static int xtls(XrdOucStream &Config);
362static int xtlsr(XrdOucStream &Config);
363static int xtrace(XrdOucStream &Config);
364static int xlimit(XrdOucStream &Config);
365
366 int ProcFAttr(char *faPath, char *faCgi, char *faArgs,
367 int faALen, int faCode, bool doAChk);
368 int XeqFADel(XrdSfsFACtl &ctl, char *faVars, int faVLen);
369 int XeqFAGet(XrdSfsFACtl &ctl, char *faVars, int faVLen);
370 int XeqFALsd(XrdSfsFACtl &ctl);
371 int XeqFALst(XrdSfsFACtl &ctl);
372 int XeqFASet(XrdSfsFACtl &ctl, char *faVars, int faVLen);
373
374static XrdObjectQ<XrdXrootdProtocol> ProtStack;
376
377protected:
378
379static unsigned int getSID();
380
381 void MonAuth();
382 int SetSF(kXR_char *fhandle, bool seton=false);
383
384static XrdXrootdXPath RPList; // Redirected paths
385static XrdXrootdXPath RQList; // Redirected paths for ENOENT
386static XrdXrootdXPath XPList; // Exported paths
387static XrdSfsFileSystem *osFS; // The filesystem
388static XrdSfsFileSystem *digFS; // The filesystem (digFS)
389static XrdSecService *CIA; // Authentication Server
390static XrdSecProtector *DHS; // Protection Server
391static XrdTlsContext *tlsCtx; // Protection Server TLS available
392static XrdXrootdFileLock *Locker; // File lock handler
393static XrdScheduler *Sched; // System scheduler
394static XrdBuffManager *BPool; // Buffer manager
395static XrdSysError &eDest; // Error message handler
396static XrdNetPMark *PMark; // Packet marking API
397static const char *myInst;
398static const char *TraceID;
399static int RQLxist; // Something is present in RQList
400static int myPID;
401static int myRole; // Role for kXR_protocol (>= 2.9.7)
402static int myRolf; // Role for kXR_protocol (< 2.9.7)
403
404static gid_t myGID;
405static uid_t myUID;
406static int myGNLen;
407static int myUNLen;
408static const char *myGName;
409static const char *myUName;
410static time_t keepT;
411
412// Admin control area
413//
415
416// Processing configuration values
417//
418static int hailWait;
419static int readWait;
420static int Port;
421static int Window;
422static int tlsPort;
423static char *Notify;
424static const char *myCName;
425static int myCNlen;
426static char isRedir;
427static char JobLCL;
428static char JobCKCGI;
430static char *JobCKT;
433static uint64_t fsFeatures;
434
435// Static redirection
436//
437static struct RD_Table {char *Host[2];
438 unsigned short Port[2];
439 short RDSz[2];} Route[RD_Num];
440
441static struct RC_Table {char *Domain[4];
442 short DomCnt;
443 bool pvtIP;
445
446static int OD_Stall;
447static bool OD_Bypass;
448static bool OD_Redir;
449
450static bool CL_Redir;
451
452static bool isProxy;
453
454// Extended attributes
455//
456static int usxMaxNsz;
457static int usxMaxVsz;
458static char *usxParms;
459
460// TLS configuration
461//
462static const char Req_TLSData = 0x01;
463static const char Req_TLSGPFile= 0x02;
464static const char Req_TLSLogin = 0x04;
465static const char Req_TLSSess = 0x08;
466static const char Req_TLSTPC = 0x10;
467
468static char tlsCap; // TLS requirements for capable clients
469static char tlsNot; // TLS requirements for incapable clients
470
471// Buffer configuration
472//
473static int maxBuffsz; // Maximum buffer size we can have
474static int maxTransz; // Maximum transfer size we can have
475static int maxReadv_ior; // Maximum readv element length
476
477// Statistical area
478//
480int numReads; // Count for kXR_read
481int numReadP; // Count for kXR_read pre-preads
482int numReadV; // Count for kkR_readv
483int numSegsV; // Count for kkR_readv segmens
484int numWritV; // Count for kkR_write
485int numSegsW; // Count for kkR_writev segmens
486int numWrites; // Count
487int numFiles; // Count
488
489int cumReads; // Count less numReads
490int cumReadP; // Count less numReadP
491int cumReadV; // Count less numReadV
492int cumSegsV; // Count less numSegsV
493int cumWritV; // Count less numWritV
494int cumSegsW; // Count less numSegsW
495int cumWrites; // Count less numWrites
496int myStalls; // Number of stalls
497long long totReadP; // Bytes
498
499// Data local to each protocol/link combination
500//
506int clientPV; // Protocol version + capabilities
507int clientRN; // Release as maj.min.patch (1 byte each).
508bool pmDone; // Packet marking has been enabled
509char reserved[3];
510short rdType;
512unsigned char CapVer;
513
514// Authentication area
515//
521
522// Request signing area
523//
524ClientRequest sigReq2Ver; // Request to verify
525SecurityRequest sigReq; // Signature request
526char sigBuff[64]; // Signature payload SHA256 + blowfish
527bool sigNeed; // Signature target present
528bool sigHere; // Signature request present
529bool sigRead; // Signature being read
530bool sigWarn; // Once for unneeded signature
531
532// Async I/O area, these need to be atomic
533//
534RAtomic_int linkAioReq; // Aio requests inflight for link
535static RAtomic_int srvrAioOps; // Aio operations inflight for server
536
537// Buffer information, used to drive getData(), and (*Resume)()
538//
540char *myBuff;
543
545{
548union {int iovAdj;
549 int BuffLen;
550 int DumpLen;
551 };
552bool useCB;
554unsigned char stalls;
556union {struct iovec *iovVec;
557 char *Buffer;
558 };
559const char *ioDType;
561
562static const int inNone = 0;
563static const int inCallBk = 1;
564static const int inData = 2;
565static const int inDataIov = 3;
566static const int inDump = 4;
567
568static const int Active = 1; // linkWait: thread is waiting for link
569static const int Terminate = 3; // linkWait: thread should immediately exit
570
572
574int (XrdXrootdProtocol::*ResumePio)(); //Used by Offload
577
578// Buffer resize control area
579//
580static int hcMax;
583 int hcNow;
585
586// This area is used for parallel streams
587//
588XrdSysMutex unbindMutex; // If locked always before streamMutex
593unsigned int mySID;
596bool isNOP;
598
599static const int maxPio = 4;
603
604short PathID; // Path for this protocol object
605bool newPio; // True when initially scheduled
606unsigned char rvSeq;
607unsigned char wvSeq;
608
609char doTLS; // TLS requirements for client
610bool ableTLS; // T->Client is able to use TLS
611bool isTLS; // T->Client using TLS on control stream
612
613// Track usage limts.
614//
615static bool PrepareAlt; // Use alternate prepare handling
616static bool LimitError; // Indicates that hitting a limit should result in an error response.
617 // If false, when possible, silently ignore errors.
619static int PrepareLimit;
620
621// Buffers to handle client requests
622//
626};
627#endif
XErrorCode
Definition XProtocol.hh:989
@ kXR_noErrorYet
unsigned char kXR_char
Definition XPtypes.hh:65
#define stat(a, b)
Definition XrdPosix.hh:101
XrdOucString Path
#define eMsg(x)
int emsg(int rc, char *msg)
class XrdBuffer * XrdSfsXioHandle
Definition XrdSfsXio.hh:46
static XrdXrootdStats * SI
static const char * myInst
int SendFile(int fildes) override
XrdXrootdProtocol * VerifyStream(int &rc, int pID, bool lok=true)
static XrdSfsFileSystem * digFS
int SetSF(kXR_char *fhandle, bool seton=false)
XrdSecProtect * Protect
int getData(gdCallBack *gdcbP, const char *dtype, struct iovec *iov, int iovn)
XrdNetPMark::Handle * pmHandle
static XrdNetPMark * PMark
XrdXrootdProtocol * Stream[maxStreams]
XrdXrootd::IOParms IO
static XrdXrootdXPath RPList
static XrdNetSocket * AdminSock
static const char Req_TLSGPFile
XrdProtocol * Match(XrdLink *lp) override
struct XrdXrootdProtocol::GetDataCtl gdCtl
void SetFD(int fildes) override
static const char Req_TLSSess
XrdXrootdWVInfo * wvInfo
XrdXrootdPgwCtl * pgwCtl
static void Reclaim(XrdSfsXioHandle h)
XrdSysSemaphore * reTry
XrdXrootdFileTable * FTab
static XrdXrootdJob * JobCKS
static XrdSysError & eDest
static unsigned int getSID()
XrdSecProtocol * AuthProt
int getData(gdCallBack *gdcbP, const char *dtype, char *buff, int blen)
XrdSfsXioHandle Claim(const char *buff, int datasz, int minasz=0) override
XrdXrootdMonitor::User Monitor
static const char * myCName
static const char Req_TLSData
XrdSfsXioHandle Swap(const char *buff, XrdSfsXioHandle h=0) override
static XrdXrootdFileLock * Locker
static const int maxPio
SecurityRequest sigReq
int(XrdXrootdProtocol::* Resume)()
static const char Req_TLSTPC
static XrdTlsContext * tlsCtx
static XrdXrootdXPath XPList
static XrdScheduler * Sched
static struct XrdXrootdProtocol::RC_Table RouteClient
int Process(XrdLink *lp) override
void Recycle(XrdLink *lp, int consec, const char *reason) override
static char * Buffer(XrdSfsXioHandle h, int *bsz)
static const char * myUName
static const char Req_TLSLogin
XrdXrootdResponse Response
int(XrdXrootdProtocol::* ResumePio)()
static const char * TraceID
static int Configure(char *parms, XrdProtocol_Config *pi)
int Stats(char *buff, int blen, int do_sync=0) override
static const int maxStreams
int getDump(const char *dtype, int dlen)
static XrdOucTList * JobCKTLST
static XrdXrootdXPath RQList
static struct XrdXrootdProtocol::RD_Table Route[RD_Num]
static XrdSecProtector * DHS
static XrdBuffManager * BPool
static XrdSecService * CIA
static RAtomic_int srvrAioOps
static const char * myGName
static uint64_t fsFeatures
static XrdOucReqID * PrepID
XrdXrootdPio * pioFirst
XrdSysCondVar2 * endNote
static XrdSfsFileSystem * osFS
XrdXrootdProtocol operator=(const XrdXrootdProtocol &rhs)=delete
virtual int gdDone()=0
XrdXrootd::gdCallBack * CallBack
static const int useSF
static const int useBasic
static const int useMMap