XRootD
Loading...
Searching...
No Matches
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) 2026 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/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <cerrno>
33#include <cstdint>
34#include <string>
35#include <vector>
36
38#include "XrdOuc/XrdOucIOVec.hh"
39#include "XrdOuc/XrdOucRange.hh"
40
41struct stat;
42class XrdOucEnv;
43
44/******************************************************************************/
45/* X r d O u c C a c h e I O C B */
46/******************************************************************************/
47
48//-----------------------------------------------------------------------------
51//-----------------------------------------------------------------------------
52
54{
55public:
56
57//------------------------------------------------------------------------------
63//------------------------------------------------------------------------------
64virtual
65void Done(int result) = 0;
66
68virtual ~XrdOucCacheIOCB() {}
69};
70
71/******************************************************************************/
72/* X r d O u c C a c h e I O C D */
73/******************************************************************************/
74
75//-----------------------------------------------------------------------------
80//-----------------------------------------------------------------------------
81
83{
84public:
85
86//------------------------------------------------------------------------------
88//------------------------------------------------------------------------------
89virtual
90void DetachDone() = 0;
91
93virtual ~XrdOucCacheIOCD() {}
94};
95
96/******************************************************************************/
97/* X r d O u c C a c h e O p */
98/******************************************************************************/
99
101 {enum Code {QFinfo = 0, // Requires a file target
102 QFSinfo = 1 // Requires a global target
103 };
104 };
105
106/******************************************************************************/
107/* C l a s s X r d O u c C a c h e I O */
108/******************************************************************************/
109
110//------------------------------------------------------------------------------
113//------------------------------------------------------------------------------
114
116{
117public:
118
119//------------------------------------------------------------------------------
134//------------------------------------------------------------------------------
135
136virtual bool Detach(XrdOucCacheIOCD &iocd) = 0;
137
138//------------------------------------------------------------------------------
146//------------------------------------------------------------------------------
147
148virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string& args,
149 std::string& resp)
150 {resp = "Function not supported";
151 return -ENOTSUP;
152 }
153
154//------------------------------------------------------------------------------
158//------------------------------------------------------------------------------
159virtual
160long long FSize() = 0;
161
162//------------------------------------------------------------------------------
173//------------------------------------------------------------------------------
174
175virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;}
176
177//-----------------------------------------------------------------------------
186//-----------------------------------------------------------------------------
187virtual
188const char *Location(bool refresh=false) {(void)refresh; return "";}
189
190//------------------------------------------------------------------------------
194//------------------------------------------------------------------------------
195virtual
196const char *Path() = 0;
197
198//-----------------------------------------------------------------------------
213//-----------------------------------------------------------------------------
214
215static const uint64_t forceCS = 0x0000000000000001ULL;
216
217virtual int pgRead(char *buff,
218 long long offs,
219 int rdlen,
220 std::vector<uint32_t> &csvec,
221 uint64_t opts=0,
222 int *csfix=0);
223
224//-----------------------------------------------------------------------------
239//-----------------------------------------------------------------------------
240
241virtual void pgRead(XrdOucCacheIOCB &iocb,
242 char *buff,
243 long long offs,
244 int rdlen,
245 std::vector<uint32_t> &csvec,
246 uint64_t opts=0,
247 int *csfix=0)
248 {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts, csfix));}
249
250//-----------------------------------------------------------------------------
264//-----------------------------------------------------------------------------
265
266virtual int pgWrite(char *buff,
267 long long offs,
268 int wrlen,
269 std::vector<uint32_t> &csvec,
270 uint64_t opts=0,
271 int *csfix=0);
272
273//-----------------------------------------------------------------------------
287//-----------------------------------------------------------------------------
288
289virtual void pgWrite(XrdOucCacheIOCB &iocb,
290 char *buff,
291 long long offs,
292 int wrlen,
293 std::vector<uint32_t> &csvec,
294 uint64_t opts=0,
295 int *csfix=0)
296 {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts, csfix));}
297
298//------------------------------------------------------------------------------
304//------------------------------------------------------------------------------
305
306static const int SingleUse = 0x0001;
307
308virtual void Preread(long long offs, int rlen, int opts=0)
309 {(void)offs; (void)rlen; (void)opts;}
310
311//------------------------------------------------------------------------------
315//------------------------------------------------------------------------------
316
317virtual void Preread(XrdOucRangeList& rlist)
318 {for (auto it = rlist.begin(); it != rlist.end(); it++)
319 Preread(it->offset, it->size);
320 }
321
322//-----------------------------------------------------------------------------
326//-----------------------------------------------------------------------------
327
329 {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1)
330 int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M)
332 short minPages; // If rdln/pgsz < min, preread minPages (0->off)
333 signed
334 char minPerf; // Minimum auto preread performance required (0->n/a)
336 void *Reserve3;
337
339 minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {}
340 };
341
342virtual void Preread(aprParms &Parms) { (void)Parms; }
343
344//------------------------------------------------------------------------------
354//------------------------------------------------------------------------------
355
356virtual int Read (char *buff, long long offs, int rlen) = 0;
357
358//------------------------------------------------------------------------------
369//------------------------------------------------------------------------------
370
371virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
372 {iocb.Done(Read(buff, offs, rlen));}
373
374//------------------------------------------------------------------------------
382//------------------------------------------------------------------------------
383
384virtual int ReadV(const XrdOucIOVec *readV, int rnum);
385
386//------------------------------------------------------------------------------
395//------------------------------------------------------------------------------
396
397virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
398 {iocb.Done(ReadV(readV, rnum));}
399
400//------------------------------------------------------------------------------
405//------------------------------------------------------------------------------
406
407virtual int Sync() = 0;
408
409//------------------------------------------------------------------------------
416//------------------------------------------------------------------------------
417
418virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());}
419
420//------------------------------------------------------------------------------
427//------------------------------------------------------------------------------
428
429virtual int Trunc(long long offs) = 0;
430
431//------------------------------------------------------------------------------
439//------------------------------------------------------------------------------
440
441virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
442 {iocb.Done(Trunc(offs));}
443
444//------------------------------------------------------------------------------
454//------------------------------------------------------------------------------
455
456virtual void Update(XrdOucCacheIO &iocp) {}
457
458//------------------------------------------------------------------------------
468//------------------------------------------------------------------------------
469
470virtual int Write(char *buff, long long offs, int wlen) = 0;
471
472//------------------------------------------------------------------------------
483//------------------------------------------------------------------------------
484
485virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
486 {iocb.Done(Write(buff, offs, wlen));}
487
488//------------------------------------------------------------------------------
496//------------------------------------------------------------------------------
497
498virtual int WriteV(const XrdOucIOVec *writV, int wnum);
499
500//------------------------------------------------------------------------------
509//------------------------------------------------------------------------------
510
511virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
512 {iocb.Done(WriteV(writV, wnum));}
513
514//------------------------------------------------------------------------------
516//------------------------------------------------------------------------------
517
519protected:
520virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete!
521};
522
523/******************************************************************************/
524/* C l a s s X r d O u c C a c h e */
525/******************************************************************************/
526
527//------------------------------------------------------------------------------
530//------------------------------------------------------------------------------
531
533{
534public:
535
536//------------------------------------------------------------------------------
552//------------------------------------------------------------------------------
553
554static const int optFIS = 0x0001;
555static const int optRW = 0x0004;
556static const int optNEW = 0x0014;
557static const int optWIN = 0x0024;
558
559virtual
561
562//------------------------------------------------------------------------------
570//------------------------------------------------------------------------------
571
572virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string& args,
573 std::string& resp)
574 {resp = "Function not supported";
575 return -ENOTSUP;
576 }
577
578//------------------------------------------------------------------------------
622//------------------------------------------------------------------------------
623
625
626virtual int LocalFilePath(const char *url, char *buff=0, int blen=0,
627 LFP_Reason why=ForAccess, bool forall=false)
628 {(void)url; (void)buff; (void)blen; (void)why;
629 (void)forall;
630 if (buff && blen > 0) *buff = 0;
631 return -ENOTSUP;
632 }
633
634//------------------------------------------------------------------------------
649//------------------------------------------------------------------------------
650
651virtual int Prepare(const char *url, int oflags, mode_t mode)
652 {(void)url; (void)oflags; (void)mode; return 0;}
653
654//------------------------------------------------------------------------------
662//------------------------------------------------------------------------------
663
664virtual int Rename(const char* oldp, const char* newp)
665 {(void)oldp; (void)newp; return 0;}
666
667//------------------------------------------------------------------------------
674//------------------------------------------------------------------------------
675
676virtual int Rmdir(const char* dirp) {(void)dirp; return 0;}
677
678//------------------------------------------------------------------------------
690//------------------------------------------------------------------------------
691
692virtual int Stat(const char *url, struct stat &sbuff)
693 {(void)url; (void)sbuff; return 1;}
694
695//------------------------------------------------------------------------------
703//------------------------------------------------------------------------------
704
705virtual int Truncate(const char* path, off_t size)
706 {(void)path; (void)size; return 0;}
707
708//------------------------------------------------------------------------------
715//------------------------------------------------------------------------------
716
717virtual int Unlink(const char* path) {(void)path; return 0;}
718
719//------------------------------------------------------------------------------
728//------------------------------------------------------------------------------
729
730enum XeqCmd {xeqNoop = 0};
731
732virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
733 {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;}
734
735//------------------------------------------------------------------------------
738//------------------------------------------------------------------------------
739
741
742//------------------------------------------------------------------------------
744//------------------------------------------------------------------------------
745
746const char CacheType[8];
747
748//------------------------------------------------------------------------------
752//------------------------------------------------------------------------------
753
754 XrdOucCache(const char *ctype) : CacheType{}
755// : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'})
756 {strncpy(const_cast<char *>(CacheType), ctype,
757 sizeof(CacheType));
758 const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0;
759 }
760
761//------------------------------------------------------------------------------
763//------------------------------------------------------------------------------
764
765virtual ~XrdOucCache() {}
766};
767
768/******************************************************************************/
769/* C r e a t i n g C a c h e P l u g - I n s */
770/******************************************************************************/
771
772//------------------------------------------------------------------------------
804
805//------------------------------------------------------------------------------
810//------------------------------------------------------------------------------
811
818
819typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *Logger, const char *Config,
820 const char *Parms, XrdOucEnv *envP);
821
822#endif
static XrdSysLogger Logger
std::vector< XrdOucRange > XrdOucRangeList
#define stat(a, b)
Definition XrdPosix.hh:101
struct myOpts opts
virtual void Done(int result)=0
virtual ~XrdOucCacheIOCB()
virtual ~XrdOucCacheIOCD()
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string &args, std::string &resp)
virtual int Fstat(struct stat &sbuff)
virtual int Write(char *buff, long long offs, int wlen)=0
virtual void Update(XrdOucCacheIO &iocp)
virtual int Sync()=0
static const int SingleUse
Mark pages for single use.
static const uint64_t forceCS
virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs)
virtual void Preread(long long offs, int rlen, int opts=0)
virtual long long FSize()=0
virtual void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual const char * Path()=0
virtual void Preread(aprParms &Parms)
virtual ~XrdOucCacheIO()
virtual const char * Location(bool refresh=false)
virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum)
virtual void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual bool Detach(XrdOucCacheIOCD &iocd)=0
virtual void Sync(XrdOucCacheIOCB &iocb)
virtual void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen)
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen)
XrdOucCacheIO()
Construct and Destructor.
virtual void Preread(XrdOucRangeList &rlist)
virtual int Trunc(long long offs)=0
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum)
virtual int Rename(const char *oldp, const char *newp)
virtual int Stat(const char *url, struct stat &sbuff)
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int opts=0)=0
const char CacheType[8]
A 1-to-7 character cache type identifier (usually pfc or rmc).
static const int optRW
File is read/write (o/w read/only).
virtual int Truncate(const char *path, off_t size)
virtual int Xeq(XeqCmd cmd, char *arg, int arglen)
virtual ~XrdOucCache()
Destructor.
virtual int Unlink(const char *path)
virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
virtual int Fcntl(XrdOucCacheOp::Code opc, const std::string &args, std::string &resp)
static const int optWIN
File is new -> optRW use write-in cache.
virtual int Prepare(const char *url, int oflags, mode_t mode)
XrdOucCacheStats Statistics
XrdOucCache(const char *ctype)
virtual int Rmdir(const char *dirp)
static const int optNEW
File is new -> optRW (o/w read or write).
static const int optFIS
File is structured (e.g. root file).