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