xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
186 
187 static const uint64_t forceCS = 0x0000000000000001ULL;
188 
189 virtual int pgRead(char *buff,
190  long long offs,
191  int rdlen,
192  std::vector<uint32_t> &csvec,
193  uint64_t opts=0);
194 
195 //-----------------------------------------------------------------------------
209 //-----------------------------------------------------------------------------
210 
211 virtual void pgRead(XrdOucCacheIOCB &iocb,
212  char *buff,
213  long long offs,
214  int rdlen,
215  std::vector<uint32_t> &csvec,
216  uint64_t opts=0)
217  {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts));}
218 
219 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
233 
234 virtual int pgWrite(char *buff,
235  long long offs,
236  int wrlen,
237  std::vector<uint32_t> &csvec,
238  uint64_t opts=0);
239 
240 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
254 
255 virtual void pgWrite(XrdOucCacheIOCB &iocb,
256  char *buff,
257  long long offs,
258  int wrlen,
259  std::vector<uint32_t> &csvec,
260  uint64_t opts=0)
261  {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts));}
262 
263 //------------------------------------------------------------------------------
269 //------------------------------------------------------------------------------
270 
271 static const int SingleUse = 0x0001;
272 
273 virtual void Preread(long long offs, int rlen, int opts=0)
274  {(void)offs; (void)rlen; (void)opts;}
275 
276 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
281 
282 struct aprParms
283  {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
284  int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
285  int Reserve1;
286  short minPages; // If rdln/pgsz < min, preread minPages (0->off)
287  signed
288  char minPerf; // Minimum auto preread performance required (0->n/a)
289  char Reserve2;
290  void *Reserve3;
291 
293  minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
294  };
295 
296 virtual void Preread(aprParms &Parms) { (void)Parms; }
297 
298 //------------------------------------------------------------------------------
308 //------------------------------------------------------------------------------
309 
310 virtual int Read (char *buff, long long offs, int rlen) = 0;
311 
312 //------------------------------------------------------------------------------
323 //------------------------------------------------------------------------------
324 
325 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
326  {iocb.Done(Read(buff, offs, rlen));}
327 
328 //------------------------------------------------------------------------------
336 //------------------------------------------------------------------------------
337 
338 virtual int ReadV(const XrdOucIOVec *readV, int rnum);
339 
340 //------------------------------------------------------------------------------
349 //------------------------------------------------------------------------------
350 
351 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
352  {iocb.Done(ReadV(readV, rnum));}
353 
354 //------------------------------------------------------------------------------
359 //------------------------------------------------------------------------------
360 
361 virtual int Sync() = 0;
362 
363 //------------------------------------------------------------------------------
370 //------------------------------------------------------------------------------
371 
372 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
373 
374 //------------------------------------------------------------------------------
381 //------------------------------------------------------------------------------
382 
383 virtual int Trunc(long long offs) = 0;
384 
385 //------------------------------------------------------------------------------
396 //------------------------------------------------------------------------------
397 
398 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
399  {iocb.Done(Trunc(offs));}
400 
401 //------------------------------------------------------------------------------
411 //------------------------------------------------------------------------------
412 
413 virtual void Update(XrdOucCacheIO &iocp) {}
414 
415 //------------------------------------------------------------------------------
425 //------------------------------------------------------------------------------
426 
427 virtual int Write(char *buff, long long offs, int wlen) = 0;
428 
429 //------------------------------------------------------------------------------
440 //------------------------------------------------------------------------------
441 
442 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
443  {iocb.Done(Write(buff, offs, wlen));}
444 
445 //------------------------------------------------------------------------------
453 //------------------------------------------------------------------------------
454 
455 virtual int WriteV(const XrdOucIOVec *writV, int wnum);
456 
457 //------------------------------------------------------------------------------
466 //------------------------------------------------------------------------------
467 
468 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
469  {iocb.Done(WriteV(writV, wnum));}
470 
471 //------------------------------------------------------------------------------
473 //------------------------------------------------------------------------------
474 
476 protected:
477 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
478 };
479 
480 /******************************************************************************/
481 /* C l a s s X r d O u c C a c h e */
482 /******************************************************************************/
483 
484 //------------------------------------------------------------------------------
487 //------------------------------------------------------------------------------
488 
490 {
491 public:
492 
493 //------------------------------------------------------------------------------
509 //------------------------------------------------------------------------------
510 
511 static const int optFIS = 0x0001;
512 static const int optRW = 0x0004;
513 static const int optNEW = 0x0014;
514 static const int optWIN = 0x0024;
515 
516 virtual
517 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0;
518 
519 //------------------------------------------------------------------------------
563 //------------------------------------------------------------------------------
564 
566 
567 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
568  LFP_Reason why=ForAccess, bool forall=false)
569  {(void)url; (void)buff; (void)blen; (void)why;
570  (void)forall;
571  if (buff && blen > 0) *buff = 0;
572  return -ENOTSUP;
573  }
574 
575 //------------------------------------------------------------------------------
590 //------------------------------------------------------------------------------
591 
592 virtual int Prepare(const char *url, int oflags, mode_t mode)
593  {(void)url; (void)oflags; (void)mode; return 0;}
594 
595 //------------------------------------------------------------------------------
603 //------------------------------------------------------------------------------
604 
605 virtual int Rename(const char* oldp, const char* newp)
606  {(void)oldp; (void)newp; return 0;}
607 
608 //------------------------------------------------------------------------------
615 //------------------------------------------------------------------------------
616 
617 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
618 
619 //------------------------------------------------------------------------------
631 //------------------------------------------------------------------------------
632 
633 virtual int Stat(const char *url, struct stat &sbuff)
634  {(void)url; (void)sbuff; return 1;}
635 
636 //------------------------------------------------------------------------------
644 //------------------------------------------------------------------------------
645 
646 virtual int Truncate(const char* path, off_t size)
647  {(void)path; (void)size; return 0;}
648 
649 //------------------------------------------------------------------------------
656 //------------------------------------------------------------------------------
657 
658 virtual int Unlink(const char* path) {(void)path; return 0;}
659 
660 //------------------------------------------------------------------------------
669 //------------------------------------------------------------------------------
670 
671 enum XeqCmd {xeqNoop = 0};
672 
673 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
674  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
675 
676 //------------------------------------------------------------------------------
679 //------------------------------------------------------------------------------
680 
682 
683 //------------------------------------------------------------------------------
685 //------------------------------------------------------------------------------
686 
687 const char CacheType[8];
688 
689 //------------------------------------------------------------------------------
693 //------------------------------------------------------------------------------
694 
695  XrdOucCache(const char *ctype) : CacheType{}
696 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
697  {strncpy(const_cast<char *>(CacheType), ctype,
698  sizeof(CacheType));
699  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
700  }
701 
702 //------------------------------------------------------------------------------
704 //------------------------------------------------------------------------------
705 
706 virtual ~XrdOucCache() {}
707 };
708 
709 /******************************************************************************/
710 /* C r e a t i n g C a c h e P l u g - I n s */
711 /******************************************************************************/
712 
713 //------------------------------------------------------------------------------
740 
741 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *,
742  const char *, XrdOucEnv *);
743 
744 //------------------------------------------------------------------------------
749 //------------------------------------------------------------------------------
750 
756 #endif
virtual const char * Location(bool refresh=false)
Definition: XrdOucCache.hh:161
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:633
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:296
void * Reserve3
Definition: XrdOucCache.hh:290
Definition: XrdOucCache.hh:565
virtual int Trunc(long long offs)=0
Definition: XrdOucCache.hh:565
static const int SingleUse
Mark pages for single use.
Definition: XrdOucCache.hh:271
aprParms()
Definition: XrdOucCache.hh:292
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:92
int Reserve1
Definition: XrdOucCache.hh:285
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:646
Definition: XrdOucCache.hh:104
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0)
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.hh:351
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:658
static const int optNEW
File is new -&gt; optRW (o/w read or write)
Definition: XrdOucCache.hh:513
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:605
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:468
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:325
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:681
short minPages
Definition: XrdOucCache.hh:286
Definition: XrdOucCache.hh:81
char Reserve2
Definition: XrdOucCache.hh:289
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:617
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
LFP_Reason
Definition: XrdOucCache.hh:565
Definition: XrdOucCache.hh:489
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:511
virtual const char * Path()=0
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:398
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:211
Definition: XrdOucIOVec.hh:40
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:477
Definition: XrdOucCache.hh:565
Definition: XrdOucCache.hh:282
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:695
Definition: XrdOucCache.hh:52
Definition: XrdSysLogger.hh:52
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:372
#define stat(a, b)
Definition: XrdPosix.hh:96
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:273
virtual int Sync()=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:413
int Trigger
Definition: XrdOucCache.hh:283
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
Definition: XrdOucCache.hh:567
static const int optWIN
File is new -&gt; optRW use write-in cache.
Definition: XrdOucCache.hh:514
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:673
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:512
static const uint64_t forceCS
Definition: XrdOucCache.hh:187
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:148
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:592
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:475
Definition: XrdOucCacheStats.hh:43
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
Definition: XrdOucCache.hh:687
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:706
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:442
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:284
Definition: XrdOucCache.hh:671
signed char minPerf
Definition: XrdOucCache.hh:288
XeqCmd
Definition: XrdOucCache.hh:671
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, std::vector< uint32_t > &csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:255
XrdOucCacheIOCB()
Definition: XrdOucCache.hh:66
virtual void Done(int result)=0