xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 //------------------------------------------------------------------------------
404 //------------------------------------------------------------------------------
405 
406 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
407  {iocb.Done(Trunc(offs));}
408 
409 //------------------------------------------------------------------------------
419 //------------------------------------------------------------------------------
420 
421 virtual void Update(XrdOucCacheIO &iocp) {}
422 
423 //------------------------------------------------------------------------------
433 //------------------------------------------------------------------------------
434 
435 virtual int Write(char *buff, long long offs, int wlen) = 0;
436 
437 //------------------------------------------------------------------------------
448 //------------------------------------------------------------------------------
449 
450 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
451  {iocb.Done(Write(buff, offs, wlen));}
452 
453 //------------------------------------------------------------------------------
461 //------------------------------------------------------------------------------
462 
463 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
464 
465 //------------------------------------------------------------------------------
474 //------------------------------------------------------------------------------
475 
476 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
477  {iocb.Done(WriteV(writV, wnum));}
478 
479 //------------------------------------------------------------------------------
481 //------------------------------------------------------------------------------
482 
484 protected:
485 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
486 };
487 
488 /******************************************************************************/
489 /* C l a s s X r d O u c C a c h e */
490 /******************************************************************************/
491 
492 //------------------------------------------------------------------------------
495 //------------------------------------------------------------------------------
496 
498 {
499 public:
500 
501 //------------------------------------------------------------------------------
517 //------------------------------------------------------------------------------
518 
519 static const int optFIS = 0x0001;
520 static const int optRW = 0x0004;
521 static const int optNEW = 0x0014;
522 static const int optWIN = 0x0024;
523 
524 virtual
525 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0;
526 
527 //------------------------------------------------------------------------------
571 //------------------------------------------------------------------------------
572 
574 
575 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
576  LFP_Reason why=ForAccess, bool forall=false)
577  {(void)url; (void)buff; (void)blen; (void)why;
578  (void)forall;
579  if (buff && blen > 0) *buff = 0;
580  return -ENOTSUP;
581  }
582 
583 //------------------------------------------------------------------------------
598 //------------------------------------------------------------------------------
599 
600 virtual int Prepare(const char *url, int oflags, mode_t mode)
601  {(void)url; (void)oflags; (void)mode; return 0;}
602 
603 //------------------------------------------------------------------------------
611 //------------------------------------------------------------------------------
612 
613 virtual int Rename(const char* oldp, const char* newp)
614  {(void)oldp; (void)newp; return 0;}
615 
616 //------------------------------------------------------------------------------
623 //------------------------------------------------------------------------------
624 
625 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
626 
627 //------------------------------------------------------------------------------
639 //------------------------------------------------------------------------------
640 
641 virtual int Stat(const char *url, struct stat &sbuff)
642  {(void)url; (void)sbuff; return 1;}
643 
644 //------------------------------------------------------------------------------
652 //------------------------------------------------------------------------------
653 
654 virtual int Truncate(const char* path, off_t size)
655  {(void)path; (void)size; return 0;}
656 
657 //------------------------------------------------------------------------------
664 //------------------------------------------------------------------------------
665 
666 virtual int Unlink(const char* path) {(void)path; return 0;}
667 
668 //------------------------------------------------------------------------------
677 //------------------------------------------------------------------------------
678 
679 enum XeqCmd {xeqNoop = 0};
680 
681 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
682  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
683 
684 //------------------------------------------------------------------------------
687 //------------------------------------------------------------------------------
688 
690 
691 //------------------------------------------------------------------------------
693 //------------------------------------------------------------------------------
694 
695 const char CacheType[8];
696 
697 //------------------------------------------------------------------------------
701 //------------------------------------------------------------------------------
702 
703  XrdOucCache(const char *ctype) : CacheType{}
704 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
705  {strncpy(const_cast<char *>(CacheType), ctype,
706  sizeof(CacheType));
707  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
708  }
709 
710 //------------------------------------------------------------------------------
712 //------------------------------------------------------------------------------
713 
714 virtual ~XrdOucCache() {}
715 };
716 
717 /******************************************************************************/
718 /* C r e a t i n g C a c h e P l u g - I n s */
719 /******************************************************************************/
720 
721 //------------------------------------------------------------------------------
748 
749 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *,
750  const char *, XrdOucEnv *);
751 
752 //------------------------------------------------------------------------------
757 //------------------------------------------------------------------------------
758 
764 #endif
virtual const char * Location(bool refresh=false)
Definition: XrdOucCache.hh:161
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:641
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:304
void * Reserve3
Definition: XrdOucCache.hh:298
Definition: XrdOucCache.hh:573
virtual int Trunc(long long offs)=0
Definition: XrdOucCache.hh:573
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:279
aprParms()
Definition: XrdOucCache.hh:300
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:92
int Reserve1
Definition: XrdOucCache.hh:293
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:654
Definition: XrdOucCache.hh:104
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.hh:359
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:666
static const int optNEW
File is new -&gt; optRW (o/w read or write)
Definition: XrdOucCache.hh:521
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:613
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:476
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:333
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:689
short minPages
Definition: XrdOucCache.hh:294
Definition: XrdOucCache.hh:81
char Reserve2
Definition: XrdOucCache.hh:297
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:625
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
LFP_Reason
Definition: XrdOucCache.hh:573
Definition: XrdOucCache.hh:497
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:519
virtual const char * Path()=0
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:406
Definition: XrdOucEnv.hh:41
Definition: XrdOucIOVec.hh:40
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:485
Definition: XrdOucCache.hh:573
j template void())
Definition: XrdOucJson.hh:4121
Definition: XrdOucCache.hh:290
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:703
Definition: XrdOucCache.hh:52
Definition: XrdSysLogger.hh:52
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:380
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
#define stat(a, b)
Definition: XrdPosix.hh:96
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:281
virtual int Sync()=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:421
int Trigger
Definition: XrdOucCache.hh:291
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition: XrdOucCache.hh:575
static const int optWIN
File is new -&gt; optRW use write-in cache.
Definition: XrdOucCache.hh:522
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:681
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
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:520
static const uint64_t forceCS
Definition: XrdOucCache.hh:188
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:148
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:600
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:483
Definition: XrdOucCacheStats.hh:43
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:695
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:714
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:450
virtual long long FSize()=0
virtual int Write(char *buff, long long offs, int wlen)=0
XrdOucCacheIOCD()
Definition: XrdOucCache.hh:91
int prRecalc
Definition: XrdOucCache.hh:292
Definition: XrdOucCache.hh:679
signed char minPerf
Definition: XrdOucCache.hh:296
XeqCmd
Definition: XrdOucCache.hh:679
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:67
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
XrdOucCacheIOCB()
Definition: XrdOucCache.hh:66
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 void Done(int result)=0