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 
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 //------------------------------------------------------------------------------
563 //------------------------------------------------------------------------------
564 
566 
567 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
568  LFP_Reason why=ForAccess)
569  {(void)url; (void)buff; (void)blen; (void)why;
570  if (buff && blen > 0) *buff = 0;
571  return -ENOTSUP;
572  }
573 
574 //------------------------------------------------------------------------------
589 //------------------------------------------------------------------------------
590 
591 virtual int Prepare(const char *url, int oflags, mode_t mode)
592  {(void)url; (void)oflags; (void)mode; return 0;}
593 
594 //------------------------------------------------------------------------------
602 //------------------------------------------------------------------------------
603 
604 virtual int Rename(const char* oldp, const char* newp)
605  {(void)oldp; (void)newp; return 0;}
606 
607 //------------------------------------------------------------------------------
614 //------------------------------------------------------------------------------
615 
616 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
617 
618 //------------------------------------------------------------------------------
630 //------------------------------------------------------------------------------
631 
632 virtual int Stat(const char *url, struct stat &sbuff)
633  {(void)url; (void)sbuff; return 1;}
634 
635 //------------------------------------------------------------------------------
643 //------------------------------------------------------------------------------
644 
645 virtual int Truncate(const char* path, off_t size)
646  {(void)path; (void)size; return 0;}
647 
648 //------------------------------------------------------------------------------
655 //------------------------------------------------------------------------------
656 
657 virtual int Unlink(const char* path) {(void)path; return 0;}
658 
659 //------------------------------------------------------------------------------
668 //------------------------------------------------------------------------------
669 
670 enum XeqCmd {xeqNoop = 0};
671 
672 virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
673  {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
674 
675 //------------------------------------------------------------------------------
678 //------------------------------------------------------------------------------
679 
681 
682 //------------------------------------------------------------------------------
684 //------------------------------------------------------------------------------
685 
686 const char CacheType[8];
687 
688 //------------------------------------------------------------------------------
692 //------------------------------------------------------------------------------
693 
694  XrdOucCache(const char *ctype) : CacheType{}
695 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
696  {strncpy(const_cast<char *>(CacheType), ctype,
697  sizeof(CacheType));
698  const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
699  }
700 
701 //------------------------------------------------------------------------------
703 //------------------------------------------------------------------------------
704 
705 virtual ~XrdOucCache() {}
706 };
707 
708 /******************************************************************************/
709 /* C r e a t i n g C a c h e P l u g - I n s */
710 /******************************************************************************/
711 
712 //------------------------------------------------------------------------------
739 
740 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *,
741  const char *, XrdOucEnv *);
742 
743 //------------------------------------------------------------------------------
748 //------------------------------------------------------------------------------
749 
755 #endif
virtual int Stat(const char *url, struct stat &sbuff)
Definition: XrdOucCache.hh:632
virtual void Preread(aprParms &Parms)
Definition: XrdOucCache.hh:300
void * Reserve3
Definition: XrdOucCache.hh:294
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:275
aprParms()
Definition: XrdOucCache.hh:296
virtual ~XrdOucCacheIOCD()
Definition: XrdOucCache.hh:90
int Reserve1
Definition: XrdOucCache.hh:289
virtual int Truncate(const char *path, off_t size)
Definition: XrdOucCache.hh:645
Definition: XrdOucCache.hh:102
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
Definition: XrdOucCache.hh:355
virtual int Unlink(const char *path)
Definition: XrdOucCache.hh:657
static const int optNEW
File is new -&gt; optRW (o/w read or write)
Definition: XrdOucCache.hh:517
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Rename(const char *oldp, const char *newp)
Definition: XrdOucCache.hh:604
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess)
Definition: XrdOucCache.hh:567
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
Definition: XrdOucCache.hh:472
virtual int pgRead(char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
Definition: XrdOucCache.hh:329
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
XrdOucCacheStats Statistics
Definition: XrdOucCache.hh:680
short minPages
Definition: XrdOucCache.hh:290
Definition: XrdOucCache.hh:79
char Reserve2
Definition: XrdOucCache.hh:293
virtual int Rmdir(const char *dirp)
Definition: XrdOucCache.hh:616
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
LFP_Reason
Definition: XrdOucCache.hh:565
Definition: XrdOucCache.hh:493
static const int optFIS
File is structured (e.g. root file)
Definition: XrdOucCache.hh:515
virtual const char * Path()=0
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
Definition: XrdOucCache.hh:402
Definition: XrdOucEnv.hh:41
Definition: XrdOucIOVec.hh:40
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, uint32_t *csvec, uint64_t opts=0)
Definition: XrdOucCache.hh:206
virtual ~XrdOucCacheIO()
Definition: XrdOucCache.hh:481
Definition: XrdOucCache.hh:565
Definition: XrdOucCache.hh:286
XrdOucCache(const char *ctype)
Definition: XrdOucCache.hh:694
Definition: XrdOucCache.hh:50
Definition: XrdSysLogger.hh:52
virtual void Sync(XrdOucCacheIOCB &iocb)
Definition: XrdOucCache.hh:376
#define stat(a, b)
Definition: XrdPosix.hh:96
virtual void Preread(long long offs, int rlen, int opts=0)
Definition: XrdOucCache.hh:277
virtual int Sync()=0
virtual void Update(XrdOucCacheIO &iocp)
Definition: XrdOucCache.hh:417
int Trigger
Definition: XrdOucCache.hh:287
static const int optWIN
File is new -&gt; optRW use write-in cache.
Definition: XrdOucCache.hh:518
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
Definition: XrdOucCache.hh:672
static const int optRW
File is read/write (o/w read/only)
Definition: XrdOucCache.hh:516
virtual int Fstat(struct stat &sbuff)
Definition: XrdOucCache.hh:146
virtual int Prepare(const char *url, int oflags, mode_t mode)
Definition: XrdOucCache.hh:591
XrdOucCacheIO()
Construct and Destructor.
Definition: XrdOucCache.hh:479
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:686
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual ~XrdOucCache()
Destructor.
Definition: XrdOucCache.hh:705
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:446
virtual long long FSize()=0
virtual int Write(char *buff, long long offs, int wlen)=0
XrdOucCacheIOCD()
Definition: XrdOucCache.hh:89
virtual const char * Location()
Definition: XrdOucCache.hh:155
int prRecalc
Definition: XrdOucCache.hh:288
Definition: XrdOucCache.hh:670
signed char minPerf
Definition: XrdOucCache.hh:292
XeqCmd
Definition: XrdOucCache.hh:670
virtual ~XrdOucCacheIOCB()
Definition: XrdOucCache.hh:65
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:259
XrdOucCacheIOCB()
Definition: XrdOucCache.hh:64
virtual void Done(int result)=0