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) 2019 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 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cerrno>
34 #include <cstdint>
35 #include <vector>
36 
38 #include "XrdOuc/XrdOucIOVec.hh"
39 
40 struct stat;
41 class XrdOucEnv;
42 
43 /******************************************************************************/
44 /* X r d O u c C a c h e I O C B */
45 /******************************************************************************/
46 
47 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 
53 {
54 public:
55 
56 //------------------------------------------------------------------------------
62 //------------------------------------------------------------------------------
63 virtual
64 void Done(int result) = 0;
65 
67 virtual ~XrdOucCacheIOCB() {}
68 };
69 
70 /******************************************************************************/
71 /* X r d O u c C a c h e I O C D */
72 /******************************************************************************/
73 
74 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
80 
82 {
83 public:
84 
85 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 virtual
89 void DetachDone() = 0;
90 
92 virtual ~XrdOucCacheIOCD() {}
93 };
94 
95 /******************************************************************************/
96 /* C l a s s X r d O u c C a c h e I O */
97 /******************************************************************************/
98 
99 //------------------------------------------------------------------------------
102 //------------------------------------------------------------------------------
103 
105 {
106 public:
107 
108 //------------------------------------------------------------------------------
123 //------------------------------------------------------------------------------
124 
125 virtual bool Detach(XrdOucCacheIOCD &iocd) = 0;
126 
127 //------------------------------------------------------------------------------
131 //------------------------------------------------------------------------------
132 virtual
133 long long FSize() = 0;
134 
135 //------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------
147 
148 virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;}
149 
150 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 virtual
161 const char *Location(bool refresh=false) {(void)refresh; return "";}
162 
163 //------------------------------------------------------------------------------
167 //------------------------------------------------------------------------------
168 virtual
169 const char *Path() = 0;
170 
171 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
187 
188 static const uint64_t forceCS = 0x0000000000000001ULL;
189 
190 virtual int pgRead(char *buff,
191  long long offs,
192  int rdlen,
193  std::vector<uint32_t> &csvec,
194  uint64_t opts=0,
195  int *csfix=0);
196 
197 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
213 
214 virtual void pgRead(XrdOucCacheIOCB &iocb,
215  char *buff,
216  long long offs,
217  int rdlen,
218  std::vector<uint32_t> &csvec,
219  uint64_t opts=0,
220  int *csfix=0)
221  {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts, csfix));}
222 
223 //-----------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------
238 
239 virtual int pgWrite(char *buff,
240  long long offs,
241  int wrlen,
242  std::vector<uint32_t> &csvec,
243  uint64_t opts=0,
244  int *csfix=0);
245 
246 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
261 
262 virtual void pgWrite(XrdOucCacheIOCB &iocb,
263  char *buff,
264  long long offs,
265  int wrlen,
266  std::vector<uint32_t> &csvec,
267  uint64_t opts=0,
268  int *csfix=0)
269  {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts, csfix));}
270 
271 //------------------------------------------------------------------------------
277 //------------------------------------------------------------------------------
278 
279 static const int SingleUse = 0x0001;
280 
281 virtual void Preread(long long offs, int rlen, int opts=0)
282  {(void)offs; (void)rlen; (void)opts;}
283 
284 //-----------------------------------------------------------------------------
288 //-----------------------------------------------------------------------------
289 
290 struct aprParms
291  {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
292  int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
293  int Reserve1;
294  short minPages; // If rdln/pgsz < min, preread minPages (0->off)
295  signed
296  char minPerf; // Minimum auto preread performance required (0->n/a)
297  char Reserve2;
298  void *Reserve3;
299 
301  minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
302  };
303 
304 virtual void Preread(aprParms &Parms) { (void)Parms; }
305 
306 //------------------------------------------------------------------------------
316 //------------------------------------------------------------------------------
317 
318 virtual int Read (char *buff, long long offs, int rlen) = 0;
319 
320 //------------------------------------------------------------------------------
331 //------------------------------------------------------------------------------
332 
333 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
334  {iocb.Done(Read(buff, offs, rlen));}
335 
336 //------------------------------------------------------------------------------
344 //------------------------------------------------------------------------------
345 
346 virtual int ReadV(const XrdOucIOVec *readV, int rnum);
347 
348 //------------------------------------------------------------------------------
357 //------------------------------------------------------------------------------
358 
359 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
360  {iocb.Done(ReadV(readV, rnum));}
361 
362 //------------------------------------------------------------------------------
367 //------------------------------------------------------------------------------
368 
369 virtual int Sync() = 0;
370 
371 //------------------------------------------------------------------------------
378 //------------------------------------------------------------------------------
379 
380 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
381 
382 //------------------------------------------------------------------------------
389 //------------------------------------------------------------------------------
390 
391 virtual int Trunc(long long offs) = 0;
392 
393 //------------------------------------------------------------------------------
401 //------------------------------------------------------------------------------
402 
403 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
404  {iocb.Done(Trunc(offs));}
405 
406 //------------------------------------------------------------------------------
416 //------------------------------------------------------------------------------
417 
418 virtual void Update(XrdOucCacheIO &iocp) {}
419 
420 //------------------------------------------------------------------------------
430 //------------------------------------------------------------------------------
431 
432 virtual int Write(char *buff, long long offs, int wlen) = 0;
433 
434 //------------------------------------------------------------------------------
445 //------------------------------------------------------------------------------
446 
447 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
448  {iocb.Done(Write(buff, offs, wlen));}
449 
450 //------------------------------------------------------------------------------
458 //------------------------------------------------------------------------------
459 
460 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
461 
462 //------------------------------------------------------------------------------
471 //------------------------------------------------------------------------------
472 
473 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
474  {iocb.Done(WriteV(writV, wnum));}
475 
476 //------------------------------------------------------------------------------
478 //------------------------------------------------------------------------------
479 
481 protected:
482 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
483 };
484 
485 /******************************************************************************/
486 /* C l a s s X r d O u c C a c h e */
487 /******************************************************************************/
488 
489 //------------------------------------------------------------------------------
492 //------------------------------------------------------------------------------
493 
495 {
496 public:
497 
498 //------------------------------------------------------------------------------
514 //------------------------------------------------------------------------------
515 
516 static const int optFIS = 0x0001;
517 static const int optRW = 0x0004;
518 static const int optNEW = 0x0014;
519 static const int optWIN = 0x0024;
520 
521 virtual
523 
524 //------------------------------------------------------------------------------
568 //------------------------------------------------------------------------------
569 
571 
572 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
573  LFP_Reason why=ForAccess, bool forall=false)
574  {(void)url; (void)buff; (void)blen; (void)why;
575  (void)forall;
576  if (buff && blen > 0) *buff = 0;
577  return -ENOTSUP;
578  }
579 
580 //------------------------------------------------------------------------------
595 //------------------------------------------------------------------------------
596 
597 virtual int Prepare(const char *url, int oflags, mode_t mode)
598  {(void)url; (void)oflags; (void)mode; return 0;}
599 
600 //------------------------------------------------------------------------------
608 //------------------------------------------------------------------------------
609 
610 virtual int Rename(const char* oldp, const char* newp)
611  {(void)oldp; (void)newp; return 0;}
612 
613 //------------------------------------------------------------------------------
620 //------------------------------------------------------------------------------
621 
622 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
623 
624 //------------------------------------------------------------------------------
636 //------------------------------------------------------------------------------
637 
638 virtual int Stat(const char *url, struct stat &sbuff)
639  {(void)url; (void)sbuff; return 1;}
640 
641 //------------------------------------------------------------------------------
649 //------------------------------------------------------------------------------
650 
651 virtual int Truncate(const char* path, off_t size)
652  {(void)path; (void)size; return 0;}
653 
654 //------------------------------------------------------------------------------
661 //------------------------------------------------------------------------------
662 
663 virtual int Unlink(const char* path) {(void)path; return 0;}
664 
665 //------------------------------------------------------------------------------
674 //------------------------------------------------------------------------------
675 
676 enum XeqCmd {xeqNoop = 0};
677 
678 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
679  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
680 
681 //------------------------------------------------------------------------------
684 //------------------------------------------------------------------------------
685 
687 
688 //------------------------------------------------------------------------------
690 //------------------------------------------------------------------------------
691 
692 const char CacheType[8];
693 
694 //------------------------------------------------------------------------------
698 //------------------------------------------------------------------------------
699 
700  XrdOucCache(const char *ctype) : CacheType{}
701 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
702  {strncpy(const_cast<char *>(CacheType), ctype,
703  sizeof(CacheType));
704  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
705  }
706 
707 //------------------------------------------------------------------------------
709 //------------------------------------------------------------------------------
710 
711 virtual ~XrdOucCache() {}
712 };
713 
714 /******************************************************************************/
715 /* C r e a t i n g C a c h e P l u g - I n s */
716 /******************************************************************************/
717 
718 //------------------------------------------------------------------------------
750 
751 //------------------------------------------------------------------------------
756 //------------------------------------------------------------------------------
757 
765 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *Logger, const char *Config,
766  const char *Parms, XrdOucEnv *envP);
767 
768 #endif
int stat(const char *path, struct stat *buf)
struct myOpts opts
virtual void Done(int result)=0
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:67
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:92
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 Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:148
virtual int Write(char *buff, long long offs, int wlen)=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:418
virtual int Sync()=0
virtual const char * Location(bool refresh=false)
Definition: XrdOucCache.hh:161
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:279
static const uint64_t forceCS
Definition: XrdOucCache.hh:188
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:403
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:281
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:214
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:304
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:482
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:473
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:262
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:380
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:333
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:447
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:480
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:359
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:610
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:638
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:692
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:517
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:651
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:678
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:711
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:663
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
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:519
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:597
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:686
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:700
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:622
static const int optNEW
File is new -> optRW (o/w read or write)
Definition: XrdOucCache.hh:518
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:516
XrdCmsConfig Config
XrdSysLogger Logger
Definition: XrdGlobals.cc:47
XrdOucEnv * envP
Definition: XrdPss.cc:109