00001 #ifndef __XRDOUCCACHE_HH__ 00002 #define __XRDOUCCACHE_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c C a c h e . h h */ 00006 /* */ 00007 /* (c) 2019 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <errno.h> 00034 00035 #include "XrdOuc/XrdOucCacheStats.hh" 00036 #include "XrdOuc/XrdOucIOVec.hh" 00037 00038 struct stat; 00039 class XrdOucEnv; 00040 00041 /******************************************************************************/ 00042 /* X r d O u c C a c h e I O C B */ 00043 /******************************************************************************/ 00044 00045 //----------------------------------------------------------------------------- 00048 //----------------------------------------------------------------------------- 00049 00050 class XrdOucCacheIOCB 00051 { 00052 public: 00053 00054 //------------------------------------------------------------------------------ 00060 //------------------------------------------------------------------------------ 00061 virtual 00062 void Done(int result) = 0; 00063 00064 XrdOucCacheIOCB() {} 00065 virtual ~XrdOucCacheIOCB() {} 00066 }; 00067 00068 /******************************************************************************/ 00069 /* X r d O u c C a c h e I O C D */ 00070 /******************************************************************************/ 00071 00072 //----------------------------------------------------------------------------- 00077 //----------------------------------------------------------------------------- 00078 00079 class XrdOucCacheIOCD 00080 { 00081 public: 00082 00083 //------------------------------------------------------------------------------ 00085 //------------------------------------------------------------------------------ 00086 virtual 00087 void DetachDone() = 0; 00088 00089 XrdOucCacheIOCD() {} 00090 virtual ~XrdOucCacheIOCD() {} 00091 }; 00092 00093 /******************************************************************************/ 00094 /* C l a s s X r d O u c C a c h e I O */ 00095 /******************************************************************************/ 00096 00097 //------------------------------------------------------------------------------ 00100 //------------------------------------------------------------------------------ 00101 00102 class XrdOucCacheIO 00103 { 00104 public: 00105 00106 //------------------------------------------------------------------------------ 00121 //------------------------------------------------------------------------------ 00122 00123 virtual bool Detach(XrdOucCacheIOCD &iocd) = 0; 00124 00125 //------------------------------------------------------------------------------ 00129 //------------------------------------------------------------------------------ 00130 virtual 00131 long long FSize() = 0; 00132 00133 //------------------------------------------------------------------------------ 00144 //------------------------------------------------------------------------------ 00145 00146 virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;} 00147 00148 //----------------------------------------------------------------------------- 00153 //----------------------------------------------------------------------------- 00154 virtual 00155 const char *Location() {return "";} 00156 00157 //------------------------------------------------------------------------------ 00161 //------------------------------------------------------------------------------ 00162 virtual 00163 const char *Path() = 0; 00164 00165 //----------------------------------------------------------------------------- 00180 //----------------------------------------------------------------------------- 00181 00182 virtual int pgRead(char *buff, 00183 long long offs, 00184 int rdlen, 00185 uint32_t *csvec, 00186 uint64_t opts=0); 00187 00188 //----------------------------------------------------------------------------- 00204 //----------------------------------------------------------------------------- 00205 00206 virtual void pgRead(XrdOucCacheIOCB &iocb, 00207 char *buff, 00208 long long offs, 00209 int rdlen, 00210 uint32_t *csvec, 00211 uint64_t opts=0) 00212 {iocb.Done(pgRead(buff, offs, rdlen, csvec, opts));} 00213 00214 //----------------------------------------------------------------------------- 00231 //----------------------------------------------------------------------------- 00232 00233 virtual int pgWrite(char *buff, 00234 long long offs, 00235 int rdlen, 00236 uint32_t *csvec, 00237 uint64_t opts=0); 00238 00239 //----------------------------------------------------------------------------- 00257 //----------------------------------------------------------------------------- 00258 00259 virtual void pgWrite(XrdOucCacheIOCB &iocb, 00260 char *buff, 00261 long long offs, 00262 int wrlen, 00263 uint32_t *csvec, 00264 uint64_t opts=0) 00265 {iocb.Done(pgWrite(buff, offs, wrlen, csvec, opts));} 00266 00267 //------------------------------------------------------------------------------ 00273 //------------------------------------------------------------------------------ 00274 00275 static const int SingleUse = 0x0001; 00276 00277 virtual void Preread(long long offs, int rlen, int opts=0) 00278 {(void)offs; (void)rlen; (void)opts;} 00279 00280 //----------------------------------------------------------------------------- 00284 //----------------------------------------------------------------------------- 00285 00286 struct aprParms 00287 {int Trigger; // preread if (rdln < Trigger) (0 -> pagesize+1) 00288 int prRecalc; // Recalc pr efficiency every prRecalc bytes (0->50M) 00289 int Reserve1; 00290 short minPages; // If rdln/pgsz < min, preread minPages (0->off) 00291 signed 00292 char minPerf; // Minimum auto preread performance required (0->n/a) 00293 char Reserve2; 00294 void *Reserve3; 00295 00296 aprParms() : Trigger(0), prRecalc(0), Reserve1(0), 00297 minPages(0), minPerf(90), Reserve2(0), Reserve3(0) {} 00298 }; 00299 00300 virtual void Preread(aprParms &Parms) { (void)Parms; } 00301 00302 //------------------------------------------------------------------------------ 00312 //------------------------------------------------------------------------------ 00313 00314 virtual int Read (char *buff, long long offs, int rlen) = 0; 00315 00316 //------------------------------------------------------------------------------ 00327 //------------------------------------------------------------------------------ 00328 00329 virtual void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen) 00330 {iocb.Done(Read(buff, offs, rlen));} 00331 00332 //------------------------------------------------------------------------------ 00340 //------------------------------------------------------------------------------ 00341 00342 virtual int ReadV(const XrdOucIOVec *readV, int rnum); 00343 00344 //------------------------------------------------------------------------------ 00353 //------------------------------------------------------------------------------ 00354 00355 virtual void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum) 00356 {iocb.Done(ReadV(readV, rnum));} 00357 00358 //------------------------------------------------------------------------------ 00363 //------------------------------------------------------------------------------ 00364 00365 virtual int Sync() = 0; 00366 00367 //------------------------------------------------------------------------------ 00374 //------------------------------------------------------------------------------ 00375 00376 virtual void Sync(XrdOucCacheIOCB &iocb) {iocb.Done(Sync());} 00377 00378 //------------------------------------------------------------------------------ 00385 //------------------------------------------------------------------------------ 00386 00387 virtual int Trunc(long long offs) = 0; 00388 00389 //------------------------------------------------------------------------------ 00400 //------------------------------------------------------------------------------ 00401 00402 virtual void Trunc(XrdOucCacheIOCB &iocb, long long offs) 00403 {iocb.Done(Trunc(offs));} 00404 00405 //------------------------------------------------------------------------------ 00415 //------------------------------------------------------------------------------ 00416 00417 virtual void Update(XrdOucCacheIO &iocp) {} 00418 00419 //------------------------------------------------------------------------------ 00429 //------------------------------------------------------------------------------ 00430 00431 virtual int Write(char *buff, long long offs, int wlen) = 0; 00432 00433 //------------------------------------------------------------------------------ 00444 //------------------------------------------------------------------------------ 00445 00446 virtual void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen) 00447 {iocb.Done(Write(buff, offs, wlen));} 00448 00449 //------------------------------------------------------------------------------ 00457 //------------------------------------------------------------------------------ 00458 00459 virtual int WriteV(const XrdOucIOVec *writV, int wnum); 00460 00461 //------------------------------------------------------------------------------ 00470 //------------------------------------------------------------------------------ 00471 00472 virtual void WriteV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *writV, int wnum) 00473 {iocb.Done(WriteV(writV, wnum));} 00474 00475 //------------------------------------------------------------------------------ 00477 //------------------------------------------------------------------------------ 00478 00479 XrdOucCacheIO() {} 00480 protected: 00481 virtual ~XrdOucCacheIO() {} // Always use Detach() instead of direct delete! 00482 }; 00483 00484 /******************************************************************************/ 00485 /* C l a s s X r d O u c C a c h e */ 00486 /******************************************************************************/ 00487 00488 //------------------------------------------------------------------------------ 00491 //------------------------------------------------------------------------------ 00492 00493 class XrdOucCache 00494 { 00495 public: 00496 00497 //------------------------------------------------------------------------------ 00513 //------------------------------------------------------------------------------ 00514 00515 static const int optFIS = 0x0001; 00516 static const int optRW = 0x0004; 00517 static const int optNEW = 0x0014; 00518 static const int optWIN = 0x0024; 00519 00520 virtual 00521 XrdOucCacheIO *Attach(XrdOucCacheIO *ioP, int opts=0) = 0; 00522 00523 //------------------------------------------------------------------------------ 00563 //------------------------------------------------------------------------------ 00564 00565 enum LFP_Reason {ForAccess=0, ForInfo, ForPath}; 00566 00567 virtual int LocalFilePath(const char *url, char *buff=0, int blen=0, 00568 LFP_Reason why=ForAccess) 00569 {(void)url; (void)buff; (void)blen; (void)why; 00570 if (buff && blen > 0) *buff = 0; 00571 return -ENOTSUP; 00572 } 00573 00574 //------------------------------------------------------------------------------ 00589 //------------------------------------------------------------------------------ 00590 00591 virtual int Prepare(const char *url, int oflags, mode_t mode) 00592 {(void)url; (void)oflags; (void)mode; return 0;} 00593 00594 //------------------------------------------------------------------------------ 00602 //------------------------------------------------------------------------------ 00603 00604 virtual int Rename(const char* oldp, const char* newp) 00605 {(void)oldp; (void)newp; return 0;} 00606 00607 //------------------------------------------------------------------------------ 00614 //------------------------------------------------------------------------------ 00615 00616 virtual int Rmdir(const char* dirp) {(void)dirp; return 0;} 00617 00618 //------------------------------------------------------------------------------ 00630 //------------------------------------------------------------------------------ 00631 00632 virtual int Stat(const char *url, struct stat &sbuff) 00633 {(void)url; (void)sbuff; return 1;} 00634 00635 //------------------------------------------------------------------------------ 00643 //------------------------------------------------------------------------------ 00644 00645 virtual int Truncate(const char* path, off_t size) 00646 {(void)path; (void)size; return 0;} 00647 00648 //------------------------------------------------------------------------------ 00655 //------------------------------------------------------------------------------ 00656 00657 virtual int Unlink(const char* path) {(void)path; return 0;} 00658 00659 //------------------------------------------------------------------------------ 00668 //------------------------------------------------------------------------------ 00669 00670 enum XeqCmd {xeqNoop = 0}; 00671 00672 virtual int Xeq(XeqCmd cmd, char *arg, int arglen) 00673 {(void)cmd; (void)arg; (void)arglen; return -ENOTSUP;} 00674 00675 //------------------------------------------------------------------------------ 00678 //------------------------------------------------------------------------------ 00679 00680 XrdOucCacheStats Statistics; 00681 00682 //------------------------------------------------------------------------------ 00684 //------------------------------------------------------------------------------ 00685 00686 const char CacheType[8]; 00687 00688 //------------------------------------------------------------------------------ 00692 //------------------------------------------------------------------------------ 00693 00694 XrdOucCache(const char *ctype) : CacheType{} 00695 // : CacheType({'\0','\0','\0','\0','\0','\0','\0','\0'}) 00696 {strncpy(const_cast<char *>(CacheType), ctype, 00697 sizeof(CacheType)); 00698 const_cast<char *>(CacheType)[sizeof(CacheType)-1]=0; 00699 } 00700 00701 //------------------------------------------------------------------------------ 00703 //------------------------------------------------------------------------------ 00704 00705 virtual ~XrdOucCache() {} 00706 }; 00707 00708 /******************************************************************************/ 00709 /* C r e a t i n g C a c h e P l u g - I n s */ 00710 /******************************************************************************/ 00711 00712 //------------------------------------------------------------------------------ 00739 00740 typedef XrdOucCache *(*XrdOucCache_t)(XrdSysLogger *, const char *, 00741 const char *, XrdOucEnv *); 00742 00743 //------------------------------------------------------------------------------ 00748 //------------------------------------------------------------------------------ 00749 00755 #endif