XRootD
XrdOucCache.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCCACHE_HH__
2 #define __XRDOUCCACHE_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c C a c h e . h h */
6 /* */
7 /* (c) 2026 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <cerrno>
33 #include <cstdint>
34 #include <string>
35 #include <vector>
36 
38 #include "XrdOuc/XrdOucIOVec.hh"
39 #include "XrdOuc/XrdOucRange.hh"
40 
41 struct stat;
42 class XrdOucEnv;
43 
44 /******************************************************************************/
45 /* X r d O u c C a c h e I O C B */
46 /******************************************************************************/
47 
48 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
52 
54 {
55 public:
56 
57 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64 virtual
65 void Done(int result) = 0;
66 
68 virtual ~XrdOucCacheIOCB() {}
69 };
70 
71 /******************************************************************************/
72 /* X r d O u c C a c h e I O C D */
73 /******************************************************************************/
74 
75 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 
83 {
84 public:
85 
86 //------------------------------------------------------------------------------
88 //------------------------------------------------------------------------------
89 virtual
90 void DetachDone() = 0;
91 
93 virtual ~XrdOucCacheIOCD() {}
94 };
95 
96 /******************************************************************************/
97 /* X r d O u c C a c h e O p */
98 /******************************************************************************/
99 
101  {enum Code {QFinfo = 0, // Requires a file target
102  QFSinfo = 1 // Requires a global target
103  };
104  };
105 
106 /******************************************************************************/
107 /* C l a s s X r d O u c C a c h e I O */
108 /******************************************************************************/
109 
110 //------------------------------------------------------------------------------
113 //------------------------------------------------------------------------------
114 
116 {
117 public:
118 
119 //------------------------------------------------------------------------------
134 //------------------------------------------------------------------------------
135 
136 virtual bool Detach(XrdOucCacheIOCD &iocd) = 0;
137 
138 //------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------
147 
148 virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string& args,
149  std::string& resp)
150  {resp = "Function not supported";
151  return -ENOTSUP;
152  }
153 
154 //------------------------------------------------------------------------------
158 //------------------------------------------------------------------------------
159 virtual
160 long long FSize() = 0;
161 
162 //------------------------------------------------------------------------------
173 //------------------------------------------------------------------------------
174 
175 virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;}
176 
177 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
187 virtual
188 const char *Location(bool refresh=false) {(void)refresh; return "";}
189 
190 //------------------------------------------------------------------------------
194 //------------------------------------------------------------------------------
195 virtual
196 const char *Path() = 0;
197 
198 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
214 
215 static const uint64_t forceCS = 0x0000000000000001ULL;
216 
217 virtual int pgRead(char *buff,
218  long long offs,
219  int rdlen,
220  std::vector<uint32_t> &csvec,
221  uint64_t opts=0,
222  int *csfix=0);
223 
224 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
240 
241 virtual void pgRead(XrdOucCacheIOCB &iocb,
242  char *buff,
243  long long offs,
244  int rdlen,
245  std::vector<uint32_t> &csvec,
246  uint64_t opts=0,
247  int *csfix=0)
248  {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts, csfix));}
249 
250 //-----------------------------------------------------------------------------
264 //-----------------------------------------------------------------------------
265 
266 virtual int pgWrite(char *buff,
267  long long offs,
268  int wrlen,
269  std::vector<uint32_t> &csvec,
270  uint64_t opts=0,
271  int *csfix=0);
272 
273 //-----------------------------------------------------------------------------
287 //-----------------------------------------------------------------------------
288 
289 virtual void pgWrite(XrdOucCacheIOCB &iocb,
290  char *buff,
291  long long offs,
292  int wrlen,
293  std::vector<uint32_t> &csvec,
294  uint64_t opts=0,
295  int *csfix=0)
296  {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts, csfix));}
297 
298 //------------------------------------------------------------------------------
304 //------------------------------------------------------------------------------
305 
306 static const int SingleUse = 0x0001;
307 
308 virtual void Preread(long long offs, int rlen, int opts=0)
309  {(void)offs; (void)rlen; (void)opts;}
310 
311 //------------------------------------------------------------------------------
315 //------------------------------------------------------------------------------
316 
317 virtual void Preread(XrdOucRangeList& rlist)
318  {for (auto it = rlist.begin(); it != rlist.end(); it++)
319  Preread(it->offset, it->size);
320  }
321 
322 //-----------------------------------------------------------------------------
326 //-----------------------------------------------------------------------------
327 
328 struct aprParms
329  {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
330  int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
331  int Reserve1;
332  short minPages; // If rdln/pgsz < min, preread minPages (0->off)
333  signed
334  char minPerf; // Minimum auto preread performance required (0->n/a)
335  char Reserve2;
336  void *Reserve3;
337 
339  minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
340  };
341 
342 virtual void Preread(aprParms &Parms) { (void)Parms; }
343 
344 //------------------------------------------------------------------------------
354 //------------------------------------------------------------------------------
355 
356 virtual int Read (char *buff, long long offs, int rlen) = 0;
357 
358 //------------------------------------------------------------------------------
369 //------------------------------------------------------------------------------
370 
371 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
372  {iocb.Done(Read(buff, offs, rlen));}
373 
374 //------------------------------------------------------------------------------
382 //------------------------------------------------------------------------------
383 
384 virtual int ReadV(const XrdOucIOVec *readV, int rnum);
385 
386 //------------------------------------------------------------------------------
395 //------------------------------------------------------------------------------
396 
397 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
398  {iocb.Done(ReadV(readV, rnum));}
399 
400 //------------------------------------------------------------------------------
405 //------------------------------------------------------------------------------
406 
407 virtual int Sync() = 0;
408 
409 //------------------------------------------------------------------------------
416 //------------------------------------------------------------------------------
417 
418 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
419 
420 //------------------------------------------------------------------------------
427 //------------------------------------------------------------------------------
428 
429 virtual int Trunc(long long offs) = 0;
430 
431 //------------------------------------------------------------------------------
439 //------------------------------------------------------------------------------
440 
441 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
442  {iocb.Done(Trunc(offs));}
443 
444 //------------------------------------------------------------------------------
454 //------------------------------------------------------------------------------
455 
456 virtual void Update(XrdOucCacheIO &iocp) {}
457 
458 //------------------------------------------------------------------------------
468 //------------------------------------------------------------------------------
469 
470 virtual int Write(char *buff, long long offs, int wlen) = 0;
471 
472 //------------------------------------------------------------------------------
483 //------------------------------------------------------------------------------
484 
485 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
486  {iocb.Done(Write(buff, offs, wlen));}
487 
488 //------------------------------------------------------------------------------
496 //------------------------------------------------------------------------------
497 
498 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
499 
500 //------------------------------------------------------------------------------
509 //------------------------------------------------------------------------------
510 
511 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
512  {iocb.Done(WriteV(writV, wnum));}
513 
514 //------------------------------------------------------------------------------
516 //------------------------------------------------------------------------------
517 
519 protected:
520 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
521 };
522 
523 /******************************************************************************/
524 /* C l a s s X r d O u c C a c h e */
525 /******************************************************************************/
526 
527 //------------------------------------------------------------------------------
530 //------------------------------------------------------------------------------
531 
533 {
534 public:
535 
536 //------------------------------------------------------------------------------
552 //------------------------------------------------------------------------------
553 
554 static const int optFIS = 0x0001;
555 static const int optRW = 0x0004;
556 static const int optNEW = 0x0014;
557 static const int optWIN = 0x0024;
558 
559 virtual
561 
562 //------------------------------------------------------------------------------
570 //------------------------------------------------------------------------------
571 
572 virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string& args,
573  std::string& resp)
574  {resp = "Function not supported";
575  return -ENOTSUP;
576  }
577 
578 //------------------------------------------------------------------------------
622 //------------------------------------------------------------------------------
623 
625 
626 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
627  LFP_Reason why=ForAccess, bool forall=false)
628  {(void)url; (void)buff; (void)blen; (void)why;
629  (void)forall;
630  if (buff && blen > 0) *buff = 0;
631  return -ENOTSUP;
632  }
633 
634 //------------------------------------------------------------------------------
649 //------------------------------------------------------------------------------
650 
651 virtual int Prepare(const char *url, int oflags, mode_t mode)
652  {(void)url; (void)oflags; (void)mode; return 0;}
653 
654 //------------------------------------------------------------------------------
662 //------------------------------------------------------------------------------
663 
664 virtual int Rename(const char* oldp, const char* newp)
665  {(void)oldp; (void)newp; return 0;}
666 
667 //------------------------------------------------------------------------------
674 //------------------------------------------------------------------------------
675 
676 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
677 
678 //------------------------------------------------------------------------------
690 //------------------------------------------------------------------------------
691 
692 virtual int Stat(const char *url, struct stat &sbuff)
693  {(void)url; (void)sbuff; return 1;}
694 
695 //------------------------------------------------------------------------------
703 //------------------------------------------------------------------------------
704 
705 virtual int Truncate(const char* path, off_t size)
706  {(void)path; (void)size; return 0;}
707 
708 //------------------------------------------------------------------------------
715 //------------------------------------------------------------------------------
716 
717 virtual int Unlink(const char* path) {(void)path; return 0;}
718 
719 //------------------------------------------------------------------------------
728 //------------------------------------------------------------------------------
729 
730 enum XeqCmd {xeqNoop = 0};
731 
732 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
733  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
734 
735 //------------------------------------------------------------------------------
738 //------------------------------------------------------------------------------
739 
741 
742 //------------------------------------------------------------------------------
744 //------------------------------------------------------------------------------
745 
746 const char CacheType[8];
747 
748 //------------------------------------------------------------------------------
752 //------------------------------------------------------------------------------
753 
754  XrdOucCache(const char *ctype) : CacheType{}
755 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
756  {strncpy(const_cast<char *>(CacheType), ctype,
757  sizeof(CacheType));
758  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
759  }
760 
761 //------------------------------------------------------------------------------
763 //------------------------------------------------------------------------------
764 
765 virtual ~XrdOucCache() {}
766 };
767 
768 /******************************************************************************/
769 /* C r e a t i n g C a c h e P l u g - I n s */
770 /******************************************************************************/
771 
772 //------------------------------------------------------------------------------
804 
805 //------------------------------------------------------------------------------
810 //------------------------------------------------------------------------------
811 
819 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *Logger, const char *Config,
820  const char *Parms, XrdOucEnv *envP);
821 
822 #endif
std::vector< XrdOucRange > XrdOucRangeList
Definition: XrdOucRange.hh:57
#define stat(a, b)
Definition: XrdPosix.hh:105
struct myOpts opts
virtual void Done(int result)=0
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:68
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:93
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
virtual const char * Path()=0
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.cc:103
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string &args, std::string &resp)
Definition: XrdOucCache.hh:148
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:175
virtual int Write(char *buff, long long offs, int wlen)=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:456
virtual int Sync()=0
virtual const char * Location(bool refresh=false)
Definition: XrdOucCache.hh:188
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:306
static const uint64_t forceCS
Definition: XrdOucCache.hh:215
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:441
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:308
virtual long long FSize()=0
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition: XrdOucCache.hh:241
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:342
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:520
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:511
virtual void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition: XrdOucCache.hh:289
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:418
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:371
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition: XrdOucCache.cc:39
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
Definition: XrdOucCache.cc:68
virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
Definition: XrdOucCache.hh:485
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:518
virtual void Preread(XrdOucRangeList &rlist)
Definition: XrdOucCache.hh:317
virtual int Trunc(long long offs)=0
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.cc:86
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.hh:397
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:664
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:692
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:746
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:555
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:705
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:732
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:765
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:717
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition: XrdOucCache.hh:626
virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string &args, std::string &resp)
Definition: XrdOucCache.hh:572
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
static const int optWIN
File is new -> optRW use write-in cache.
Definition: XrdOucCache.hh:557
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:651
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:740
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:754
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:676
static const int optNEW
File is new -> optRW (o/w read or write)
Definition: XrdOucCache.hh:556
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:554
XrdCmsConfig Config
XrdSysLogger Logger
Definition: XrdGlobals.cc:47
XrdOucEnv * envP
Definition: XrdPss.cc:110