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 <errno.h>
34 
36 #include "XrdOuc/XrdOucIOVec.hh"
37 
38 struct stat;
39 class XrdOucEnv;
40 
41 /******************************************************************************/
42 /* X r d O u c C a c h e I O C B */
43 /******************************************************************************/
44 
45 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 
51 {
52 public:
53 
54 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
61 virtual
62 void Done(int result) = 0;
63 
65 virtual ~XrdOucCacheIOCB() {}
66 };
67 
68 /******************************************************************************/
69 /* X r d O u c C a c h e I O C D */
70 /******************************************************************************/
71 
72 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
78 
80 {
81 public:
82 
83 //------------------------------------------------------------------------------
85 //------------------------------------------------------------------------------
86 virtual
87 void DetachDone() = 0;
88 
90 virtual ~XrdOucCacheIOCD() {}
91 };
92 
93 /******************************************************************************/
94 /* C l a s s X r d O u c C a c h e I O */
95 /******************************************************************************/
96 
97 //------------------------------------------------------------------------------
100 //------------------------------------------------------------------------------
101 
103 {
104 public:
105 
106 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
122 
123 virtual bool Detach(XrdOucCacheIOCD &iocd) = 0;
124 
125 //------------------------------------------------------------------------------
129 //------------------------------------------------------------------------------
130 virtual
131 long long FSize() = 0;
132 
133 //------------------------------------------------------------------------------
144 //------------------------------------------------------------------------------
145 
146 virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;}
147 
148 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------
154 virtual
155 const char *Location() {return "";}
156 
157 //------------------------------------------------------------------------------
161 //------------------------------------------------------------------------------
162 virtual
163 const char *Path() = 0;
164 
165 //-----------------------------------------------------------------------------
180 //-----------------------------------------------------------------------------
181 
182 virtual int pgRead(char *buff,
183  long long offs,
184  int rdlen,
185  uint32_t *csvec,
186  uint64_t opts=0);
187 
188 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
205 
206 virtual void pgRead(XrdOucCacheIOCB &iocb,
207  char *buff,
208  long long offs,
209  int rdlen,
210  uint32_t *csvec,
211  uint64_t opts=0)
212  {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts));}
213 
214 //-----------------------------------------------------------------------------
231 //-----------------------------------------------------------------------------
232 
233 virtual int pgWrite(char *buff,
234  long long offs,
235  int rdlen,
236  uint32_t *csvec,
237  uint64_t opts=0);
238 
239 //-----------------------------------------------------------------------------
257 //-----------------------------------------------------------------------------
258 
259 virtual void pgWrite(XrdOucCacheIOCB &iocb,
260  char *buff,
261  long long offs,
262  int wrlen,
263  uint32_t *csvec,
264  uint64_t opts=0)
265  {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts));}
266 
267 //------------------------------------------------------------------------------
273 //------------------------------------------------------------------------------
274 
275 static const int SingleUse = 0x0001;
276 
277 virtual void Preread(long long offs, int rlen, int opts=0)
278  {(void)offs; (void)rlen; (void)opts;}
279 
280 //-----------------------------------------------------------------------------
284 //-----------------------------------------------------------------------------
285 
286 struct aprParms
287  {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
288  int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
289  int Reserve1;
290  short minPages; // If rdln/pgsz < min, preread minPages (0->off)
291  signed
292  char minPerf; // Minimum auto preread performance required (0->n/a)
293  char Reserve2;
294  void *Reserve3;
295 
297  minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
298  };
299 
300 virtual void Preread(aprParms &Parms) { (void)Parms; }
301 
302 //------------------------------------------------------------------------------
312 //------------------------------------------------------------------------------
313 
314 virtual int Read (char *buff, long long offs, int rlen) = 0;
315 
316 //------------------------------------------------------------------------------
327 //------------------------------------------------------------------------------
328 
329 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
330  {iocb.Done(Read(buff, offs, rlen));}
331 
332 //------------------------------------------------------------------------------
340 //------------------------------------------------------------------------------
341 
342 virtual int ReadV(const XrdOucIOVec *readV, int rnum);
343 
344 //------------------------------------------------------------------------------
353 //------------------------------------------------------------------------------
354 
355 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
356  {iocb.Done(ReadV(readV, rnum));}
357 
358 //------------------------------------------------------------------------------
363 //------------------------------------------------------------------------------
364 
365 virtual int Sync() = 0;
366 
367 //------------------------------------------------------------------------------
374 //------------------------------------------------------------------------------
375 
376 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
377 
378 //------------------------------------------------------------------------------
385 //------------------------------------------------------------------------------
386 
387 virtual int Trunc(long long offs) = 0;
388 
389 //------------------------------------------------------------------------------
400 //------------------------------------------------------------------------------
401 
402 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
403  {iocb.Done(Trunc(offs));}
404 
405 //------------------------------------------------------------------------------
415 //------------------------------------------------------------------------------
416 
417 virtual void Update(XrdOucCacheIO &iocp) {}
418 
419 //------------------------------------------------------------------------------
429 //------------------------------------------------------------------------------
430 
431 virtual int Write(char *buff, long long offs, int wlen) = 0;
432 
433 //------------------------------------------------------------------------------
444 //------------------------------------------------------------------------------
445 
446 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
447  {iocb.Done(Write(buff, offs, wlen));}
448 
449 //------------------------------------------------------------------------------
457 //------------------------------------------------------------------------------
458 
459 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
460 
461 //------------------------------------------------------------------------------
470 //------------------------------------------------------------------------------
471 
472 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
473  {iocb.Done(WriteV(writV, wnum));}
474 
475 //------------------------------------------------------------------------------
477 //------------------------------------------------------------------------------
478 
480 protected:
481 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
482 };
483 
484 /******************************************************************************/
485 /* C l a s s X r d O u c C a c h e */
486 /******************************************************************************/
487 
488 //------------------------------------------------------------------------------
491 //------------------------------------------------------------------------------
492 
494 {
495 public:
496 
497 //------------------------------------------------------------------------------
513 //------------------------------------------------------------------------------
514 
515 static const int optFIS = 0x0001;
516 static const int optRW = 0x0004;
517 static const int optNEW = 0x0014;
518 static const int optWIN = 0x0024;
519 
520 virtual
521 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0;
522 
523 //------------------------------------------------------------------------------
567 //------------------------------------------------------------------------------
568 
570 
571 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
572  LFP_Reason why=ForAccess, bool forall=false)
573  {(void)url; (void)buff; (void)blen; (void)why;
574  (void)forall;
575  if (buff && blen > 0) *buff = 0;
576  return -ENOTSUP;
577  }
578 
579 //------------------------------------------------------------------------------
594 //------------------------------------------------------------------------------
595 
596 virtual int Prepare(const char *url, int oflags, mode_t mode)
597  {(void)url; (void)oflags; (void)mode; return 0;}
598 
599 //------------------------------------------------------------------------------
607 //------------------------------------------------------------------------------
608 
609 virtual int Rename(const char* oldp, const char* newp)
610  {(void)oldp; (void)newp; return 0;}
611 
612 //------------------------------------------------------------------------------
619 //------------------------------------------------------------------------------
620 
621 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
622 
623 //------------------------------------------------------------------------------
635 //------------------------------------------------------------------------------
636 
637 virtual int Stat(const char *url, struct stat &sbuff)
638  {(void)url; (void)sbuff; return 1;}
639 
640 //------------------------------------------------------------------------------
648 //------------------------------------------------------------------------------
649 
650 virtual int Truncate(const char* path, off_t size)
651  {(void)path; (void)size; return 0;}
652 
653 //------------------------------------------------------------------------------
660 //------------------------------------------------------------------------------
661 
662 virtual int Unlink(const char* path) {(void)path; return 0;}
663 
664 //------------------------------------------------------------------------------
673 //------------------------------------------------------------------------------
674 
675 enum XeqCmd {xeqNoop = 0};
676 
677 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
678  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
679 
680 //------------------------------------------------------------------------------
683 //------------------------------------------------------------------------------
684 
686 
687 //------------------------------------------------------------------------------
689 //------------------------------------------------------------------------------
690 
691 const char CacheType[8];
692 
693 //------------------------------------------------------------------------------
697 //------------------------------------------------------------------------------
698 
699  XrdOucCache(const char *ctype) : CacheType{}
700 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
701  {strncpy(const_cast<char *>(CacheType), ctype,
702  sizeof(CacheType));
703  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
704  }
705 
706 //------------------------------------------------------------------------------
708 //------------------------------------------------------------------------------
709 
710 virtual ~XrdOucCache() {}
711 };
712 
713 /******************************************************************************/
714 /* C r e a t i n g C a c h e P l u g - I n s */
715 /******************************************************************************/
716 
717 //------------------------------------------------------------------------------
744 
745 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *,
746  const char *, XrdOucEnv *);
747 
748 //------------------------------------------------------------------------------
753 //------------------------------------------------------------------------------
754 
760 #endif
XrdOucCache::XeqCmd
XeqCmd
Definition: XrdOucCache.hh:675
XrdOucCache::optNEW
static const int optNEW
File is new -> optRW (o/w read or write)
Definition: XrdOucCache.hh:517
XrdOucCacheIOCB::XrdOucCacheIOCB
XrdOucCacheIOCB()
Definition: XrdOucCache.hh:64
XrdOucCache::Stat
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:637
XrdOucCacheIO
Definition: XrdOucCache.hh:103
XrdOucCache::Attach
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
XrdOucCacheIO::~XrdOucCacheIO
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:481
XrdOucCacheIO::XrdOucCacheIO
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:479
XrdOucCache::Unlink
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:662
XrdOucCache
Definition: XrdOucCache.hh:494
XrdOucCacheIOCD::DetachDone
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
XrdOucCacheIO::Read
virtual int Read(char *buff, long long offs, int rlen)=0
XrdOucCacheIO::Path
virtual const char * Path()=0
XrdOucCacheIO::FSize
virtual long long FSize()=0
XrdOucCache::Truncate
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:650
XrdOucCache::Rename
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:609
XrdOucCacheIO::Detach
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
XrdOucCacheIO::Preread
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:277
XrdOucCacheIO::pgRead
virtual int pgRead(char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
XrdOucCacheIO::ReadV
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
XrdOucIOVec
Definition: XrdOucIOVec.hh:41
XrdOucCacheIO::aprParms::Reserve1
int Reserve1
Definition: XrdOucCache.hh:289
XrdOucCache::ForInfo
@ ForInfo
Definition: XrdOucCache.hh:569
XrdOucCacheIO::aprParms::Trigger
int Trigger
Definition: XrdOucCache.hh:287
XrdOucCache::ForAccess
@ ForAccess
Definition: XrdOucCache.hh:569
XrdOucCacheIO::Trunc
virtual int Trunc(long long offs)=0
XrdOucCacheIO::Update
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:417
XrdOucCache::Rmdir
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:621
XrdOucCacheIO::SingleUse
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:275
XrdOucCacheIO::Fstat
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:146
XrdOucCacheIO::pgWrite
virtual int pgWrite(char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
XrdOucEnv
Definition: XrdOucEnv.hh:42
XrdOucIOVec.hh
XrdOucCacheIO::pgRead
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:206
XrdOucCacheIO::aprParms::minPages
short minPages
Definition: XrdOucCache.hh:290
XrdOucCache::Statistics
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:685
XrdOucCacheIO::Preread
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:300
XrdOucCacheIOCD
Definition: XrdOucCache.hh:80
XrdOucCache::LFP_Reason
LFP_Reason
Definition: XrdOucCache.hh:569
XrdOucCacheStats.hh
XrdOucCacheIO::Write
virtual int Write(char *buff, long long offs, int wlen)=0
XrdSysLogger
Definition: XrdSysLogger.hh:53
XrdOucCacheIO::Location
virtual const char * Location()
Definition: XrdOucCache.hh:155
XrdOucCache::CacheType
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:691
XrdOucCache::LocalFilePath
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition: XrdOucCache.hh:571
XrdOucCacheIOCD::XrdOucCacheIOCD
XrdOucCacheIOCD()
Definition: XrdOucCache.hh:89
XrdOucCacheIO::pgWrite
virtual void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, uint32_t *csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:259
XrdOucCacheIO::aprParms
Definition: XrdOucCache.hh:287
XrdOucCacheStats
Definition: XrdOucCacheStats.hh:44
XrdOucCache::optFIS
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:515
XrdOucCacheIO::aprParms::prRecalc
int prRecalc
Definition: XrdOucCache.hh:288
XrdOucCache::XrdOucCache
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:699
XrdOucCache::~XrdOucCache
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:710
XrdOucCacheIO::aprParms::minPerf
signed char minPerf
Definition: XrdOucCache.hh:292
XrdOucCacheIOCB::Done
virtual void Done(int result)=0
XrdOucCacheIO::aprParms::Reserve2
char Reserve2
Definition: XrdOucCache.hh:293
XrdOucCacheIO::Sync
virtual int Sync()=0
XrdOucCache::xeqNoop
@ xeqNoop
Definition: XrdOucCache.hh:675
XrdOucCacheIO::WriteV
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:472
XrdOucCacheIOCB
Definition: XrdOucCache.hh:51
stat
#define stat(a, b)
Definition: XrdPosix.hh:96
XrdOucCacheIOCD::~XrdOucCacheIOCD
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:90
XrdOucCacheIO::aprParms::Reserve3
void * Reserve3
Definition: XrdOucCache.hh:294
XrdOucCache::ForPath
@ ForPath
Definition: XrdOucCache.hh:569
XrdOucCache::optWIN
static const int optWIN
File is new -> optRW use write-in cache.
Definition: XrdOucCache.hh:518
XrdOucCacheIOCB::~XrdOucCacheIOCB
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:65
XrdOucCache::optRW
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:516
XrdOucCacheIO::WriteV
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
XrdOucCache::Xeq
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:677
XrdOucCache::Prepare
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:596
XrdOucCacheIO::aprParms::aprParms
aprParms()
Definition: XrdOucCache.hh:296