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 #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 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
188 
189 static const uint64_t forceCS = 0x0000000000000001ULL;
190 
191 virtual int pgRead(char *buff,
192  long long offs,
193  int rdlen,
194  std::vector<uint32_t> &csvec,
195  uint64_t opts=0);
196 
197 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
214 
215 virtual void pgRead(XrdOucCacheIOCB &iocb,
216  char *buff,
217  long long offs,
218  int rdlen,
219  std::vector<uint32_t> &csvec,
220  uint64_t opts=0)
221  {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts));}
222 
223 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
241 
242 virtual int pgWrite(char *buff,
243  long long offs,
244  int rdlen,
245  uint32_t *csvec,
246  uint64_t opts=0);
247 
248 //-----------------------------------------------------------------------------
266 //-----------------------------------------------------------------------------
267 
268 virtual void pgWrite(XrdOucCacheIOCB &iocb,
269  char *buff,
270  long long offs,
271  int wrlen,
272  uint32_t *csvec,
273  uint64_t opts=0)
274  {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts));}
275 
276 //------------------------------------------------------------------------------
282 //------------------------------------------------------------------------------
283 
284 static const int SingleUse = 0x0001;
285 
286 virtual void Preread(long long offs, int rlen, int opts=0)
287  {(void)offs; (void)rlen; (void)opts;}
288 
289 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
294 
295 struct aprParms
296  {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
297  int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
298  int Reserve1;
299  short minPages; // If rdln/pgsz < min, preread minPages (0->off)
300  signed
301  char minPerf; // Minimum auto preread performance required (0->n/a)
302  char Reserve2;
303  void *Reserve3;
304 
306  minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
307  };
308 
309 virtual void Preread(aprParms &Parms) { (void)Parms; }
310 
311 //------------------------------------------------------------------------------
321 //------------------------------------------------------------------------------
322 
323 virtual int Read (char *buff, long long offs, int rlen) = 0;
324 
325 //------------------------------------------------------------------------------
336 //------------------------------------------------------------------------------
337 
338 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
339  {iocb.Done(Read(buff, offs, rlen));}
340 
341 //------------------------------------------------------------------------------
349 //------------------------------------------------------------------------------
350 
351 virtual int ReadV(const XrdOucIOVec *readV, int rnum);
352 
353 //------------------------------------------------------------------------------
362 //------------------------------------------------------------------------------
363 
364 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
365  {iocb.Done(ReadV(readV, rnum));}
366 
367 //------------------------------------------------------------------------------
372 //------------------------------------------------------------------------------
373 
374 virtual int Sync() = 0;
375 
376 //------------------------------------------------------------------------------
383 //------------------------------------------------------------------------------
384 
385 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
386 
387 //------------------------------------------------------------------------------
394 //------------------------------------------------------------------------------
395 
396 virtual int Trunc(long long offs) = 0;
397 
398 //------------------------------------------------------------------------------
409 //------------------------------------------------------------------------------
410 
411 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
412  {iocb.Done(Trunc(offs));}
413 
414 //------------------------------------------------------------------------------
424 //------------------------------------------------------------------------------
425 
426 virtual void Update(XrdOucCacheIO &iocp) {}
427 
428 //------------------------------------------------------------------------------
438 //------------------------------------------------------------------------------
439 
440 virtual int Write(char *buff, long long offs, int wlen) = 0;
441 
442 //------------------------------------------------------------------------------
453 //------------------------------------------------------------------------------
454 
455 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
456  {iocb.Done(Write(buff, offs, wlen));}
457 
458 //------------------------------------------------------------------------------
466 //------------------------------------------------------------------------------
467 
468 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
469 
470 //------------------------------------------------------------------------------
479 //------------------------------------------------------------------------------
480 
481 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
482  {iocb.Done(WriteV(writV, wnum));}
483 
484 //------------------------------------------------------------------------------
486 //------------------------------------------------------------------------------
487 
489 protected:
490 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
491 };
492 
493 /******************************************************************************/
494 /* C l a s s X r d O u c C a c h e */
495 /******************************************************************************/
496 
497 //------------------------------------------------------------------------------
500 //------------------------------------------------------------------------------
501 
503 {
504 public:
505 
506 //------------------------------------------------------------------------------
522 //------------------------------------------------------------------------------
523 
524 static const int optFIS = 0x0001;
525 static const int optRW = 0x0004;
526 static const int optNEW = 0x0014;
527 static const int optWIN = 0x0024;
528 
529 virtual
530 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0;
531 
532 //------------------------------------------------------------------------------
576 //------------------------------------------------------------------------------
577 
579 
580 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
581  LFP_Reason why=ForAccess, bool forall=false)
582  {(void)url; (void)buff; (void)blen; (void)why;
583  (void)forall;
584  if (buff && blen > 0) *buff = 0;
585  return -ENOTSUP;
586  }
587 
588 //------------------------------------------------------------------------------
603 //------------------------------------------------------------------------------
604 
605 virtual int Prepare(const char *url, int oflags, mode_t mode)
606  {(void)url; (void)oflags; (void)mode; return 0;}
607 
608 //------------------------------------------------------------------------------
616 //------------------------------------------------------------------------------
617 
618 virtual int Rename(const char* oldp, const char* newp)
619  {(void)oldp; (void)newp; return 0;}
620 
621 //------------------------------------------------------------------------------
628 //------------------------------------------------------------------------------
629 
630 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
631 
632 //------------------------------------------------------------------------------
644 //------------------------------------------------------------------------------
645 
646 virtual int Stat(const char *url, struct stat &sbuff)
647  {(void)url; (void)sbuff; return 1;}
648 
649 //------------------------------------------------------------------------------
657 //------------------------------------------------------------------------------
658 
659 virtual int Truncate(const char* path, off_t size)
660  {(void)path; (void)size; return 0;}
661 
662 //------------------------------------------------------------------------------
669 //------------------------------------------------------------------------------
670 
671 virtual int Unlink(const char* path) {(void)path; return 0;}
672 
673 //------------------------------------------------------------------------------
682 //------------------------------------------------------------------------------
683 
684 enum XeqCmd {xeqNoop = 0};
685 
686 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
687  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
688 
689 //------------------------------------------------------------------------------
692 //------------------------------------------------------------------------------
693 
695 
696 //------------------------------------------------------------------------------
698 //------------------------------------------------------------------------------
699 
700 const char CacheType[8];
701 
702 //------------------------------------------------------------------------------
706 //------------------------------------------------------------------------------
707 
708  XrdOucCache(const char *ctype) : CacheType{}
709 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
710  {strncpy(const_cast<char *>(CacheType), ctype,
711  sizeof(CacheType));
712  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
713  }
714 
715 //------------------------------------------------------------------------------
717 //------------------------------------------------------------------------------
718 
719 virtual ~XrdOucCache() {}
720 };
721 
722 /******************************************************************************/
723 /* C r e a t i n g C a c h e P l u g - I n s */
724 /******************************************************************************/
725 
726 //------------------------------------------------------------------------------
753 
754 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *,
755  const char *, XrdOucEnv *);
756 
757 //------------------------------------------------------------------------------
762 //------------------------------------------------------------------------------
763 
769 #endif
virtual const char * Location(bool refresh=false)
Definition: XrdOucCache.hh:161
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:646
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:309
void * Reserve3
Definition: XrdOucCache.hh:303
Definition: XrdOucCache.hh:578
virtual int Trunc(long long offs)=0
Definition: XrdOucCache.hh:578
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:284
aprParms()
Definition: XrdOucCache.hh:305
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:92
int Reserve1
Definition: XrdOucCache.hh:298
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:659
Definition: XrdOucCache.hh:104
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.hh:364
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:671
static const int optNEW
File is new -> optRW (o/w read or write)
Definition: XrdOucCache.hh:526
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:618
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:481
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:338
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:694
short minPages
Definition: XrdOucCache.hh:299
Definition: XrdOucCache.hh:81
char Reserve2
Definition: XrdOucCache.hh:302
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:630
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
LFP_Reason
Definition: XrdOucCache.hh:578
Definition: XrdOucCache.hh:502
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:524
virtual const char * Path()=0
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:411
Definition: XrdOucEnv.hh:41
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:215
Definition: XrdOucIOVec.hh:40
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:490
Definition: XrdOucCache.hh:578
Definition: XrdOucCache.hh:295
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:708
Definition: XrdOucCache.hh:52
Definition: XrdSysLogger.hh:52
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:385
#define stat(a, b)
Definition: XrdPosix.hh:96
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:286
virtual int Sync()=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:426
int Trigger
Definition: XrdOucCache.hh:296
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition: XrdOucCache.hh:580
static const int optWIN
File is new -> optRW use write-in cache.
Definition: XrdOucCache.hh:527
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:686
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:525
static const uint64_t forceCS
Definition: XrdOucCache.hh:189
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:148
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:605
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:488
virtual int pgWrite(char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
Definition: XrdOucCacheStats.hh:43
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:700
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:719
virtual int Read(char *buff, long long offs, int rlen)=0
virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
Definition: XrdOucCache.hh:455
virtual long long FSize()=0
virtual int Write(char *buff, long long offs, int wlen)=0
XrdOucCacheIOCD()
Definition: XrdOucCache.hh:91
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0)
int prRecalc
Definition: XrdOucCache.hh:297
Definition: XrdOucCache.hh:684
signed char minPerf
Definition: XrdOucCache.hh:301
XeqCmd
Definition: XrdOucCache.hh:684
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:67
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
virtual void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, uint32_t *csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:268
XrdOucCacheIOCB()
Definition: XrdOucCache.hh:66
virtual void Done(int result)=0