00001 #ifndef __SFS_INTERFACE_H__ 00002 #define __SFS_INTERFACE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S f s I n t e r f a c e . h h */ 00006 /* */ 00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <string.h> // For strlcpy() 00033 #include <errno.h> 00034 #include <sys/types.h> 00035 #include <sys/stat.h> 00036 00037 #include "XrdOuc/XrdOucErrInfo.hh" 00038 #include "XrdOuc/XrdOucIOVec.hh" 00039 #include "XrdOuc/XrdOucSFVec.hh" 00040 00041 /******************************************************************************/ 00042 /* O p e n M o d e s */ 00043 /******************************************************************************/ 00044 00045 #define SFS_O_RDONLY 0 // open read/only 00046 #define SFS_O_WRONLY 1 // open write/only 00047 #define SFS_O_RDWR 2 // open read/write 00048 #define SFS_O_CREAT 0x100 // used for file creation 00049 #define SFS_O_TRUNC 0x200 // used for file truncation 00050 #define SFS_O_MULTIW 0x400 // used for multi-write locations 00051 #define SFS_O_POSC 0x0100000 // persist on successful close 00052 #define SFS_O_FORCE 0x0200000 // used for locate only 00053 #define SFS_O_HNAME 0x0400000 // used for locate only 00054 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd) 00055 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays 00056 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression 00057 #define SFS_O_RESET 0x04000000 // Reset any cached information 00058 #define SFS_O_REPLICA 0x08000000 // Open for replication 00059 00060 // The following flag may be set in the access mode arg for open() & mkdir() 00061 // Note that on some systems mode_t is 16-bits so we use a careful value! 00062 // 00063 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing 00064 00065 // The following options are here to provide a uniform clustering interface. 00066 // They may be passed through open/locate/stat, as applicable. 00067 // 00068 #define SFS_O_LOCATE 0x10000000 // This request generated by locate() 00069 #define SFS_O_STAT 0x20000000 // This request generated by stat() 00070 #define SFS_O_META 0x40000000 // This request generated by metaop 00071 00072 /******************************************************************************/ 00073 /* D e f i n e s */ 00074 /******************************************************************************/ 00075 00076 // Common fctl command values (0 to 255) 00077 // 00078 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible 00079 #define SFS_FCTL_STATV 2 // Return visa information 00080 #define SFS_FCTL_SPEC1 3 // Return implementation defined information 00081 00082 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value 00083 00084 // Common fsctl command values (0 to 255) 00085 // 00086 #define SFS_FSCTL_CMD 255 00087 00088 #define SFS_FSCTL_LOCATE 1 // Locate a file 00089 #define SFS_FSCTL_STATFS 2 // Return FS data 00090 #define SFS_FSCTL_STATLS 3 // Return LS data 00091 #define SFS_FSCTL_STATXA 4 // Return XA data 00092 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status 00093 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data 00094 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data 00095 00096 // Return values for integer & XrdSfsXferSize returning XrdSfs methods 00097 // 00098 #define SFS_STALL 1 // Return value -> Seconds to stall client 00099 #define SFS_OK 0 // ErrInfo code -> All is well 00100 #define SFS_ERROR -1 // ErrInfo code -> Error occurred 00101 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to 00102 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion 00103 #define SFS_DATA -1024 // ErrInfo code -> Length of data 00104 #define SFS_DATAVEC -2048 // ErrInfo code -> Num iovec elements in msgbuff 00105 00106 // The following macros are used for dealing with special local paths 00107 // 00108 #define SFS_LCLPRFX "/=/" 00109 #define SFS_LCLPLEN 3 00110 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN) 00111 #define SFS_LCLPRFY "/=" 00112 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \ 00113 && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0) 00114 00115 /******************************************************************************/ 00116 /* S t r u c t u r e s & T y p e d e f s */ 00117 /******************************************************************************/ 00118 00119 typedef long long XrdSfsFileOffset; 00120 typedef int XrdSfsFileOpenMode; 00121 typedef int XrdSfsMode; 00122 typedef int XrdSfsXferSize; 00123 00124 enum XrdSfsFileExistence 00125 { 00126 XrdSfsFileExistNo, 00127 XrdSfsFileExistIsFile, 00128 XrdSfsFileExistIsDirectory, 00129 XrdSfsFileExistIsOffline, 00130 XrdSfsFileExistIsOther 00131 }; 00132 //------------------------------------------------ 00133 00134 #define Prep_PRTY0 0 00135 #define Prep_PRTY1 1 00136 #define Prep_PRTY2 2 00137 #define Prep_PRTY3 3 00138 #define Prep_PMASK 3 00139 #define Prep_SENDAOK 4 00140 #define Prep_SENDERR 8 00141 #define Prep_SENDACK 12 00142 #define Prep_WMODE 16 00143 #define Prep_STAGE 32 00144 #define Prep_COLOC 64 00145 #define Prep_FRESH 128 00146 #define Prep_CANCEL 256 00147 #define Prep_QUERY 512 00148 #define Prep_EVICT 1024 00149 00150 class XrdOucTList; 00151 00152 struct XrdSfsFSctl 00153 { 00154 const char *Arg1; 00155 int Arg1Len; 00156 int Arg2Len; 00157 const char *Arg2; 00158 }; 00159 00160 struct XrdSfsPrep 00161 { 00162 char *reqid; 00163 char *notify; 00164 int opts; 00165 XrdOucTList *paths; 00166 XrdOucTList *oinfo; 00167 }; 00168 00169 /******************************************************************************/ 00170 /* A b s t r a c t C l a s s e s */ 00171 /******************************************************************************/ 00172 00173 class XrdSfsFile; 00174 class XrdSfsDirectory; 00175 class XrdOucEnv; 00176 class XrdOucTList; 00177 class XrdSecEntity; 00178 00179 /******************************************************************************/ 00180 /* X r d S f s F i l e S y s t e m */ 00181 /******************************************************************************/ 00182 00183 //----------------------------------------------------------------------------- 00207 //----------------------------------------------------------------------------- 00208 00209 class XrdSfsFileSystem 00210 { 00211 public: 00212 00213 //----------------------------------------------------------------------------- 00223 //----------------------------------------------------------------------------- 00224 00225 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0; 00226 00227 //----------------------------------------------------------------------------- 00237 //----------------------------------------------------------------------------- 00238 00239 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0; 00240 00241 //----------------------------------------------------------------------------- 00260 //----------------------------------------------------------------------------- 00261 00262 enum csFunc {csCalc = 0, csGet, csSize}; 00263 00264 virtual int chksum( csFunc Func, 00265 const char *csName, 00266 const char *path, 00267 XrdOucErrInfo &eInfo, 00268 const XrdSecEntity *client = 0, 00269 const char *opaque = 0) 00270 { 00271 (void)Func; (void)csName; (void)path; (void)eInfo; (void)client; 00272 (void)opaque; 00273 eInfo.setErrInfo(ENOTSUP, "Not supported."); 00274 return SFS_ERROR; 00275 } 00276 00277 //----------------------------------------------------------------------------- 00287 //----------------------------------------------------------------------------- 00288 00289 virtual int chmod(const char *path, 00290 XrdSfsMode mode, 00291 XrdOucErrInfo &eInfo, 00292 const XrdSecEntity *client = 0, 00293 const char *opaque = 0) = 0; 00294 00295 //----------------------------------------------------------------------------- 00299 //----------------------------------------------------------------------------- 00300 00301 virtual void Disc(const XrdSecEntity *client = 0) 00302 { 00303 (void)client; 00304 } 00305 00306 //----------------------------------------------------------------------------- 00311 //----------------------------------------------------------------------------- 00312 00313 virtual void EnvInfo(XrdOucEnv *envP) 00314 { 00315 (void)envP; 00316 } 00317 00318 //----------------------------------------------------------------------------- 00346 //----------------------------------------------------------------------------- 00347 00348 virtual int FSctl(const int cmd, 00349 XrdSfsFSctl &args, 00350 XrdOucErrInfo &eInfo, 00351 const XrdSecEntity *client = 0) 00352 { 00353 (void)cmd; (void)args; (void)eInfo; (void)client; 00354 return SFS_OK; 00355 } 00356 00357 //----------------------------------------------------------------------------- 00373 //----------------------------------------------------------------------------- 00374 00375 virtual int fsctl(const int cmd, 00376 const char *args, 00377 XrdOucErrInfo &eInfo, 00378 const XrdSecEntity *client = 0) = 0; 00379 00380 //----------------------------------------------------------------------------- 00390 //----------------------------------------------------------------------------- 00391 00392 virtual int getStats(char *buff, int blen) = 0; 00393 00394 //----------------------------------------------------------------------------- 00398 //----------------------------------------------------------------------------- 00399 00400 virtual const char *getVersion() = 0; 00401 00402 //----------------------------------------------------------------------------- 00418 //----------------------------------------------------------------------------- 00419 00420 virtual int exists(const char *path, 00421 XrdSfsFileExistence &eFlag, 00422 XrdOucErrInfo &eInfo, 00423 const XrdSecEntity *client = 0, 00424 const char *opaque = 0) = 0; 00425 00426 //----------------------------------------------------------------------------- 00436 //----------------------------------------------------------------------------- 00437 00438 virtual int mkdir(const char *path, 00439 XrdSfsMode mode, 00440 XrdOucErrInfo &eInfo, 00441 const XrdSecEntity *client = 0, 00442 const char *opaque = 0) = 0; 00443 00444 //----------------------------------------------------------------------------- 00452 //----------------------------------------------------------------------------- 00453 00454 virtual int prepare( XrdSfsPrep &pargs, 00455 XrdOucErrInfo &eInfo, 00456 const XrdSecEntity *client = 0) = 0; 00457 00458 //----------------------------------------------------------------------------- 00467 //----------------------------------------------------------------------------- 00468 00469 virtual int rem(const char *path, 00470 XrdOucErrInfo &eInfo, 00471 const XrdSecEntity *client = 0, 00472 const char *opaque = 0) = 0; 00473 00474 //----------------------------------------------------------------------------- 00483 //----------------------------------------------------------------------------- 00484 00485 virtual int remdir(const char *path, 00486 XrdOucErrInfo &eInfo, 00487 const XrdSecEntity *client = 0, 00488 const char *opaque = 0) = 0; 00489 00490 //----------------------------------------------------------------------------- 00501 //----------------------------------------------------------------------------- 00502 00503 virtual int rename(const char *oPath, 00504 const char *nPath, 00505 XrdOucErrInfo &eInfo, 00506 const XrdSecEntity *client = 0, 00507 const char *opaqueO = 0, 00508 const char *opaqueN = 0) = 0; 00509 00510 //----------------------------------------------------------------------------- 00521 //----------------------------------------------------------------------------- 00522 00523 virtual int stat(const char *Name, 00524 struct stat *buf, 00525 XrdOucErrInfo &eInfo, 00526 const XrdSecEntity *client = 0, 00527 const char *opaque = 0) = 0; 00528 00529 //----------------------------------------------------------------------------- 00541 //----------------------------------------------------------------------------- 00542 00543 virtual int stat(const char *path, 00544 mode_t &mode, 00545 XrdOucErrInfo &eInfo, 00546 const XrdSecEntity *client = 0, 00547 const char *opaque = 0) = 0; 00548 00549 //----------------------------------------------------------------------------- 00559 //----------------------------------------------------------------------------- 00560 00561 virtual int truncate(const char *path, 00562 XrdSfsFileOffset fsize, 00563 XrdOucErrInfo &eInfo, 00564 const XrdSecEntity *client = 0, 00565 const char *opaque = 0) = 0; 00566 00567 //----------------------------------------------------------------------------- 00569 //----------------------------------------------------------------------------- 00570 00571 XrdSfsFileSystem() {} 00572 virtual ~XrdSfsFileSystem() {} 00573 }; 00574 00575 /******************************************************************************/ 00576 /* F i l e S y s t e m I n s t a n t i a t o r */ 00577 /******************************************************************************/ 00578 00579 //----------------------------------------------------------------------------- 00613 typedef XrdSfsFileSystem *(*XrdSfsFileSystem_t) (XrdSfsFileSystem *nativeFS, 00614 XrdSysLogger *Logger, 00615 const char *configFn); 00616 00617 typedef XrdSfsFileSystem *(*XrdSfsFileSystem2_t)(XrdSfsFileSystem *nativeFS, 00618 XrdSysLogger *Logger, 00619 const char *configFn, 00620 XrdOucEnv *envP); 00621 00622 //----------------------------------------------------------------------------- 00623 00624 //------------------------------------------------------------------------------ 00636 //------------------------------------------------------------------------------ 00637 00638 /******************************************************************************/ 00639 /* X r d S f s F i l e */ 00640 /******************************************************************************/ 00641 00642 //------------------------------------------------------------------------------ 00645 //------------------------------------------------------------------------------ 00646 00647 class XrdSfsAio; 00648 class XrdSfsDio; 00649 class XrdSfsXio; 00650 00651 class XrdSfsFile 00652 { 00653 public: 00654 00655 //----------------------------------------------------------------------------- 00658 //----------------------------------------------------------------------------- 00659 00660 XrdOucErrInfo error; 00661 00662 //----------------------------------------------------------------------------- 00683 //----------------------------------------------------------------------------- 00684 00685 virtual int open(const char *fileName, 00686 XrdSfsFileOpenMode openMode, 00687 mode_t createMode, 00688 const XrdSecEntity *client = 0, 00689 const char *opaque = 0) = 0; 00690 00691 //----------------------------------------------------------------------------- 00695 //----------------------------------------------------------------------------- 00696 00697 virtual int close() = 0; 00698 00699 //----------------------------------------------------------------------------- 00716 //----------------------------------------------------------------------------- 00717 00718 virtual int fctl(const int cmd, 00719 const char *args, 00720 XrdOucErrInfo &eInfo) = 0; 00721 00722 //----------------------------------------------------------------------------- 00735 //----------------------------------------------------------------------------- 00736 00737 virtual int fctl(const int cmd, 00738 int alen, 00739 const char *args, 00740 const XrdSecEntity *client = 0) 00741 { 00742 (void)cmd; (void)alen; (void)args; (void)client; 00743 return SFS_OK; 00744 } 00745 00746 //----------------------------------------------------------------------------- 00750 //----------------------------------------------------------------------------- 00751 00752 virtual const char *FName() = 0; 00753 00754 00755 //----------------------------------------------------------------------------- 00762 //----------------------------------------------------------------------------- 00763 00764 virtual int getMmap(void **Addr, off_t &Size) = 0; 00765 00766 //----------------------------------------------------------------------------- 00774 //----------------------------------------------------------------------------- 00775 00776 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00777 XrdSfsXferSize size) = 0; 00778 00779 //----------------------------------------------------------------------------- 00788 //----------------------------------------------------------------------------- 00789 00790 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00791 char *buffer, 00792 XrdSfsXferSize size) = 0; 00793 00794 //----------------------------------------------------------------------------- 00801 //----------------------------------------------------------------------------- 00802 00803 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0; 00804 00805 //----------------------------------------------------------------------------- 00815 //----------------------------------------------------------------------------- 00816 00817 virtual XrdSfsXferSize readv(XrdOucIOVec *readV, 00818 int rdvCnt) 00819 {XrdSfsXferSize rdsz, totbytes = 0; 00820 for (int i = 0; i < rdvCnt; i++) 00821 {rdsz = read(readV[i].offset, 00822 readV[i].data, readV[i].size); 00823 if (rdsz != readV[i].size) 00824 {if (rdsz < 0) return rdsz; 00825 error.setErrInfo(ESPIPE,"read past eof"); 00826 return SFS_ERROR; 00827 } 00828 totbytes += rdsz; 00829 } 00830 return totbytes; 00831 } 00832 00833 //----------------------------------------------------------------------------- 00843 //----------------------------------------------------------------------------- 00844 00845 virtual int SendData(XrdSfsDio *sfDio, 00846 XrdSfsFileOffset offset, 00847 XrdSfsXferSize size) 00848 { 00849 (void)sfDio; (void)offset; (void)size; 00850 return SFS_OK; 00851 } 00852 00853 //----------------------------------------------------------------------------- 00862 //----------------------------------------------------------------------------- 00863 00864 virtual XrdSfsXferSize write(XrdSfsFileOffset offset, 00865 const char *buffer, 00866 XrdSfsXferSize size) = 0; 00867 00868 //----------------------------------------------------------------------------- 00875 //----------------------------------------------------------------------------- 00876 00877 virtual int write(XrdSfsAio *aioparm) = 0; 00878 00879 //----------------------------------------------------------------------------- 00889 //----------------------------------------------------------------------------- 00890 00891 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV, 00892 int wdvCnt) 00893 {XrdSfsXferSize wrsz, totbytes = 0; 00894 for (int i = 0; i < wdvCnt; i++) 00895 {wrsz = write(writeV[i].offset, 00896 writeV[i].data, writeV[i].size); 00897 if (wrsz != writeV[i].size) 00898 {if (wrsz < 0) return wrsz; 00899 error.setErrInfo(ESPIPE,"write past eof"); 00900 return SFS_ERROR; 00901 } 00902 totbytes += wrsz; 00903 } 00904 return totbytes; 00905 } 00906 00907 //----------------------------------------------------------------------------- 00914 //----------------------------------------------------------------------------- 00915 00916 virtual int stat(struct stat *buf) = 0; 00917 00918 //----------------------------------------------------------------------------- 00922 //----------------------------------------------------------------------------- 00923 00924 virtual int sync() = 0; 00925 00926 //----------------------------------------------------------------------------- 00931 //----------------------------------------------------------------------------- 00932 00933 virtual int sync(XrdSfsAio *aiop) = 0; 00934 00935 //----------------------------------------------------------------------------- 00941 //----------------------------------------------------------------------------- 00942 00943 virtual int truncate(XrdSfsFileOffset fsize) = 0; 00944 00945 //----------------------------------------------------------------------------- 00953 //----------------------------------------------------------------------------- 00954 00955 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0; 00956 00957 //----------------------------------------------------------------------------- 00961 //----------------------------------------------------------------------------- 00962 00963 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; } 00964 00965 //----------------------------------------------------------------------------- 00972 //----------------------------------------------------------------------------- 00973 00974 XrdSfsFile(const char *user=0, int MonID=0) 00975 : error(user, MonID) {} 00976 00977 //----------------------------------------------------------------------------- 00979 //----------------------------------------------------------------------------- 00980 00981 virtual ~XrdSfsFile() {} 00982 00983 }; // class XrdSfsFile 00984 00985 /******************************************************************************/ 00986 /* X r d S f s D i r e c t o r y */ 00987 /******************************************************************************/ 00988 00989 //------------------------------------------------------------------------------ 00992 //------------------------------------------------------------------------------ 00993 00994 class XrdSfsDirectory 00995 { 00996 public: 00997 00998 //----------------------------------------------------------------------------- 01001 //----------------------------------------------------------------------------- 01002 01003 XrdOucErrInfo error; 01004 01005 //----------------------------------------------------------------------------- 01013 //----------------------------------------------------------------------------- 01014 01015 virtual int open(const char *path, 01016 const XrdSecEntity *client = 0, 01017 const char *opaque = 0) = 0; 01018 01019 //----------------------------------------------------------------------------- 01027 //----------------------------------------------------------------------------- 01028 01029 virtual const char *nextEntry() = 0; 01030 01031 //----------------------------------------------------------------------------- 01035 //----------------------------------------------------------------------------- 01036 01037 virtual int close() = 0; 01038 01039 //----------------------------------------------------------------------------- 01043 //----------------------------------------------------------------------------- 01044 01045 virtual const char *FName() = 0; 01046 01047 //----------------------------------------------------------------------------- 01053 //----------------------------------------------------------------------------- 01054 01055 virtual int autoStat(struct stat *buf) 01056 {(void)buf; 01057 error.setErrInfo(ENOTSUP, "Not supported."); 01058 return SFS_ERROR; 01059 } 01060 01061 //----------------------------------------------------------------------------- 01068 //----------------------------------------------------------------------------- 01069 01070 XrdSfsDirectory(const char *user=0, int MonID=0) 01071 : error(user, MonID) {} 01072 01073 //----------------------------------------------------------------------------- 01075 //----------------------------------------------------------------------------- 01076 01077 virtual ~XrdSfsDirectory() {} 01078 01079 }; // class XrdSfsDirectory 01080 #endif